diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-07 00:28:50 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:39 +0000 |
| commit | c0317efc1e86f75ee72d6f65b978bfe634bd3b2c (patch) | |
| tree | e4f82b94e7b47f62815f889e902a42de03102356 /src | |
| parent | Inherit destructor and recursively delete all widgets (diff) | |
| download | inkscape-c0317efc1e86f75ee72d6f65b978bfe634bd3b2c.tar.gz inkscape-c0317efc1e86f75ee72d6f65b978bfe634bd3b2c.zip | |
Re-implement get_param() locally using get_widgets()
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/extension.cpp | 93 | ||||
| -rw-r--r-- | src/extension/extension.h | 29 | ||||
| -rw-r--r-- | src/extension/prefdialog/parameter-notebook.cpp | 37 | ||||
| -rw-r--r-- | src/extension/prefdialog/parameter-notebook.h | 3 | ||||
| -rw-r--r-- | src/extension/prefdialog/parameter.cpp | 5 | ||||
| -rw-r--r-- | src/extension/prefdialog/parameter.h | 4 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.cpp | 2 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.h | 2 |
8 files changed, 59 insertions, 116 deletions
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 1da909594..256f1d99a 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -410,26 +410,58 @@ const char *Extension::get_translation(const char *msgid, const char *msgctxt) { } } +/** + \brief A function to get the parameters in a string form + \return An array with all the parameters in it. + +*/ +void +Extension::paramListString (std::list <std::string> &retlist) +{ + // first collect all widgets in the current extension + std::vector<InxWidget *> widget_list; + for (auto widget : _widgets) { + widget->get_widgets(widget_list); + } + + // then build a list of parameter strings from parameter names and values, as '--name=value' + for (auto widget : widget_list) { + InxParameter *parameter = dynamic_cast<InxParameter *>(widget); // filter InxParameters from InxWidgets + if (parameter) { + const char *name = parameter->name(); + std::string value = parameter->value_to_string(); + + if (name && !value.empty()) { // TODO: Shouldn't empty string values be allowed? + std::string parameter_string; + parameter_string += "--"; + parameter_string += name; + parameter_string += "="; + parameter_string += value; + retlist.push_back(parameter_string); + } + } + } + + return; +} + InxParameter *Extension::get_param(const gchar *name) { - if (name == nullptr) { + if (!name || _widgets.empty()) { throw Extension::param_not_exist(); } - if (this->_widgets.empty()) { - throw Extension::param_not_exist(); + + // first collect all widgets in the current extension + std::vector<InxWidget *> widget_list; + for (auto widget : _widgets) { + widget->get_widgets(widget_list); } - for(auto widget : _widgets) { + // then search for a parameter with a matching name + for (auto widget : widget_list) { InxParameter *parameter = dynamic_cast<InxParameter *>(widget); // filter InxParameters from InxWidgets - if (parameter) { - if (!strcmp(parameter->name(), name)) { - return parameter; - } else { - InxParameter *subparam = parameter->get_param(name); - if (subparam) { - return subparam; - } - } + if (parameter && !strcmp(parameter->name(), name)) { + return parameter; } } @@ -758,41 +790,6 @@ Extension::autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<voi return agui; }; -/** - \brief A function to get the parameters in a string form - \return An array with all the parameters in it. - -*/ -void -Extension::paramListString (std::list <std::string> &retlist) -{ - // first collect all widgets in the current extension - std::vector<const InxWidget *> widget_list; - for (auto widget : _widgets) { - widget->get_widgets(widget_list); - } - - // then build a list of parameter strings from parameter names and values, as '--name=value' - for (auto widget : widget_list) { - const InxParameter *parameter = dynamic_cast<const InxParameter *>(widget); // filter InxParameters from InxWidgets - if (parameter) { - const char *name = parameter->name(); - std::string value = parameter->value_to_string(); - - if (name && !value.empty()) { // TODO: Shouldn't empty string values be allowed? - std::string parameter_string; - parameter_string += "--"; - parameter_string += name; - parameter_string += "="; - parameter_string += value; - retlist.push_back(parameter_string); - } - } - } - - return; -} - /* Extension editor dialog stuff */ Gtk::VBox * diff --git a/src/extension/extension.h b/src/extension/extension.h index a5cbdf481..eb9a73316 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -174,27 +174,20 @@ private: void make_param (Inkscape::XML::Node * paramrepr); /** - * This function looks through the linked list for a parameter - * structure with the name of the passed in name. + * Looks up the parameter with the specified name. * - * This is an inline function that is used by all the get_param and - * set_param functions to find a param_t in the linked list with - * the passed in name. + * Searches the list of parameters attached to this extension, + * looking for a parameter with a matching name. * * This function can throw a 'param_not_exist' exception if the * name is not found. * - * The first thing that this function checks is if the list is NULL. - * It could be NULL because there are no parameters for this extension - * or because all of them have been checked. If the list - * is NULL then the 'param_not_exist' exception is thrown. - * - * @param name The name to search for. - * @return Parameter structure with a name of 'name'. + * @param name Name of the parameter to search for. + * @return Parameter with matching name. */ - InxParameter *get_param(const gchar * name); + InxParameter *get_param(const gchar *name); - InxParameter const *get_param(const gchar * name) const; + InxParameter const *get_param(const gchar *name) const; public: bool get_param_bool (const gchar *name, @@ -261,15 +254,15 @@ public: static void error_file_close (); public: - Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node *node, sigc::signal<void> * changeSignal = nullptr); - void paramListString (std::list <std::string> & retlist); + Gtk::Widget *autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal = nullptr); + void paramListString(std::list <std::string> &retlist); void set_gui(bool s) { _gui = s; } bool get_gui() { return _gui; } /* Extension editor dialog stuff */ public: - Gtk::VBox * get_info_widget(); - Gtk::VBox * get_params_widget(); + Gtk::VBox *get_info_widget(); + Gtk::VBox *get_params_widget(); protected: inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Grid * table, int * row); }; diff --git a/src/extension/prefdialog/parameter-notebook.cpp b/src/extension/prefdialog/parameter-notebook.cpp index 1fca1b402..9cdf5df8e 100644 --- a/src/extension/prefdialog/parameter-notebook.cpp +++ b/src/extension/prefdialog/parameter-notebook.cpp @@ -91,27 +91,10 @@ Gtk::Widget *ParamNotebook::ParamNotebookPage::get_widget(SPDocument *doc, Inksc return dynamic_cast<Gtk::Widget *>(vbox); } -/** Search the parameter's name in the page content. */ -InxParameter *ParamNotebook::ParamNotebookPage::get_param(const char *name) -{ - if (name == nullptr) { - throw Extension::param_not_exist(); - } - if (_children.empty()) { - throw Extension::param_not_exist(); - } +/** End ParamNotebookPage **/ - for (auto child : _children) { - InxParameter *parameter = dynamic_cast<InxParameter *>(child); - if (parameter && !strcmp(parameter->name(), name)) { - return parameter; - } - } - return nullptr; -} -/** End ParamNotebookPage **/ /** ParamNotebook **/ ParamNotebook::ParamNotebook(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) @@ -234,24 +217,6 @@ void NotebookWidget::changed_page(Gtk::Widget * /*page*/, guint pagenum) } } -/** Search the parameter's name in the notebook content. */ -InxParameter *ParamNotebook::get_param(const char *name) -{ - if (name == nullptr) { - throw Extension::param_not_exist(); - } - for (auto child : _children) { - ParamNotebookPage *page = dynamic_cast<ParamNotebookPage *>(child); - InxParameter *subparam = page->get_param(name); - if (subparam) { - return subparam; - } - } - - return nullptr; -} - - /** * Creates a Notebook widget for a notebook parameter. * diff --git a/src/extension/prefdialog/parameter-notebook.h b/src/extension/prefdialog/parameter-notebook.h index ee8727158..bba6cdd64 100644 --- a/src/extension/prefdialog/parameter-notebook.h +++ b/src/extension/prefdialog/parameter-notebook.h @@ -49,7 +49,6 @@ private: ParamNotebookPage(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal) override; - InxParameter *get_param(const char *name) override; // ParamNotebookPage is not a real parameter (it has no value), so make sure it does not return one std::string value_to_string() const override { return ""; }; @@ -68,8 +67,6 @@ public: std::string value_to_string() const override; - InxParameter *get_param (const char *name) override; - const Glib::ustring& get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } const Glib::ustring& set (const int in, SPDocument *doc, Inkscape::XML::Node *node); }; /* class ParamNotebook */ diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 7d8751353..d0e284ea7 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -272,11 +272,6 @@ std::string InxParameter::value_to_string() const return ""; } -InxParameter *InxParameter::get_param(const char */*name*/) -{ - return nullptr; -} - const Glib::ustring InxParameter::extension_pref_root = "/extensions/"; } // namespace Extension diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h index eba096be2..23fea0204 100644 --- a/src/extension/prefdialog/parameter.h +++ b/src/extension/prefdialog/parameter.h @@ -118,10 +118,6 @@ public: */ virtual std::string value_to_string() const; - /** All the code in Notebook::get_param to get the notebook content. */ - virtual InxParameter *get_param(char const *name); - - /** Recommended spacing between the widgets making up a single Parameter (e.g. label and input) (in px) */ const static int GUI_PARAM_WIDGETS_SPACING = 4; diff --git a/src/extension/prefdialog/widget.cpp b/src/extension/prefdialog/widget.cpp index efd97e099..db5700b2e 100644 --- a/src/extension/prefdialog/widget.cpp +++ b/src/extension/prefdialog/widget.cpp @@ -136,7 +136,7 @@ const char *InxWidget::get_translation(const char* msgid) { return _extension->get_translation(msgid, _context); } -void InxWidget::get_widgets(std::vector<const InxWidget *> &list) const +void InxWidget::get_widgets(std::vector<InxWidget *> &list) { list.push_back(this); for (auto child : _children) { diff --git a/src/extension/prefdialog/widget.h b/src/extension/prefdialog/widget.h index b31fc1d53..07706f8d6 100644 --- a/src/extension/prefdialog/widget.h +++ b/src/extension/prefdialog/widget.h @@ -76,7 +76,7 @@ public: * * @param list Reference to a vector of pointers to \a InxWidget that will be appended with the new \a InxWidgets */ - virtual void get_widgets(std::vector<const InxWidget *> &list) const; + virtual void get_widgets(std::vector<InxWidget *> &list); /** Recommended margin of boxes containing multiple widgets (in px) */ |
