From a7f2b2ba3f13ceb60376802f4a31e104153839e8 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Tue, 17 Feb 2015 03:00:37 +0100 Subject: At first, I was thinking "I just have to go to the selection file, and change that GSList* with a std::list, then resolve the few problems" So, i tried that. And I will continue tomorrow, and the days after, on and on. (bzr r13922.1.1) --- src/text-chemistry.cpp | 83 ++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) (limited to 'src/text-chemistry.cpp') diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 65b59f2ad..391e255a5 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,11 +43,10 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_FLOWTEXT(*i)) + return ((SPItem *) *i); } return NULL; } @@ -55,11 +54,10 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_TEXT(items->data) || SP_IS_FLOWTEXT(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) + return ((SPItem *) *i); } return NULL; } @@ -67,11 +65,10 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - if (SP_IS_SHAPE(items->data)) - return ((SPItem *) items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + if (SP_IS_SHAPE(*i)) + return ((SPItem *) *i); } return NULL; } @@ -90,7 +87,7 @@ text_put_on_path() Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) { + if (!text || !shape || selection->itemList().size() != 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and a path to put text on path.")); return; } @@ -199,11 +196,9 @@ text_remove_from_path() } bool did = false; - - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + SelContainer items(selection->itemList()); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = SP_OBJECT(*i); if (SP_IS_TEXT_TEXTPATH(obj)) { SPObject *tp = obj->firstChild(); @@ -219,7 +214,7 @@ text_remove_from_path() } else { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove text from path")); - selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description + selection->setList(selection->itemList()); // reselect to update statusbar description } } @@ -265,10 +260,9 @@ text_remove_all_kerns() bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { - SPObject *obj = SP_OBJECT(items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPObject *obj = SP_OBJECT(*i); if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; @@ -302,7 +296,7 @@ text_flow_into_shape() SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); - if (!text || !shape || g_slist_length((GSList *) selection->itemList()) < 2) { + if (!text || !shape || selection->itemList().size() < 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and one or more paths or shapes to flow text into frame.")); return; } @@ -326,10 +320,9 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - for (GSList *items = (GSList *) selection->itemList(); - items != NULL; - items = items->next) { - SPItem *item = SP_ITEM(items->data); + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + SPItem *item = SP_ITEM(*i); if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); clone->setAttribute("x", "0"); @@ -394,23 +387,22 @@ text_unflow () Inkscape::Selection *selection = desktop->getSelection(); - if (!flowtext_in_selection(selection) || g_slist_length((GSList *) selection->itemList()) < 1) { + if (!flowtext_in_selection(selection) || selection->itemList().size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a flowed text to unflow it.")); return; } - GSList *new_objs = NULL; + SelContainer new_objs; GSList *old_objs = NULL; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + SelContainer items = selection->itemList(); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - if (!SP_IS_FLOWTEXT(SP_OBJECT(items->data))) { + if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { continue; } - SPItem *flowtext = SP_ITEM(items->data); + SPItem *flowtext = SP_ITEM(*i); // we discard transform when unflowing, but we must preserve expansion which is visible as // font size multiplier @@ -451,7 +443,7 @@ text_unflow () SPText *text = SP_TEXT(text_object); text->_adjustFontsizeRecursive(text, ex); - new_objs = g_slist_prepend (new_objs, text_object); + new_objs.push_front(text_object); old_objs = g_slist_prepend (old_objs, flowtext); Inkscape::GC::release(rtext); @@ -466,7 +458,6 @@ text_unflow () } g_slist_free (old_objs); - g_slist_free (new_objs); DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, _("Unflow flowed text")); @@ -487,11 +478,11 @@ flowtext_to_text() bool did = false; - GSList *reprs = NULL; - GSList *items = g_slist_copy((GSList *) selection->itemList()); - for (; items != NULL; items = items->next) { + SelContainer reprs; + SelContainer items(selection->itemList()); + for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = (SPItem *) *i; if (!SP_IS_FLOWTEXT(item)) continue; @@ -519,10 +510,9 @@ flowtext_to_text() Inkscape::GC::release(repr); item->deleteObject(); - reprs = g_slist_prepend(reprs, repr); + reprs.push_front(dynamic_cast(repr)); } - g_slist_free(items); if (did) { DocumentUndo::done(desktop->getDocument(), @@ -535,7 +525,6 @@ flowtext_to_text() _("No flowed text(s) to convert in the selection.")); } - g_slist_free(reprs); } -- cgit v1.2.3 From 5fd00cab14d48beaf2279a2b8f3ad5b02b76c87b Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 19 Feb 2015 04:25:21 +0100 Subject: Put a few std::vector (bzr r13922.1.5) --- src/text-chemistry.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/text-chemistry.cpp') diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 391e255a5..33192a330 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,8 +43,8 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_FLOWTEXT(*i)) return ((SPItem *) *i); } @@ -54,8 +54,8 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return ((SPItem *) *i); } @@ -65,8 +65,8 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_SHAPE(*i)) return ((SPItem *) *i); } @@ -196,8 +196,8 @@ text_remove_from_path() } bool did = false; - SelContainer items(selection->itemList()); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items(selection->itemList()); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *obj = SP_OBJECT(*i); if (SP_IS_TEXT_TEXTPATH(obj)) { @@ -260,8 +260,8 @@ text_remove_all_kerns() bool did = false; - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPObject *obj = SP_OBJECT(*i); if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { @@ -320,8 +320,8 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = SP_ITEM(*i); if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -392,11 +392,11 @@ text_unflow () return; } - SelContainer new_objs; + std::vector new_objs; GSList *old_objs = NULL; - SelContainer items = selection->itemList(); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector items = selection->itemList(); + for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { continue; @@ -443,7 +443,7 @@ text_unflow () SPText *text = SP_TEXT(text_object); text->_adjustFontsizeRecursive(text, ex); - new_objs.push_front(text_object); + new_objs.push_back((SPItem*)text_object); old_objs = g_slist_prepend (old_objs, flowtext); Inkscape::GC::release(rtext); @@ -478,9 +478,9 @@ flowtext_to_text() bool did = false; - SelContainer reprs; - SelContainer items(selection->itemList()); - for(SelContainer::const_iterator i=items.begin();i!=items.end();i++){ + std::vector reprs; + std::vector items(selection->itemList()); + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ SPItem *item = (SPItem *) *i; @@ -510,7 +510,7 @@ flowtext_to_text() Inkscape::GC::release(repr); item->deleteObject(); - reprs.push_front(dynamic_cast(repr)); + reprs.push_back(repr); } -- cgit v1.2.3 From 9a7fa4d1899d30ec745107823f307b2a0bf3172f Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 27 Feb 2015 03:10:36 +0100 Subject: corrected the casts (hopefully) (bzr r13922.1.10) --- src/text-chemistry.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/text-chemistry.cpp') diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 33192a330..eadab90dd 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -46,7 +46,7 @@ flowtext_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_FLOWTEXT(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -57,7 +57,7 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -68,7 +68,7 @@ shape_in_selection(Inkscape::Selection *selection) std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (SP_IS_SHAPE(*i)) - return ((SPItem *) *i); + return *i; } return NULL; } @@ -402,7 +402,7 @@ text_unflow () continue; } - SPItem *flowtext = SP_ITEM(*i); + SPItem *flowtext = *i; // we discard transform when unflowing, but we must preserve expansion which is visible as // font size multiplier @@ -482,7 +482,7 @@ flowtext_to_text() std::vector items(selection->itemList()); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = (SPItem *) *i; + SPItem *item = *i; if (!SP_IS_FLOWTEXT(item)) continue; -- cgit v1.2.3 From 9bdc157f705ca61516e599cb416580283d21ec35 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Fri, 27 Feb 2015 04:21:48 +0100 Subject: more cast cleanup (bzr r13922.1.11) --- src/text-chemistry.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/text-chemistry.cpp') diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index eadab90dd..5d57ac020 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -198,7 +198,7 @@ text_remove_from_path() bool did = false; std::vector items(selection->itemList()); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *obj = SP_OBJECT(*i); + SPObject *obj = *i; if (SP_IS_TEXT_TEXTPATH(obj)) { SPObject *tp = obj->firstChild(); @@ -262,7 +262,7 @@ text_remove_all_kerns() std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPObject *obj = SP_OBJECT(*i); + SPObject *obj = *i; if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; @@ -322,7 +322,7 @@ text_flow_into_shape() /* Add clones */ std::vector items = selection->itemList(); for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ - SPItem *item = SP_ITEM(*i); + SPItem *item = *i; if (SP_IS_SHAPE(item)){ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); clone->setAttribute("x", "0"); @@ -398,7 +398,7 @@ text_unflow () std::vector items = selection->itemList(); for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ - if (!SP_IS_FLOWTEXT(SP_OBJECT(*i))) { + if (!SP_IS_FLOWTEXT(*i)) { continue; } -- cgit v1.2.3 From 60bdd590969d1c32c392a8fed15f4ceac4a678d2 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 27 Apr 2015 01:12:03 +0200 Subject: Just reread the entire diff against trunk. Given the diff size, i must have forgotten things, but hopefully, there are only very few changes of semantics: ->childList is now in the intuitive order (childList()[0] is now firstChild) -> sp_selection_paste_impl is now in the opposite order (change is local to selection-chemistry.cpp, and simplify a few things) -> selection.setReprList now takes the list in the opposite order. It was always the case (the list was always reversed before handing to it) -> a few comparison functions now work "the c++ way": the C way was to return -1 if ab, now they return (bool)(a items = selection->itemList(); - for(std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for(std::vector::const_iterator i=items.begin();i!=items.end();i++){ if (!SP_IS_FLOWTEXT(*i)) { continue; @@ -452,6 +452,7 @@ text_unflow () } selection->clear(); + reverse(new_objs.begin(),new_objs.end()); selection->setList(new_objs); for (GSList *i = old_objs; i; i = i->next) { SP_OBJECT(i->data)->deleteObject (true); -- cgit v1.2.3