diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-01 15:49:26 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-01 15:49:26 +0000 |
| commit | e0957537cd0938313803c290a2f3922a3889e6f1 (patch) | |
| tree | 7f158d00a7655ee91ac094f676f6b3bd624a78b7 /src | |
| parent | Merge branch 'master' of gitlab.com:inkscape/inkscape (diff) | |
| download | inkscape-e0957537cd0938313803c290a2f3922a3889e6f1.tar.gz inkscape-e0957537cd0938313803c290a2f3922a3889e6f1.zip | |
Removed all GSList occurences in .h files
Diffstat (limited to 'src')
39 files changed, 389 insertions, 509 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 589cc849d..187597794 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -294,8 +294,8 @@ CanvasAxonomGrid::readRepr() gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu } - for (GSList *l = canvasitems; l != NULL; l = l->next) { - sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); + for (auto i:canvasitems) { + sp_canvas_item_request_update(i); } return; } diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 4243d3365..01bfc2fc0 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -149,7 +149,6 @@ CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocume } namedview = nv; - canvasitems = NULL; } CanvasGrid::~CanvasGrid() @@ -157,11 +156,9 @@ CanvasGrid::~CanvasGrid() if (repr) { repr->removeListenerByData (this); } - - while (canvasitems) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(canvasitems->data)); - canvasitems = g_slist_remove(canvasitems, canvasitems->data); - } + for (auto i:canvasitems) + sp_canvas_item_destroy(i); + canvasitems.clear(); } const char * @@ -276,8 +273,8 @@ CanvasGrid::createCanvasItem(SPDesktop * desktop) // but share the same CanvasGrid object; that is what this function is for. // check if there is already a canvasitem on this desktop linking to this grid - for (GSList *l = canvasitems; l != NULL; l = l->next) { - if ( desktop->getGridGroup() == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) { + for (auto i:canvasitems) { + if ( desktop->getGridGroup() == SP_CANVAS_GROUP(i->parent) ) { return NULL; } } @@ -287,7 +284,7 @@ CanvasGrid::createCanvasItem(SPDesktop * desktop) sp_canvas_item_show(SP_CANVAS_ITEM(item)); g_object_ref(item); // since we're keeping a link to this item, we need to bump up the ref count - canvasitems = g_slist_prepend(canvasitems, item); + canvasitems.push_back(item); return item; } @@ -650,8 +647,8 @@ CanvasXYGrid::readRepr() gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu } - for (GSList *l = canvasitems; l != NULL; l = l->next) { - sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); + for (auto i:canvasitems) { + sp_canvas_item_request_update(i); } return; diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 91fa43e69..6b36390c8 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -112,7 +112,7 @@ protected: virtual Gtk::Widget * newSpecificWidget() = 0; - GSList * canvasitems; // list of created canvasitems + std::vector<SPCanvasItem*> canvasitems; // list of created canvasitems SPNamedView * namedview; diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 6e662b17b..1115978e9 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -38,6 +38,15 @@ SPCurve::SPCurve(Geom::PathVector const& pathv) _pathv(pathv) {} +//concat constructor +SPCurve::SPCurve(std::list<SPCurve *> const& l) : _refcount(1) +{ + for (auto c:l) { + _pathv.insert( _pathv.end(), c->get_pathvector().begin(), c->get_pathvector().end() ); + } +} + + SPCurve * SPCurve::new_from_rect(Geom::Rect const &rect, bool all_four_sides) { @@ -134,32 +143,24 @@ SPCurve::copy() const * Return new curve that is the concatenation of all curves in list. */ SPCurve * -SPCurve::concat(GSList const *list) -{ - SPCurve *new_curve = new SPCurve(); - - for (GSList const *l = list; l != NULL; l = l->next) { - SPCurve *c = static_cast<SPCurve *>(l->data); - new_curve->_pathv.insert( new_curve->_pathv.end(), c->get_pathvector().begin(), c->get_pathvector().end() ); - } - - return new_curve; -} +SPCurve::concat(std::list<SPCurve *> l){ + return new SPCurve(l); +}; /** * Returns a list of new curves corresponding to the subpaths in \a curve. * 2geomified */ -GSList * +std::list<SPCurve *> SPCurve::split() const { - GSList *l = NULL; + std::list<SPCurve *> l; for (Geom::PathVector::const_iterator path_it = _pathv.begin(); path_it != _pathv.end(); ++path_it) { Geom::PathVector newpathv; newpathv.push_back(*path_it); SPCurve * newcurve = new SPCurve(newpathv); - l = g_slist_prepend(l, newcurve); + l.push_back(newcurve); } return l; diff --git a/src/display/curve.h b/src/display/curve.h index 8375e1105..87b9984a8 100644 --- a/src/display/curve.h +++ b/src/display/curve.h @@ -16,8 +16,7 @@ #include <2geom/pathvector.h> #include <cstddef> #include <boost/optional.hpp> - -extern "C" { typedef struct _GSList GSList; } +#include <list> /** * Wrapper around a Geom::PathVector object. @@ -27,6 +26,7 @@ public: /* Constructors */ explicit SPCurve(); explicit SPCurve(Geom::PathVector const& pathv); + explicit SPCurve(std::list<SPCurve *> const& pathv); static SPCurve * new_from_rect(Geom::Rect const &rect, bool all_four_sides = false); virtual ~SPCurve(); @@ -78,8 +78,8 @@ public: SPCurve * append_continuous(SPCurve const *c1, double tolerance); SPCurve * create_reverse() const; - GSList * split() const; - static SPCurve * concat(GSList const *list); + std::list<SPCurve *> split() const; + static SPCurve * concat(std::list<SPCurve *> l); protected: size_t _refcount; diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index f1b328f05..d9ea5eca7 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -64,7 +64,6 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat id = NULL; name = NULL; _state = STATE_UNLOADED; - parameters = NULL; if (in_imp == NULL) { imp = new Implementation::Implementation(); @@ -97,7 +96,7 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat Parameter * param; param = Parameter::make(child_repr, this); if (param != NULL) - parameters = g_slist_append(parameters, param); + parameters.push_back(param); } /* param || _param */ if (!strcmp(chname, "dependency")) { _deps.push_back(new Dependency(child_repr)); @@ -146,12 +145,9 @@ Extension::~Extension (void) /** \todo Need to do parameters here */ // delete parameters: - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { delete param; } - g_slist_free(parameters); - for (unsigned int i = 0 ; i < _deps.size(); i++) { delete _deps[i]; @@ -402,14 +398,11 @@ Parameter *Extension::get_param(gchar const *name) if (name == NULL) { throw Extension::param_not_exist(); } - if (this->parameters == NULL) { - // the list of parameters is empty + if (this->parameters.empty()) { throw Extension::param_not_exist(); } - for (GSList * list = this->parameters; list != NULL; list = -g_slist_next(list)) { - Parameter * param = static_cast<Parameter*>(list->data); + for( auto param:this->parameters) { if (!strcmp(param->name(), name)) { return param; } else { @@ -730,8 +723,7 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<v agui->set_spacing(Parameter::GUI_BOX_SPACING); //go through the list of parameters to see if there are any non-hidden ones - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { if (param->get_hidden()) continue; //Ignore hidden parameters Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); gchar const * tip = param->get_tooltip(); @@ -751,8 +743,7 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<v void Extension::paramListString (std::list <std::string> &retlist) { - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for(auto param:parameters) { param->string(retlist); } @@ -835,8 +826,7 @@ Extension::get_params_widget(void) unsigned int Extension::param_visible_count ( ) { unsigned int _visible_count = 0; - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { if (!param->get_hidden()) _visible_count++; } return _visible_count; diff --git a/src/extension/extension.h b/src/extension/extension.h index 962c3c8a7..9ccc9869b 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -133,7 +133,7 @@ public: /* Parameter Stuff */ private: - GSList * parameters; /**< A table to store the parameters for this extension. + std::vector<Parameter *> parameters; /**< A table to store the parameters for this extension. This only gets created if there are parameters in this extension */ @@ -141,8 +141,7 @@ public: /** \brief A function to get the number of parameters that the extension has. \return The number of parameters. */ - unsigned int param_count ( ) { return parameters == NULL ? 0 : - g_slist_length(parameters); }; + unsigned int param_count ( ) { return parameters.size(); }; /** \brief A function to get the number of parameters that are visible to the user that the extension has. \return The number of visible parameters. diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index c513744a8..3edb58a13 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -163,10 +163,10 @@ CairoRenderState* CairoRenderContext::getCurrentState(void) const CairoRenderState* CairoRenderContext::getParentState(void) const { // if this is the root node just return it - if (g_slist_length(_state_stack) == 1) { + if (_state_stack.size() == 1) { return _state; } else { - return static_cast<CairoRenderState *>(g_slist_nth_data(_state_stack, 1)); + return _state_stack[_state_stack.size()-2]; } } @@ -975,7 +975,7 @@ void CairoRenderContext::pushState(void) CairoRenderState *new_state = _createState(); // copy current state's transform new_state->transform = _state->transform; - _state_stack = g_slist_prepend(_state_stack, new_state); + _state_stack.push_back(new_state); _state = new_state; } @@ -985,11 +985,11 @@ void CairoRenderContext::popState(void) cairo_restore(_cr); - g_free(_state_stack->data); - _state_stack = g_slist_remove_link(_state_stack, _state_stack); - _state = static_cast<CairoRenderState*>(_state_stack->data); + g_free(_state_stack.back()); + _state_stack.pop_back(); - g_assert( g_slist_length(_state_stack) > 0 ); + g_assert( !_state_stack.empty()); + _state = _state_stack.back(); } static bool pattern_hasItemChildren(SPPattern *pat) diff --git a/src/extension/internal/cairo-render-context.h b/src/extension/internal/cairo-render-context.h index 9b976fd6d..be5169a74 100644 --- a/src/extension/internal/cairo-render-context.h +++ b/src/extension/internal/cairo-render-context.h @@ -198,7 +198,7 @@ protected: unsigned int _clip_rule : 8; unsigned int _clip_winding_failed : 1; - GSList *_state_stack; + std::vector<CairoRenderState *> _state_stack; CairoRenderState *_state; // the current state CairoRenderer *_renderer; diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index a2b8fb22f..3724a5e17 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -121,13 +121,12 @@ CairoRenderer::createContext(void) CairoRenderContext *new_context = new CairoRenderContext(this); g_assert( new_context != NULL ); - new_context->_state_stack = NULL; new_context->_state = NULL; // create initial render state CairoRenderState *state = new_context->_createState(); state->transform = Geom::identity(); - new_context->_state_stack = g_slist_prepend(new_context->_state_stack, state); + new_context->_state_stack.push_back(state); new_context->_state = state; return new_context; @@ -517,20 +516,17 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) // Do the export SPDocument *document = item->document; - GSList *items = NULL; - items = g_slist_append(items, item); boost::scoped_ptr<Inkscape::Pixbuf> pb( sp_generate_internal_bitmap(document, NULL, bbox->min()[Geom::X], bbox->min()[Geom::Y], bbox->max()[Geom::X], bbox->max()[Geom::Y], - width, height, res, res, (guint32) 0xffffff00, items )); + width, height, res, res, (guint32) 0xffffff00, item )); if (pb) { //TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL )); ctx->renderImage(pb.get(), t, item->style); } - g_slist_free (items); } diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 7cd860465..db34a6ef9 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -32,20 +32,6 @@ namespace Inkscape { namespace Extension { -/* For internal use only. - Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class enumentry { -public: - enumentry (Glib::ustring &val, Glib::ustring &text) : - value(val), - text(text) - {} - - Glib::ustring value; - Glib::ustring text; -}; - - ParamComboBox::ParamComboBox(const gchar * name, const gchar * text, const gchar * description, @@ -55,7 +41,6 @@ ParamComboBox::ParamComboBox(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) , _value(NULL) - , choices(NULL) { const char *xmlval = NULL; // the value stored in XML @@ -93,7 +78,7 @@ ParamComboBox::ParamComboBox(const gchar * name, } if ( (!newtext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here - choices = g_slist_append( choices, new enumentry(newvalue, newtext) ); + choices.push_back(new enumentry(newvalue, newtext) ); } } } @@ -120,11 +105,9 @@ ParamComboBox::ParamComboBox(const gchar * name, ParamComboBox::~ParamComboBox (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast<enumentry *>(list->data)); + for (auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -151,8 +134,7 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape } Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { if ( !entr->text.compare(in) ) { settext = entr->value; break; // break out of for loop @@ -181,8 +163,7 @@ bool ParamComboBox::contains(const gchar * text, SPDocument const * /*doc*/, Ink return false; /* Can't have NULL string */ } - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { if ( !entr->text.compare(text) ) return true; } @@ -256,8 +237,7 @@ Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * n ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: Glib::ustring settext; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - enumentry * entr = reinterpret_cast<enumentry *>(list->data); + for (auto entr:choices) { Glib::ustring text = entr->text; combo->append(text); diff --git a/src/extension/param/enum.h b/src/extension/param/enum.h index 143a648d7..d34c0dcaa 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -34,7 +34,23 @@ private: been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + * Note that value and text MUST be non-NULL. + * This is ensured by newing only at one location in the code where non-NULL checks are made. + */ + class enumentry { + public: + enumentry (Glib::ustring &val, Glib::ustring &text) : + value(val), + text(text) + {} + + Glib::ustring value; + Glib::ustring text; + }; + + std::vector<enumentry *> choices; /**< A table to store the choice strings */ public: ParamComboBox(const gchar * name, diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 4e94b5216..220d6eb32 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -42,34 +42,7 @@ namespace Inkscape { namespace Extension { -/** - * A class to represent the pages of a notebookparameter of an extension. - */ -class ParamNotebookPage : public Parameter { -private: - GSList * parameters; /**< A table to store the parameters for this page. - This only gets created if there are parameters on this - page */ - -public: - static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - ParamNotebookPage(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamNotebookPage(void); - - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void paramString (std::list <std::string> &list); - gchar * get_text (void) {return _text;}; - Parameter * get_param (const gchar * name); -}; /* class ParamNotebookPage */ - - -ParamNotebookPage::ParamNotebookPage(const gchar * name, +ParamNotebook::ParamNotebookPage::ParamNotebookPage(const gchar * name, const gchar * text, const gchar * description, bool hidden, @@ -77,7 +50,6 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, /*indent*/ 0, ext) { - parameters = NULL; // Read XML to build page if (xml != NULL) { @@ -92,28 +64,25 @@ ParamNotebookPage::ParamNotebookPage(const gchar * name, if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { Parameter * param; param = Parameter::make(child_repr, ext); - if (param != NULL) parameters = g_slist_append(parameters, param); + if (param != NULL) parameters.push_back(param); } child_repr = child_repr->next(); } } } -ParamNotebookPage::~ParamNotebookPage (void) +ParamNotebook::ParamNotebookPage::~ParamNotebookPage (void) { //destroy parameters - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { delete param; } - g_slist_free(parameters); } /** Return the value as a string. */ -void ParamNotebookPage::paramString(std::list <std::string> &list) +void ParamNotebook::ParamNotebookPage::paramString(std::list <std::string> &list) { - for (GSList * plist = parameters; plist != NULL; plist = g_slist_next(plist)) { - Parameter * param = reinterpret_cast<Parameter *>(plist->data); + for (auto param:parameters) { param->string(list); } } @@ -143,8 +112,8 @@ void ParamNotebookPage::paramString(std::list <std::string> &list) straight forward. In all cases the value is set to the default value from the XML and the type is set to the interpreted type. */ -ParamNotebookPage * -ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) +ParamNotebook::ParamNotebookPage * +ParamNotebook::ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) { const char * name; const char * text; @@ -186,7 +155,7 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: * * Builds a notebook page (a vbox) and puts parameters on it. */ -Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) +Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { if (_hidden) { return NULL; @@ -197,8 +166,7 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod vbox->set_spacing(Parameter::GUI_BOX_SPACING); // add parameters onto page (if any) - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); + for (auto param:parameters) { Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); if (widg) { int indent = param->get_indent(); @@ -224,6 +192,28 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod return dynamic_cast<Gtk::Widget *>(vbox); } +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +{ + if (name == NULL) { + throw Extension::param_not_exist(); + } + if (this->parameters.empty()) { + // the list of parameters is empty + throw Extension::param_not_exist(); + } + + for (auto param:parameters) { + if (!strcmp(param->name(), name)) { + return param; + } + } + + return NULL; +} + +/** End ParamNotebookPage **/ +/** ParamNotebook **/ ParamNotebook::ParamNotebook(const gchar * name, const gchar * text, @@ -234,8 +224,6 @@ ParamNotebook::ParamNotebook(const gchar * name, Inkscape::XML::Node * xml) : Parameter(name, text, description, hidden, indent, ext) { - pages = NULL; - // Read XML tree to add pages: if (xml != NULL) { Inkscape::XML::Node *child_repr = xml->firstChild(); @@ -249,7 +237,7 @@ ParamNotebook::ParamNotebook(const gchar * name, if (!strcmp(chname, "page")) { ParamNotebookPage * page; page = ParamNotebookPage::makepage(child_repr, ext); - if (page != NULL) pages = g_slist_append(pages, page); + if (page != NULL) pages.push_back(page); } child_repr = child_repr->next(); } @@ -258,9 +246,8 @@ ParamNotebook::ParamNotebook(const gchar * name, // Initialize _value with the current page const char * defaultval = NULL; // set first page as default - if (pages != NULL) { - ParamNotebookPage * defpage = reinterpret_cast<ParamNotebookPage *>(pages->data); - defaultval = defpage->name(); + if (!pages.empty()) { + defaultval = pages[0]->name(); } gchar * pref_name = this->pref_name(); @@ -277,12 +264,9 @@ ParamNotebook::ParamNotebook(const gchar * name, ParamNotebook::~ParamNotebook (void) { //destroy pages - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); + for (auto page:pages) { delete page; } - g_slist_free(pages); - g_free(_value); } @@ -304,12 +288,8 @@ ParamNotebook::~ParamNotebook (void) */ const gchar *ParamNotebook::set(const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { - ParamNotebookPage * page = NULL; - int i = 0; - for (GSList * list = pages; (list != NULL) && (i <= in); list = g_slist_next(list)) { - page = reinterpret_cast<ParamNotebookPage *>(list->data); - i++; - } + int i = in < pages.size() ? in : pages.size()-1; + ParamNotebookPage * page = pages[i]; if (page == NULL) return _value; @@ -336,8 +316,7 @@ void ParamNotebook::string(std::list <std::string> &list) const param_string += "\""; list.insert(list.end(), param_string); - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); + for (auto page:pages) { page->paramString(list); } } @@ -384,8 +363,7 @@ Parameter *ParamNotebook::get_param(const gchar * name) if (name == NULL) { throw Extension::param_not_exist(); } - for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); + for (auto page:pages) { Parameter * subparam = page->get_param(name); if (subparam) { return subparam; @@ -395,26 +373,6 @@ Parameter *ParamNotebook::get_param(const gchar * name) return NULL; } -/** Search the parameter's name in the page content. */ -Parameter *ParamNotebookPage::get_param(const gchar * name) -{ - if (name == NULL) { - throw Extension::param_not_exist(); - } - if (this->parameters == NULL) { - // the list of parameters is empty - throw Extension::param_not_exist(); - } - - for (GSList * list = this->parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = static_cast<Parameter*>(list->data); - if (!strcmp(param->name(), name)) { - return param; - } - } - - return NULL; -} /** * Creates a Notebook widget for a notebook parameter. @@ -432,9 +390,8 @@ Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * // add pages (if any) int i = -1; int pagenr = i; - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { + for (auto page:pages) { i++; - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); nb->append_page(*widg, _(page->get_text())); if (!strcmp(_value, page->name())) { diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h index 8475de61d..f1bebd372 100644 --- a/src/extension/param/notebook.h +++ b/src/extension/param/notebook.h @@ -37,7 +37,34 @@ private: */ gchar * _value; - GSList * pages; /**< A table to store the pages with parameters for this notebook. + /** + * A class to represent the pages of a notebookparameter of an extension. + */ + class ParamNotebookPage : public Parameter { + private: + std::vector<Parameter *> parameters; /**< A table to store the parameters for this page. + This only gets created if there are parameters on this + page */ + + public: + static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); + + ParamNotebookPage(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~ParamNotebookPage(void); + + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); + void paramString (std::list <std::string> &list); + gchar * get_text (void) {return _text;}; + Parameter * get_param (const gchar * name); + }; /* class ParamNotebookPage */ + + + std::vector<ParamNotebookPage*> pages; /**< A table to store the pages with parameters for this notebook. This only gets created if there are pages in this notebook */ public: diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index a08ba6860..ca6dbb31d 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -42,20 +42,6 @@ namespace Extension { /* For internal use only. Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class optionentry { -public: - optionentry (Glib::ustring * val, Glib::ustring * txt) { - value = val; - text = txt; - } - ~optionentry() { - delete value; - delete text; - } - - Glib::ustring * value; - Glib::ustring * text; -}; ParamRadioButton::ParamRadioButton(const gchar * name, const gchar * text, @@ -68,7 +54,6 @@ ParamRadioButton::ParamRadioButton(const gchar * name, : Parameter(name, text, description, hidden, indent, ext) , _value(0) , _mode(mode) - , choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); @@ -105,7 +90,7 @@ ParamRadioButton::ParamRadioButton(const gchar * name, } if ( (newtext) && (newvalue) ) { // logical error if this is not true here - choices = g_slist_append( choices, new optionentry(newvalue, newtext) ); + choices.push_back(new optionentry(newvalue, newtext)); } } child_repr = child_repr->next(); @@ -115,8 +100,8 @@ ParamRadioButton::ParamRadioButton(const gchar * name, // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (choices) { - defaultval = (static_cast<optionentry*> (choices->data))->value->c_str(); + if (!choices.empty()) { + defaultval = (static_cast<optionentry*> (choices[0]))->value->c_str(); } gchar * pref_name = this->pref_name(); @@ -135,11 +120,9 @@ ParamRadioButton::ParamRadioButton(const gchar * name, ParamRadioButton::~ParamRadioButton (void) { //destroy choice strings - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - delete (reinterpret_cast<optionentry *>(list->data)); + for(auto i:choices) { + delete i; } - g_slist_free(choices); - g_free(_value); } @@ -166,8 +149,7 @@ const gchar *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inksc } Glib::ustring * settext = NULL; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for (auto entr:choices) { if ( !entr->value->compare(in) ) { settext = entr->value; break; // break out of for loop @@ -278,8 +260,7 @@ Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) { Glib::ustring value = ""; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for ( auto entr:choices) { if ( !entr->text->compare(label) ) { value = *(entr->value); break; @@ -319,8 +300,7 @@ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node // add choice strings as radiobuttons // and select last selected option (_value) Gtk::RadioButtonGroup group; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); + for (auto entr:choices) { Glib::ustring * text = entr->text; switch ( _mode ) { case MINIMAL: diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index b91b11ea3..e3ced8eb8 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -27,6 +27,7 @@ namespace Extension { class Extension; + // \brief A class to represent a radiobutton parameter of an extension class ParamRadioButton : public Parameter { public: @@ -63,7 +64,24 @@ private: It is the value of the current selected string */ gchar * _value; AppearanceMode _mode; - GSList * choices; /**< A table to store the choice strings */ + + /* For internal use only. + Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ + class optionentry { + public: + optionentry (Glib::ustring * val, Glib::ustring * txt) { + value = val; + text = txt; + } + ~optionentry() { + delete value; + delete text; + } + Glib::ustring * value; + Glib::ustring * text; + }; + + std::vector<optionentry*> choices; /**< A table to store the choice strings */ }; /* class ParamRadioButton */ diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index bb33f7b15..438a428e6 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -34,9 +34,9 @@ // TODO look for copy-n-paste duplication of this function: /** - * Hide all items that are not listed in list, recursively, skipping groups and defs. + * Hide all items except @item, recursively, skipping groups and defs. */ -static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dkey) +static void hide_other_items_recursively(SPObject *o, SPItem *i, unsigned dkey) { SPItem *item = dynamic_cast<SPItem *>(o); if ( item @@ -44,15 +44,15 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke && !dynamic_cast<SPRoot *>(item) && !dynamic_cast<SPGroup *>(item) && !dynamic_cast<SPUse *>(item) - && !g_slist_find(list, o) ) + && (i != o) ) { item->invoke_hide(dkey); } // recurse - if (!g_slist_find(list, o)) { + if (i != o) { for (auto& child: o->children) { - hide_other_items_recursively(&child, list, dkey); + hide_other_items_recursively(&child, i, dkey); } } } @@ -65,11 +65,11 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke bool sp_export_jpg_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned width, unsigned height, double xdpi, double ydpi, - unsigned long bgcolor, double quality,GSList *items) + unsigned long bgcolor, double quality, SPItem* item) { boost::scoped_ptr<Inkscape::Pixbuf> pixbuf( sp_generate_internal_bitmap(doc, filename, x0, y0, x1, y1, - width, height, xdpi, ydpi, bgcolor, items)); + width, height, xdpi, ydpi, bgcolor, item)); gchar c[32]; g_snprintf(c, 32, "%f", quality); @@ -78,6 +78,7 @@ bool sp_export_jpg_file(SPDocument *doc, gchar const *filename, return saved; } + /** generates a bitmap from given items the bitmap is stored in RAM and not written to file @@ -95,7 +96,7 @@ Inkscape::Pixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const */*fi double x0, double y0, double x1, double y1, unsigned width, unsigned height, double xdpi, double ydpi, unsigned long /*bgcolor*/, - GSList *items_only) + SPItem *item_only) { if (width == 0 || height == 0) return NULL; @@ -128,8 +129,8 @@ Inkscape::Pixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const */*fi // We show all and then hide all items we don't want, instead of showing only requested items, // because that would not work if the shown item references something in defs - if (items_only) { - hide_other_items_recursively(doc->getRoot(), items_only, dkey); + if (item_only) { + hide_other_items_recursively(doc->getRoot(), item_only, dkey); } Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); diff --git a/src/helper/pixbuf-ops.h b/src/helper/pixbuf-ops.h index 61a879f9b..067bc0be4 100644 --- a/src/helper/pixbuf-ops.h +++ b/src/helper/pixbuf-ops.h @@ -17,12 +17,12 @@ class SPDocument; namespace Inkscape { class Pixbuf; } -bool sp_export_jpg_file (SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, - unsigned int width, unsigned int height, double xdpi, double ydpi, unsigned long bgcolor, double quality, GSList *items_only = NULL); + bool sp_export_jpg_file (SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, + unsigned int width, unsigned int height, double xdpi, double ydpi, unsigned long bgcolor, double quality, SPItem *item_only = NULL); Inkscape::Pixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned width, unsigned height, double xdpi, double ydpi, - unsigned long bgcolor, GSList *items_only = NULL); + unsigned long bgcolor, SPItem *item_only = NULL); #endif diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index 7f20dee95..9a73b9eca 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -800,7 +800,7 @@ void Layout::fitToPathAlign(SVGLength const &startOffset, Path const &path) SPCurve *Layout::convertToCurves(iterator const &from_glyph, iterator const &to_glyph) const { - GSList *cc = NULL; + std::list<SPCurve *> cc; for (int glyph_index = from_glyph._glyph_index ; glyph_index < to_glyph._glyph_index ; glyph_index++) { Geom::Affine glyph_matrix; @@ -811,22 +811,14 @@ SPCurve *Layout::convertToCurves(iterator const &from_glyph, iterator const &to_ if (pathv) { Geom::PathVector pathv_trans = (*pathv) * glyph_matrix; SPCurve *c = new SPCurve(pathv_trans); - if (c) cc = g_slist_prepend(cc, c); + if (c) cc.push_back(c); } } - cc = g_slist_reverse(cc); + SPCurve *curve = new SPCurve(cc); - SPCurve *curve; - if ( cc ) { - curve = SPCurve::concat(cc); - } else { - curve = new SPCurve(); - } - - while (cc) { + for (auto i:cc) { /* fixme: This is dangerous, as we are mixing art_alloc and g_new */ - reinterpret_cast<SPCurve *>(cc->data)->unref(); - cc = g_slist_remove(cc, cc->data); + i->unref(); } return curve; diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 7840c4ca8..043d47517 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -237,13 +237,12 @@ ObjectSet::breakApart(bool skip_undo) item->deleteObject(false); - GSList *list = curve->split(); + std::list<SPCurve *> list = curve->split(); curve->unref(); std::vector<Inkscape::XML::Node*> reprs; - for (GSList *l = list; l != NULL; l = l->next) { - curve = (SPCurve *) l->data; + for (auto curve:list) { Inkscape::XML::Node *repr = parent->document()->createElement("svg:path"); repr->setAttribute("style", style); @@ -266,7 +265,7 @@ ObjectSet::breakApart(bool skip_undo) repr->setPosition(pos > 0 ? pos : 0); // if it's the first one, restore id - if (l == list) + if (curve == *(list.begin())) repr->setAttribute("id", id); reprs.push_back(repr); @@ -275,7 +274,6 @@ ObjectSet::breakApart(bool skip_undo) } setReprList(reprs); - g_slist_free(list); g_free(style); g_free(path_effect); } diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 4f7657f4f..3318b5e6b 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -50,8 +50,6 @@ namespace Dialog { SpellCheck::SpellCheck (void) : UI::Widget::Panel ("", "/dialogs/spellcheck/", SP_VERB_DIALOG_SPELLCHECK), - _rects(NULL), - _seen_objects(NULL), _text(NULL), _layout(NULL), _stops(0), @@ -196,12 +194,11 @@ void SpellCheck::setTargetDesktop(SPDesktop *desktop) void SpellCheck::clearRects() { - for (GSList *it = _rects; it; it = it->next) { - sp_canvas_item_hide(SP_CANVAS_ITEM(it->data)); - sp_canvas_item_destroy(SP_CANVAS_ITEM(it->data)); + for(auto t : _rects) { + sp_canvas_item_hide(t); + sp_canvas_item_destroy(t); } - g_slist_free(_rects); - _rects = NULL; + _rects.clear(); } void SpellCheck::disconnect() @@ -214,47 +211,39 @@ void SpellCheck::disconnect() } } -GSList *SpellCheck::allTextItems (SPObject *r, GSList *l, bool hidden, bool locked) +void SpellCheck::allTextItems (SPObject *r, std::vector<SPItem *> &l, bool hidden, bool locked) { if (!desktop) - return l; // no desktop to check + return; // no desktop to check if (SP_IS_DEFS(r)) - return l; // we're not interested in items in defs + return; // we're not interested in items in defs if (!strcmp(r->getRepr()->name(), "svg:metadata")) { - return l; // we're not interested in metadata + return; // we're not interested in metadata } for (auto& child: r->children) { if (SP_IS_ITEM (&child) && !child.cloned && !desktop->isLayer(SP_ITEM(&child))) { if ((hidden || !desktop->itemIsHidden(SP_ITEM(&child))) && (locked || !SP_ITEM(&child)->isLocked())) { if (SP_IS_TEXT(&child) || SP_IS_FLOWTEXT(&child)) - l = g_slist_prepend (l, &child); + l.push_back(static_cast<SPItem*>(&child)); } } - l = allTextItems (&child, l, hidden, locked); + allTextItems (&child, l, hidden, locked); } - return l; + return; } bool SpellCheck::textIsValid (SPObject *root, SPItem *text) { - GSList *l = NULL; - l = allTextItems (root, l, false, true); - for (GSList *i = l; i; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); - if (item == text) { - g_slist_free (l); - return true; - } - } - g_slist_free (l); - return false; + std::vector<SPItem*> l; + allTextItems (root, l, false, true); + return (std::find(l.begin(), l.end(), text) != l.end()); } -gint SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b) +bool SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b)//returns a<b { SPItem *i1 = SP_ITEM(a); SPItem *i2 = SP_ITEM(b); @@ -262,41 +251,28 @@ gint SpellCheck::compareTextBboxes (gconstpointer a, gconstpointer b) Geom::OptRect bbox1 = i1->desktopVisualBounds(); Geom::OptRect bbox2 = i2->desktopVisualBounds(); if (!bbox1 || !bbox2) { - return 0; + return false; } // vector between top left corners Geom::Point diff = Geom::Point(bbox2->min()[Geom::X], bbox2->max()[Geom::Y]) - Geom::Point(bbox1->min()[Geom::X], bbox1->max()[Geom::Y]); - // sort top to bottom, left to right, but: - // if i2 is higher only 0.2 or less times it is righter than i1, put i1 first - if (diff[Geom::Y] > 0.2 * diff[Geom::X]) - return 1; - else - return -1; - - return 0; + return diff[Geom::Y] == 0 ? (diff[Geom::X] < 0) : (diff[Geom::Y] < 0); } // We regenerate and resort the list every time, because user could have changed it while the // dialog was waiting SPItem *SpellCheck::getText (SPObject *root) { - GSList *l = NULL; - l = allTextItems (root, l, false, true); - l = g_slist_sort(l, (GCompareFunc)SpellCheck::compareTextBboxes); - - for (GSList *i = l; i; i = i->next) { - SPItem *item = static_cast<SPItem *>(i->data); - if (!g_slist_find (_seen_objects, item)) { - _seen_objects = g_slist_prepend(_seen_objects, item); - g_slist_free(l); + std::vector<SPItem*> l; + allTextItems (root, l, false, true); + std::sort(l.begin(),l.end(),SpellCheck::compareTextBboxes); + + for (auto item:l) { + if(_seen_objects.insert(item).second) return item; - } } - - g_slist_free(l); return NULL; } @@ -402,8 +378,7 @@ SpellCheck::init(SPDesktop *d) _root = desktop->getDocument()->getRoot(); // empty the list of objects we've checked - g_slist_free (_seen_objects); - _seen_objects = NULL; + _seen_objects.clear(); // grab first text nextText(); @@ -456,8 +431,7 @@ SpellCheck::finished () g_free(label); } - g_slist_free(_seen_objects); - _seen_objects = NULL; + _seen_objects.clear(); desktop = NULL; _root = NULL; @@ -615,7 +589,7 @@ SpellCheck::nextWord() curve->lineto(area.corner(0)); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve); sp_canvas_item_show(rect); - _rects = g_slist_prepend(_rects, rect); + _rects.push_back(rect); // scroll to make it all visible Geom::Point const center = desktop->get_display_area().midpoint(); @@ -707,10 +681,10 @@ SpellCheck::nextWord() void SpellCheck::deleteLastRect () { - if (_rects) { - sp_canvas_item_hide(SP_CANVAS_ITEM(_rects->data)); - sp_canvas_item_destroy(SP_CANVAS_ITEM(_rects->data)); - _rects = _rects->next; // pop latest-prepended rect + if (!_rects.empty()) { + sp_canvas_item_hide(_rects.back()); + sp_canvas_item_destroy(_rects.back()); + _rects.pop_back(); // pop latest-prepended rect } } @@ -861,7 +835,6 @@ SpellCheck::onStart () } } - /* Local Variables: mode:c++ diff --git a/src/ui/dialog/spellcheck.h b/src/ui/dialog/spellcheck.h index 834f23c24..e7563ad1e 100644 --- a/src/ui/dialog/spellcheck.h +++ b/src/ui/dialog/spellcheck.h @@ -16,6 +16,9 @@ # include <config.h> #endif +#include <vector> +#include <set> + #include <gtkmm/box.h> #include <gtkmm/button.h> #include <gtkmm/buttonbox.h> @@ -68,7 +71,7 @@ private: /** * Returns a list of all the text items in the SPObject */ - GSList *allTextItems (SPObject *r, GSList *l, bool hidden, bool locked); + void allTextItems (SPObject *r, std::vector<SPItem *> &l, bool hidden, bool locked); /** * Is text inside the SPOject's tree @@ -78,7 +81,7 @@ private: /** * Compare the visual bounds of 2 SPItems referred to by a and b */ - static gint compareTextBboxes (gconstpointer a, gconstpointer b); + static bool compareTextBboxes (gconstpointer a, gconstpointer b); SPItem *getText (SPObject *root); void nextText (); @@ -165,12 +168,12 @@ private: /** * list of canvasitems (currently just rects) that mark misspelled things on canvas */ - GSList *_rects; + std::vector<SPCanvasItem *> _rects; /** * list of text objects we have already checked in this session */ - GSList *_seen_objects; + std::set<SPItem *> _seen_objects; /** * the object currently being checked diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index b876fa98c..558b0b19e 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -617,52 +617,48 @@ void SymbolsDialog::get_symbols() { } } -GSList* SymbolsDialog::symbols_in_doc_recursive (SPObject *r, GSList *l) +void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector<SPSymbol*> &l) { - g_return_val_if_fail(r != NULL, l); + if(!r) return; // Stop multiple counting of same symbol if ( dynamic_cast<SPUse *>(r) ) { - return l; + return; } if ( dynamic_cast<SPSymbol *>(r) ) { - l = g_slist_prepend (l, r); + l.push_back(dynamic_cast<SPSymbol *>(r)); } for (auto& child: r->children) { - l = symbols_in_doc_recursive( &child, l ); + symbols_in_doc_recursive( &child, l ); } - - return l; } -GSList* SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument ) { +std::vector<SPSymbol*> SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument ) +{ - GSList *l = NULL; - l = symbols_in_doc_recursive (symbolDocument->getRoot(), l ); - l = g_slist_reverse( l ); + std::vector<SPSymbol*> l; + symbols_in_doc_recursive (symbolDocument->getRoot(), l ); return l; } -GSList* SymbolsDialog::use_in_doc_recursive (SPObject *r, GSList *l) +void SymbolsDialog::use_in_doc_recursive (SPObject *r, std::vector<SPUse*> &l) { if ( dynamic_cast<SPUse *>(r) ) { - l = g_slist_prepend (l, r); + l.push_back(dynamic_cast<SPUse *>(r)); } for (auto& child: r->children) { - l = use_in_doc_recursive( &child, l ); + use_in_doc_recursive( &child, l ); } - - return l; } -GSList* SymbolsDialog::use_in_doc( SPDocument* useDocument ) { +std::vector<SPUse*> SymbolsDialog::use_in_doc( SPDocument* useDocument ) { - GSList *l = NULL; - l = use_in_doc_recursive (useDocument->getRoot(), l ); + std::vector<SPUse*> l; + use_in_doc_recursive (useDocument->getRoot(), l); return l; } @@ -671,10 +667,8 @@ GSList* SymbolsDialog::use_in_doc( SPDocument* useDocument ) { gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* document) { gchar const* style = 0; - GSList* l = use_in_doc( document ); - for( ; l != NULL; l = l->next ) { - SPObject *obj = reinterpret_cast<SPObject *>(l->data); - SPUse *use = dynamic_cast<SPUse *>(obj); + std::vector<SPUse*> l = use_in_doc( document ); + for( auto use:l ) { if ( use ) { gchar const *href = use->getRepr()->attribute("xlink:href"); if( href ) { @@ -693,10 +687,8 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen void SymbolsDialog::add_symbols( SPDocument* symbolDocument ) { - GSList* l = symbols_in_doc( symbolDocument ); - for( ; l != NULL; l = l->next ) { - SPObject *obj = reinterpret_cast<SPObject *>(l->data); - SPSymbol *symbol = dynamic_cast<SPSymbol *>(obj); + std::vector<SPSymbol*> l = symbols_in_doc( symbolDocument ); + for(auto symbol:l) { if (symbol) { add_symbol( symbol ); } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 5dc1e3cad..747e5c6c9 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -14,10 +14,10 @@ #define INKSCAPE_UI_DIALOG_SYMBOLS_H #include "display/drawing.h" - #include "ui/dialog/desktop-tracker.h" - #include "ui/widget/panel.h" +#include "sp-symbol.h" +#include "sp-use.h" #include <vector> @@ -85,10 +85,10 @@ private: void add_symbol( SPObject* symbol_document ); SPDocument* symbols_preview_doc(); - GSList* symbols_in_doc_recursive(SPObject *r, GSList *l); - GSList* symbols_in_doc( SPDocument* document ); - GSList* use_in_doc_recursive(SPObject *r, GSList *l); - GSList* use_in_doc( SPDocument* document ); + void symbols_in_doc_recursive(SPObject *r, std::vector<SPSymbol*> &l); + std::vector<SPSymbol*> symbols_in_doc( SPDocument* document ); + void use_in_doc_recursive(SPObject *r, std::vector<SPUse*> &l); + std::vector<SPUse*> use_in_doc( SPDocument* document ); gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr<Gdk::Pixbuf> draw_symbol(SPObject *symbol); diff --git a/src/ui/tool/manipulator.h b/src/ui/tool/manipulator.h index 07e01a656..0f26c6de1 100644 --- a/src/ui/tool/manipulator.h +++ b/src/ui/tool/manipulator.h @@ -98,16 +98,17 @@ public: bool empty() { return _mmap.empty(); } - void setItems(GSList const *list) { + + void setItems(std::vector<gpointer> list) { // this function is not called anywhere ... delete ? std::set<void*> to_remove; for (typename MapType::iterator mi = _mmap.begin(); mi != _mmap.end(); ++mi) { to_remove.insert(mi->first); } - for (GSList *i = const_cast<GSList*>(list); i; i = i->next) { - if (_isItemType(i->data)) { + for (auto i:list) { + if (_isItemType(i)) { // erase returns the number of items removed // if nothing was removed, it means this item did not have a manipulator - add it - if (!to_remove.erase(i->data)) addItem(i->data); + if (!to_remove.erase(i)) addItem(i); } } typedef typename std::set<void*>::iterator RmIter; diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index 3e00fe69c..ca94ac75f 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -421,10 +421,9 @@ void CalligraphicTool::cancel() { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); /* Remove all temporary line segments */ - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); - } + for (auto i:this->segments) + sp_canvas_item_destroy(SP_CANVAS_ITEM(i)); + this->segments.clear(); /* reset accumulated curve */ this->accumulated->reset(); @@ -731,10 +730,9 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { this->apply(motion_dt); /* Remove all temporary line segments */ - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); - } + for (auto i:this->segments) + sp_canvas_item_destroy(SP_CANVAS_ITEM(i)); + this->segments.clear(); /* Create object */ this->fit_and_split(true); @@ -1089,7 +1087,7 @@ void CalligraphicTool::fit_and_split(bool release) { this->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); } // FIXME: dc->segments is always NULL at this point?? - if (!this->segments) { // first segment + if (this->segments.empty()) { // first segment add_cap(this->currentcurve, b2[0], b1[0], this->cap_rounding); } this->currentcurve->closepath(); @@ -1143,8 +1141,8 @@ void CalligraphicTool::fit_and_split(bool release) { sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cbp), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* fixme: Cannot we cascade it to root more clearly? */ g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), desktop); - - this->segments = g_slist_prepend(this->segments, cbp); + + this->segments.push_back(cbp); } this->point1[0] = this->point1[this->npoints - 1]; diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp index bb4989333..1026c26c6 100644 --- a/src/ui/tools/dynamic-base.cpp +++ b/src/ui/tools/dynamic-base.cpp @@ -21,7 +21,6 @@ namespace Tools { DynamicBase::DynamicBase(gchar const *const *cursor_shape) : ToolBase(cursor_shape) , accumulated(NULL) - , segments(NULL) , currentshape(NULL) , currentcurve(NULL) , cal1(NULL) @@ -62,10 +61,10 @@ DynamicBase::~DynamicBase() { this->accumulated = 0; } - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); + for (auto i:segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(i)); } + segments.clear(); if (this->currentcurve) { this->currentcurve = this->currentcurve->unref(); diff --git a/src/ui/tools/dynamic-base.h b/src/ui/tools/dynamic-base.h index e270052f3..b9ffd71ce 100644 --- a/src/ui/tools/dynamic-base.h +++ b/src/ui/tools/dynamic-base.h @@ -20,6 +20,7 @@ */ #include "ui/tools/tool-base.h" +#include "display/sp-canvas-item.h" struct SPCanvasItem; class SPCurve; @@ -48,7 +49,7 @@ protected: SPCurve *accumulated; /** canvas items for "committed" segments */ - GSList *segments; + std::vector<SPCanvasItem*> segments; /** canvas item for red "leading" segment */ SPCanvasItem *currentshape; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index b919c138c..83039be18 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -360,10 +360,9 @@ void EraserTool::cancel() { this->is_drawing = false; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0); /* Remove all temporary line segments */ - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); - } + for (auto i : this->segments) + sp_canvas_item_destroy(SP_CANVAS_ITEM(i)); + this->segments.clear(); /* reset accumulated curve */ this->accumulated->reset(); this->clear_current(); @@ -464,10 +463,9 @@ bool EraserTool::root_handler(GdkEvent* event) { this->apply(motion_dt); /* Remove all temporary line segments */ - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); - } + for (auto i : this->segments) + sp_canvas_item_destroy(SP_CANVAS_ITEM(i)); + this->segments.clear(); /* Create object */ this->fit_and_split(true); @@ -1015,7 +1013,7 @@ void EraserTool::fit_and_split(bool release) { } // FIXME: this->segments is always NULL at this point?? - if (!this->segments) { // first segment + if (this->segments.empty()) { // first segment add_cap(this->currentcurve, b2[1], b2[0], b1[0], b1[1], this->cap_rounding); } @@ -1072,7 +1070,7 @@ void EraserTool::fit_and_split(bool release) { /* fixme: Cannot we cascade it to root more clearly? */ g_signal_connect(G_OBJECT(cbp), "event", G_CALLBACK(sp_desktop_root_handler), desktop); - this->segments = g_slist_prepend(this->segments, cbp); + this->segments.push_back(cbp); if (eraser_mode == ERASER_MODE_DELETE) { sp_canvas_item_hide(cbp); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index fce17542a..a85c89400 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -76,13 +76,10 @@ FreehandBase::FreehandBase(gchar const *const *cursor_shape) , red_curve(NULL) , blue_bpath(NULL) , blue_curve(NULL) - , green_bpaths(NULL) , green_curve(NULL) , green_anchor(NULL) , green_closed(false) , white_item(NULL) - , white_curves(NULL) - , white_anchors(NULL) , overwrite_curve(NULL) , sa(NULL) , ea(NULL) @@ -558,22 +555,20 @@ static void spdc_attach_selection(FreehandBase *dc, Inkscape::Selection */*sel*/ SPCurve *norm = SP_PATH(item)->get_curve_for_edit(); norm->transform((dc->white_item)->i2dt_affine()); g_return_if_fail( norm != NULL ); - dc->white_curves = g_slist_reverse(norm->split()); + dc->white_curves = norm->split(); norm->unref(); // Anchor list - for (GSList *l = dc->white_curves; l != NULL; l = l->next) { - SPCurve *c; - c = static_cast<SPCurve*>(l->data); + for (auto c:dc->white_curves) { g_return_if_fail( c->get_segment_count() > 0 ); if ( !c->is_closed() ) { SPDrawAnchor *a; a = sp_draw_anchor_new(dc, c, TRUE, *(c->first_point())); if (a) - dc->white_anchors = g_slist_prepend(dc->white_anchors, a); + dc->white_anchors.push_back(a); a = sp_draw_anchor_new(dc, c, FALSE, *(c->last_point())); if (a) - dc->white_anchors = g_slist_prepend(dc->white_anchors, a); + dc->white_anchors.push_back(a); } } // fixme: recalculate active anchor? @@ -645,10 +640,9 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // Green dc->green_curve = new SPCurve(); - while (dc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->green_bpaths->data)); - dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data); - } + for (auto i : dc->green_bpaths) + sp_canvas_item_destroy(i); + dc->green_bpaths.clear(); // Blue c->append_continuous(dc->blue_curve, 0.0625); @@ -698,8 +692,8 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) c->unref(); dc->overwrite_curve->closepath_current(); if(dc->sa){ - dc->white_curves = g_slist_remove(dc->white_curves, dc->sa->curve); - dc->white_curves = g_slist_append(dc->white_curves, dc->overwrite_curve); + dc->white_curves.erase(std::find(dc->white_curves.begin(),dc->white_curves.end(), dc->sa->curve)); + dc->white_curves.push_back(dc->overwrite_curve); } }else{ dc->sa->curve->append_continuous(c, 0.0625); @@ -713,7 +707,7 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) // Step C - test start if (dc->sa) { SPCurve *s = dc->sa->curve; - dc->white_curves = g_slist_remove(dc->white_curves, s); + dc->white_curves.erase(std::find(dc->white_curves.begin(),dc->white_curves.end(), s)); if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ s = dc->overwrite_curve; @@ -726,7 +720,7 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) c = s; } else /* Step D - test end */ if (dc->ea) { SPCurve *e = dc->ea->curve; - dc->white_curves = g_slist_remove(dc->white_curves, e); + dc->white_curves.erase(std::find(dc->white_curves.begin(),dc->white_curves.end(), e)); if (!dc->ea->start) { e = reverse_then_unref(e); } @@ -766,11 +760,10 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) { SPCurve *c; - if (dc->white_curves) { + if (! dc->white_curves.empty()) { g_assert(dc->white_item); c = SPCurve::concat(dc->white_curves); - g_slist_free(dc->white_curves); - dc->white_curves = NULL; + dc->white_curves.clear(); if (gc) { c->append(gc, FALSE); } @@ -856,8 +849,8 @@ SPDrawAnchor *spdc_test_inside(FreehandBase *dc, Geom::Point p) active = sp_draw_anchor_test(dc->green_anchor, p, TRUE); } - for (GSList *l = dc->white_anchors; l != NULL; l = l->next) { - SPDrawAnchor *na = sp_draw_anchor_test(static_cast<SPDrawAnchor*>(l->data), p, !active); + for (auto i:dc->white_anchors) { + SPDrawAnchor *na = sp_draw_anchor_test(i, p, !active); if ( !active && na ) { active = na; } @@ -871,14 +864,12 @@ static void spdc_reset_white(FreehandBase *dc) // We do not hold refcount dc->white_item = NULL; } - while (dc->white_curves) { - reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref(); - dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data); - } - while (dc->white_anchors) { - sp_draw_anchor_destroy(static_cast<SPDrawAnchor*>(dc->white_anchors->data)); - dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data); - } + for (auto i: dc->white_curves) + i->unref(); + dc->white_curves.clear(); + for (auto i:dc->white_anchors) + sp_draw_anchor_destroy(i); + dc->white_anchors.clear(); } static void spdc_free_colors(FreehandBase *dc) @@ -902,10 +893,9 @@ static void spdc_free_colors(FreehandBase *dc) } // Green - while (dc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->green_bpaths->data)); - dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data); - } + for (auto i : dc->green_bpaths) + sp_canvas_item_destroy(i); + dc->green_bpaths.clear(); if (dc->green_curve) { dc->green_curve = dc->green_curve->unref(); } @@ -918,14 +908,12 @@ static void spdc_free_colors(FreehandBase *dc) // We do not hold refcount dc->white_item = NULL; } - while (dc->white_curves) { - reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref(); - dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data); - } - while (dc->white_anchors) { - sp_draw_anchor_destroy(static_cast<SPDrawAnchor *>(dc->white_anchors->data)); - dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data); - } + for (auto i: dc->white_curves) + i->unref(); + dc->white_curves.clear(); + for (auto i:dc->white_anchors) + sp_draw_anchor_destroy(i); + dc->white_anchors.clear(); } void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *tool, guint event_state) { diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index a3069aa09..dc114ef68 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -66,15 +66,15 @@ public: SPCurve *blue_curve; // Green - GSList *green_bpaths; + std::vector<SPCanvasItem*> green_bpaths; SPCurve *green_curve; SPDrawAnchor *green_anchor; gboolean green_closed; // a flag meaning we hit the green anchor, so close the path on itself // White SPItem *white_item; - GSList *white_curves; - GSList *white_anchors; + std::list<SPCurve *> white_curves; + std::vector<SPDrawAnchor*> white_anchors; // Alternative curve to use on continuing the exisiting curve in case of // bspline or spirolive, because using anchor curves gives random memory diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 0db5c3954..f8dfd7a10 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -860,18 +860,18 @@ bool PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { void PenTool::_redrawAll() { // green - if (this->green_bpaths) { + if (! this->green_bpaths.empty()) { // remove old piecewise green canvasitems - while (this->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + for (auto i : this->green_bpaths){ + sp_canvas_item_destroy(i); } + this->green_bpaths.clear(); // one canvas bpath for all of green_curve SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO); - this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape); + this->green_bpaths.push_back(canvas_shape); } if (this->green_anchor) { SP_CTRL(this->green_anchor->ctrl)->moveto(this->green_anchor->dp); @@ -1253,10 +1253,10 @@ void PenTool::_resetColors() { this->blue_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL, true); // Green - while (this->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + for (auto i:this->green_bpaths) { + sp_canvas_item_destroy(i); } + this->green_bpaths.clear(); this->green_curve->reset(); if (this->green_anchor) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); @@ -1332,17 +1332,17 @@ void PenTool::_bsplineSpiroColor() } //We erase all the "green_bpaths" to recreate them after with the colour //transparency recently modified - if (this->green_bpaths) { + if (!this->green_bpaths.empty()) { // remove old piecewise green canvasitems - while (this->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + for (auto i:this->green_bpaths) { + sp_canvas_item_destroy(i); } + this->green_bpaths.clear(); // one canvas bpath for all of green_curve SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO); - this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape); + this->green_bpaths.push_back(canvas_shape); } sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); } @@ -1555,18 +1555,18 @@ void PenTool::_bsplineSpiroMotion(guint const state){ this->overwrite_curve = tmp_curve->copy(); } } - if (this->green_bpaths) { + if (!this->green_bpaths.empty()) { this->green_curve = tmp_curve->copy(); // remove old piecewise green canvasitems - while (this->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + for (auto i: this->green_bpaths) { + sp_canvas_item_destroy(i); } + this->green_bpaths.clear(); // one canvas bpath for all of green_curve SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO); - this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape); + this->green_bpaths.push_back(canvas_shape); } } if (cubic) { @@ -1927,7 +1927,7 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) { curve->unref(); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape); + this->green_bpaths.push_back(canvas_shape); this->p[0] = this->p[3]; this->p[1] = this->p[4]; @@ -1953,11 +1953,9 @@ bool PenTool::_undoLastPoint() { // Reset red curve this->red_curve->reset(); // Destroy topmost green bpath - if (this->green_bpaths) { - if (this->green_bpaths->data) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - } - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + if (!this->green_bpaths.empty()) { + sp_canvas_item_destroy(this->green_bpaths.back()); + this->green_bpaths.pop_back(); } // Get last segment if ( this->green_curve->is_unset() ) { @@ -1985,11 +1983,9 @@ bool PenTool::_undoLastPoint() { // delete the last segment of the green curve if (this->green_curve->get_segment_count() == 1) { this->npoints = 5; - if (this->green_bpaths) { - if (this->green_bpaths->data) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - } - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + if (!this->green_bpaths.empty()) { + sp_canvas_item_destroy(this->green_bpaths.back()); + this->green_bpaths.pop_back(); } this->green_curve->reset(); } else { diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 99b8103c3..61799b306 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -437,10 +437,10 @@ void PencilTool::_cancel() { this->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); - while (this->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); - this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + for (auto i:this->green_bpaths) { + sp_canvas_item_destroy(i); } + this->green_bpaths.clear(); this->green_curve->reset(); if (this->green_anchor) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); @@ -858,7 +858,7 @@ void PencilTool::_fitAndSplit() { } sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); + this->green_bpaths.push_back(cshape); this->red_curve_is_valid = false; } diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 68acddfcc..5d911e9d2 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -139,7 +139,6 @@ SelectedStyle::SelectedStyle(bool /*layout*/) _opacity_blocked (false), - _unit_mis(NULL), _sw_unit(NULL) { set_name("SelectedStyle"); @@ -336,7 +335,7 @@ SelectedStyle::SelectedStyle(bool /*layout*/) while(iter != m.end()) { Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group)); mi->add(*(new Gtk::Label(iter->first, Gtk::ALIGN_START))); - _unit_mis = g_slist_append(_unit_mis, mi); + _unit_mis.push_back(mi); Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first); mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit const *>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u)); _popup_sw.attach(*mi, 0,1, row, row+1); @@ -449,6 +448,7 @@ SelectedStyle::~SelectedStyle() delete selection_modified_connection; subselection_changed_connection->disconnect(); delete subselection_changed_connection; + _unit_mis.clear(); for (int i = SS_FILL; i <= SS_STROKE; i++) { delete _color_preview[i]; @@ -488,9 +488,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) _sw_unit = desktop->getNamedView()->display_units; // Set the doc default unit active in the units list - gint length = g_slist_length(_unit_mis); - for (int i = 0; i < length; i++) { - Gtk::RadioMenuItem *mi = (Gtk::RadioMenuItem *) g_slist_nth_data(_unit_mis, i); + for ( auto mi:_unit_mis ) { if (mi && mi->get_label() == _sw_unit->abbr) { mi->set_active(); break; diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index 065d745f0..b7f3d5dda 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -267,7 +267,7 @@ protected: Gtk::Menu _popup_sw; Gtk::RadioButtonGroup _sw_group; - GSList *_unit_mis; + std::vector<Gtk::RadioMenuItem*> _unit_mis; void on_popup_units(Inkscape::Util::Unit const *u); void on_popup_preset(int i); Gtk::MenuItem _popup_sw_remove; diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index a1501c229..d36220b74 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -14,7 +14,7 @@ #include "style-internal.h" #include "unit-tracker.h" -#include "widgets/ege-select-one-action.h" +//#include "widgets/ege-select-one-action.h" #define COLUMN_STRING 0 @@ -31,9 +31,6 @@ UnitTracker::UnitTracker(UnitType unit_type) : _activeUnit(NULL), _activeUnitInitialized(false), _store(0), - _unitList(0), - _actionList(0), - _adjList(0), _priorValues() { _store = gtk_list_store_new(1, G_TYPE_STRING); @@ -58,17 +55,17 @@ UnitTracker::UnitTracker(UnitType unit_type) : UnitTracker::~UnitTracker() { // Unhook weak references to GtkActions - while (_actionList) { - g_signal_handlers_disconnect_by_func(G_OBJECT(_actionList->data), (gpointer) _unitChangedCB, this); - g_object_weak_unref(G_OBJECT(_actionList->data), _actionFinalizedCB, this); - _actionList = g_slist_delete_link(_actionList, _actionList); + for (auto i : _actionList) { + g_signal_handlers_disconnect_by_func(G_OBJECT(i), (gpointer) _unitChangedCB, this); + g_object_weak_unref(G_OBJECT(i), _actionFinalizedCB, this); } + _actionList.clear(); // Unhook weak references to GtkAdjustments - while (_adjList) { - g_object_weak_unref(G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this); - _adjList = g_slist_delete_link(_adjList, _adjList); + for (auto i : _adjList) { + g_object_weak_unref(G_OBJECT(i), _adjustmentFinalizedCB, this); } + _adjList.clear(); } bool UnitTracker::isUpdating() const @@ -109,9 +106,9 @@ void UnitTracker::setActiveUnitByAbbr(gchar const *abbr) void UnitTracker::addAdjustment(GtkAdjustment *adj) { - if (!g_slist_find(_adjList, adj)) { + if (std::find(_adjList.begin(),_adjList.end(),adj)!=_adjList.end()) { g_object_weak_ref(G_OBJECT(adj), _adjustmentFinalizedCB, this); - _adjList = g_slist_append(_adjList, adj); + _adjList.push_back(adj); } } @@ -147,7 +144,7 @@ GtkAction *UnitTracker::createAction(gchar const *name, gchar const *label, gcha ege_select_one_action_set_appearance(act1, "minimal"); g_object_weak_ref(G_OBJECT(act1), _actionFinalizedCB, this); g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(_unitChangedCB), this); - _actionList = g_slist_append(_actionList, act1); + _actionList.push_back(act1); return GTK_ACTION(act1); } @@ -180,9 +177,10 @@ void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_objec void UnitTracker::_actionFinalized(GObject *where_the_object_was) { - GSList *target = g_slist_find(_actionList, where_the_object_was); - if (target) { - _actionList = g_slist_remove(_actionList, where_the_object_was); + EgeSelectOneAction* act = (EgeSelectOneAction*)(where_the_object_was); + auto it = std::find(_actionList.begin(),_actionList.end(), act); + if (it != _actionList.end()) { + _actionList.erase(it); } else { g_warning("Received a finalization callback for unknown object %p", where_the_object_was); } @@ -190,9 +188,10 @@ void UnitTracker::_actionFinalized(GObject *where_the_object_was) void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was) { - GSList *target = g_slist_find(_adjList, where_the_object_was); - if (target) { - _adjList = g_slist_remove(_adjList, where_the_object_was); + GtkAdjustment* adj = (GtkAdjustment*)(where_the_object_was); + auto it = std::find(_adjList.begin(),_adjList.end(), adj); + if (it != _adjList.end()) { + _adjList.erase(it); } else { g_warning("Received a finalization callback for unknown object %p", where_the_object_was); } @@ -217,7 +216,7 @@ void UnitTracker::_setActive(gint active) Inkscape::Util::Unit const *newUnit = unit_table.getUnit(newAbbr); _activeUnit = newUnit; - if (_adjList) { + if (!_adjList.empty()) { _fixupAdjustments(unit, newUnit); } @@ -230,11 +229,8 @@ void UnitTracker::_setActive(gint active) _active = active; - for ( GSList *cur = _actionList ; cur ; cur = g_slist_next(cur) ) { - if (IS_EGE_SELECT_ONE_ACTION(cur->data)) { - EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(cur->data); - ege_select_one_action_set_active(act, active); - } + for (auto act:_actionList) { + ege_select_one_action_set_active(act, active); } _activeUnitInitialized = true; @@ -244,8 +240,7 @@ void UnitTracker::_setActive(gint active) void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit) { _isUpdating = true; - for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) { - GtkAdjustment *adj = GTK_ADJUSTMENT(cur->data); + for ( auto adj : _adjList ) { gdouble oldVal = gtk_adjustment_get_value(adj); gdouble val = oldVal; diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index 8fa9ff304..643ac4e51 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -17,6 +17,7 @@ #include <map> #include "util/units.h" +#include "widgets/ege-select-one-action.h" using Inkscape::Util::Unit; using Inkscape::Util::UnitType; @@ -65,9 +66,8 @@ private: Inkscape::Util::Unit const *_activeUnit; bool _activeUnitInitialized; GtkListStore *_store; - GSList *_unitList; - GSList *_actionList; - GSList *_adjList; + std::vector<EgeSelectOneAction*> _actionList; + std::vector<GtkAdjustment*> _adjList; std::map <GtkAdjustment *, gdouble> _priorValues; }; diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index 96994741c..9ddcf993d 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -111,22 +111,20 @@ MarkerComboBox::refreshHistory() updating = true; - GSList *ml = get_marker_list(doc); + std::vector<SPMarker *> ml = get_marker_list(doc); /* * Seems to be no way to get notified of changes just to markers, * so listen to changes in all defs and check if the number of markers has changed here * to avoid unnecessary refreshes when things like gradients change */ - if (markerCount != g_slist_length(ml)) { + if (markerCount != ml.size()) { const char *active = get_active()->get_value(marker_columns.marker); sp_marker_list_from_doc(doc, true); set_selected(active); - markerCount = g_slist_length(ml); + markerCount = ml.size(); } - g_slist_free (ml); - updating = false; } @@ -295,45 +293,32 @@ void MarkerComboBox::set_selected(const gchar *name, gboolean retry/*=true*/) { */ void MarkerComboBox::sp_marker_list_from_doc(SPDocument *source, gboolean history) { - GSList *ml = get_marker_list(source); - GSList *clean_ml = NULL; - - for (; ml != NULL; ml = ml->next) { - if (!SP_IS_MARKER(ml->data)) - continue; - - // Add to the list of markers we really do wish to show - clean_ml = g_slist_prepend (clean_ml, ml->data); - } + std::vector<SPMarker *> ml = get_marker_list(source); remove_markers(history); // Seem to need to remove 2x remove_markers(history); - add_markers(clean_ml, source, history); - - g_slist_free (ml); - g_slist_free (clean_ml); - + add_markers(ml, source, history); } /** - * Returns a list of markers in the defs of the given source document as a GSList object + * Returns a list of markers in the defs of the given source document as a vector * Returns NULL if there are no markers in the document. */ -GSList *MarkerComboBox::get_marker_list (SPDocument *source) +std::vector<SPMarker *> MarkerComboBox::get_marker_list (SPDocument *source) { + std::vector<SPMarker *> ml; if (source == NULL) - return NULL; + return ml; - GSList *ml = NULL; SPDefs *defs = source->getDefs(); if (!defs) { - return NULL; + return ml; } for (auto& child: defs->children) { if (SP_IS_MARKER(&child)) { - ml = g_slist_prepend (ml, &child); + ml.push_back(SP_MARKER(&child)); } } return ml; @@ -361,7 +346,7 @@ void MarkerComboBox::remove_markers (gboolean history) /** * Adds markers in marker_list to the combo */ -void MarkerComboBox::add_markers (GSList *marker_list, SPDocument *source, gboolean history) +void MarkerComboBox::add_markers (std::vector<SPMarker *> const& marker_list, SPDocument *source, gboolean history) { // Do this here, outside of loop, to speed up preview generation: Inkscape::Drawing drawing; @@ -388,9 +373,9 @@ void MarkerComboBox::add_markers (GSList *marker_list, SPDocument *source, gbool row[marker_columns.separator] = false; } - for (; marker_list != NULL; marker_list = marker_list->next) { + for (auto i:marker_list) { - Inkscape::XML::Node *repr = reinterpret_cast<SPItem *>(marker_list->data)->getRepr(); + Inkscape::XML::Node *repr = i->getRepr(); gchar const *markid = repr->attribute("inkscape:stockid") ? repr->attribute("inkscape:stockid") : repr->attribute("id"); // generate preview diff --git a/src/widgets/stroke-marker-selector.h b/src/widgets/stroke-marker-selector.h index a7ee788b8..24389526c 100644 --- a/src/widgets/stroke-marker-selector.h +++ b/src/widgets/stroke-marker-selector.h @@ -9,7 +9,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include <vector> #include <gtkmm/box.h> #include <gtkmm/combobox.h> #include <gtkmm/liststore.h> @@ -20,6 +20,7 @@ #include "document.h" #include "inkscape.h" #include "display/drawing.h" +#include "sp-marker.h" namespace Gtk { class Container; @@ -80,8 +81,8 @@ private: void init_combo(); void set_history(Gtk::TreeModel::Row match_row); void sp_marker_list_from_doc(SPDocument *source, gboolean history); - GSList *get_marker_list (SPDocument *source); - void add_markers (GSList *marker_list, SPDocument *source, gboolean history); + std::vector <SPMarker*> get_marker_list (SPDocument *source); + void add_markers (std::vector<SPMarker *> const& marker_list, SPDocument *source, gboolean history); void remove_markers (gboolean history); SPDocument *ink_markers_preview_doc (); Gtk::Image * create_marker_image(unsigned psize, gchar const *mname, |
