diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-07-22 23:06:21 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:38 +0000 |
| commit | 8f7a3a637f6a465e78e88490a03f539f0d8fdc1a (patch) | |
| tree | e503502036ba4268921ded10a81ab3b4157d89d5 /src/extension/prefdialog/parameter-int.cpp | |
| parent | Move error classes to Parameter where they belong (diff) | |
| download | inkscape-8f7a3a637f6a465e78e88490a03f539f0d8fdc1a.tar.gz inkscape-8f7a3a637f6a465e78e88490a03f539f0d8fdc1a.zip | |
Refactor a lot of the parameter handling code
Many fixes, improvements and simplifications to existing code.
Implements the first part of the changes discussed in
https://gitlab.com/inkscape/inkscape/issues/333
Diffstat (limited to 'src/extension/prefdialog/parameter-int.cpp')
| -rw-r--r-- | src/extension/prefdialog/parameter-int.cpp | 93 |
1 files changed, 43 insertions, 50 deletions
diff --git a/src/extension/prefdialog/parameter-int.cpp b/src/extension/prefdialog/parameter-int.cpp index 2b9e2c5f6..b03afc1e1 100644 --- a/src/extension/prefdialog/parameter-int.cpp +++ b/src/extension/prefdialog/parameter-int.cpp @@ -23,42 +23,15 @@ namespace Inkscape { namespace Extension { -/** Use the superclass' allocator and set the \c _value. */ -ParamInt::ParamInt(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) - : Parameter(name, text, description, hidden, indent, ext) - , _value(0) - , _mode(mode) - , _min(0) - , _max(10) +ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - const char * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - if (defaultval != nullptr) { - _value = atoi(defaultval); - } - - const char * maxval = xml->attribute("max"); - if (maxval != nullptr) { - _max = atoi(maxval); - } - - const char * minval = xml->attribute("min"); - if (minval != nullptr) { - _min = atoi(minval); - } - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10; - _min = 0; + // get value + if (xml->firstChild()) { + const char *value = xml->firstChild()->content(); + if (value) { + _value = strtol(value, nullptr, 0); + } } gchar *pref_name = this->pref_name(); @@ -66,14 +39,34 @@ ParamInt::ParamInt(const gchar * name, _value = prefs->getInt(extension_pref_root + pref_name, _value); g_free(pref_name); - // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; + // parse and apply limits + const char *min = xml->attribute("min"); + if (min) { + _min = strtol(min, nullptr, 0); + } - if (_value > _max) { - _value = _max; + const char *max = xml->attribute("max"); + if (max) { + _max = strtol(max, nullptr, 0); } + if (_value < _min) { _value = _min; } + + if (_value > _max) { + _value = _max; + } + + // parse appearance + if (_appearance) { + if (!strcmp(_appearance, "full")) { + _mode = FULL; + } else { + g_warning("Invalid value ('%s') for appearance of parameter '%s' in extension '%s'", + _appearance, _name, _extension->get_id()); + } + } } /** @@ -96,10 +89,10 @@ int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) _value = _min; } - gchar * prefname = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(extension_pref_root + prefname, _value); - g_free(prefname); + prefs->setInt(extension_pref_root + pref_name, _value); + g_free(pref_name); return _value; } @@ -107,14 +100,14 @@ int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) /** A class to make an adjustment that uses Extension params. */ class ParamIntAdjustment : public Gtk::Adjustment { /** The parameter to adjust. */ - ParamInt * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal<void> * _changeSignal; + ParamInt *_pref; + SPDocument *_doc; + Inkscape::XML::Node *_node; + sigc::signal<void> *_changeSignal; public: /** Make the adjustment using an extension and the string describing the parameter. */ - ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) : + ParamIntAdjustment (ParamInt *param, SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal) : Gtk::Adjustment(0.0, param->min(), param->max(), 1.0, 10.0, 0), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { this->set_value(_pref->get(nullptr, nullptr) /* \todo fix */); this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed)); @@ -144,13 +137,13 @@ void ParamIntAdjustment::val_changed() * Builds a hbox with a label and a int adjustment in it. */ Gtk::Widget * -ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) +ParamInt::get_widget (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal) { if (_hidden) { return nullptr; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); auto pia = new ParamIntAdjustment(this, doc, node, changeSignal); Glib::RefPtr<Gtk::Adjustment> fadjust(pia); @@ -165,8 +158,8 @@ ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal scale->show(); hbox->pack_start(*scale, true, true); } - else if (_mode == MINIMAL) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + else if (_mode == DEFAULT) { + Gtk::Label *label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); hbox->pack_start(*label, true, true); |
