From 058e95a59ccb2ab1748392acdfdbbffd516c9c81 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 11 Jul 2016 14:24:52 +0200 Subject: First part of new SPObject children list (bzr r14954.1.17) --- src/sp-item.cpp | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 9fd6e8ecc..258a5cd14 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -308,50 +308,35 @@ bool is_item(SPObject const &object) { void SPItem::raiseToTop() { using Inkscape::Algorithms::find_last_if; - SPObject *topmost=find_last_if( - next, NULL, &is_item - ); - if (topmost) { + auto topmost = find_last_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); + if (topmost != parent->_children.end()) { getRepr()->parent()->changeOrder( getRepr(), topmost->getRepr() ); } } void SPItem::raiseOne() { - SPObject *next_higher=std::find_if( - next, NULL, &is_item - ); - if (next_higher) { + auto next_higher = std::find_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); + if (next_higher != parent->_children.end()) { Inkscape::XML::Node *ref = next_higher->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); } } void SPItem::lowerOne() { - using Inkscape::Util::MutableList; - using Inkscape::Util::reverse_list; - - MutableList next_lower=std::find_if( - reverse_list( - parent->firstChild(), this - ), - MutableList(), - &is_item - ); - if (next_lower) { - ++next_lower; - Inkscape::XML::Node *ref = ( next_lower ? next_lower->getRepr() : NULL ); + using Inkscape::Algorithms::find_last_if; + + auto next_lower = find_last_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); + if (next_lower != parent->_children.iterator_to(*this)) { + next_lower--; + Inkscape::XML::Node *ref = next_lower->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); } } void SPItem::lowerToBottom() { - using Inkscape::Algorithms::find_last_if; - using Inkscape::Util::MutableList; - using Inkscape::Util::reverse_list; - - SPObject * bottom=parent->firstChild(); - while(dynamic_cast(bottom) && dynamic_cast(bottom->next) && bottom!=this && !is_item(*(bottom->next))) bottom=bottom->next; - if (bottom && bottom != this) { + auto bottom = std::find_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); + if (bottom != parent->_children.iterator_to(*this)) { + bottom--; Inkscape::XML::Node *ref = bottom->getRepr() ; parent->getRepr()->changeOrder(getRepr(), ref); } -- cgit v1.2.3 From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/sp-item.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 258a5cd14..ba57cec8b 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -705,9 +705,9 @@ Inkscape::XML::Node* SPItem::write(Inkscape::XML::Document *xml_doc, Inkscape::X // so we need to add any children from the underlying object to the new repr if (flags & SP_OBJECT_WRITE_BUILD) { GSList *l = NULL; - for (SPObject *child = object->firstChild(); child != NULL; child = child->next ) { - if (dynamic_cast(child) || dynamic_cast(child)) { - Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags); + for (auto& child: object->_children) { + if (dynamic_cast(&child) || dynamic_cast(&child)) { + Inkscape::XML::Node *crepr = child.updateRepr(xml_doc, NULL, flags); if (crepr) { l = g_slist_prepend (l, crepr); } @@ -719,9 +719,9 @@ Inkscape::XML::Node* SPItem::write(Inkscape::XML::Document *xml_doc, Inkscape::X l = g_slist_remove (l, l->data); } } else { - for (SPObject *child = object->firstChild() ; child != NULL; child = child->next ) { - if (dynamic_cast(child) || dynamic_cast(child)) { - child->updateRepr(flags); + for (auto& child: object->_children) { + if (dynamic_cast(&child) || dynamic_cast(&child)) { + child.updateRepr(flags); } } } @@ -928,12 +928,12 @@ unsigned int SPItem::pos_in_parent() const { unsigned int pos = 0; - for ( SPObject *iter = parent->firstChild() ; iter ; iter = iter->next) { - if (iter == this) { + for (auto& iter: parent->_children) { + if (&iter == this) { return pos; } - if (dynamic_cast(iter)) { + if (dynamic_cast(&iter)) { pos++; } } @@ -1666,8 +1666,8 @@ SPItem const *sp_item_first_item_child(SPObject const *obj) SPItem *sp_item_first_item_child(SPObject *obj) { SPItem *child = 0; - for ( SPObject *iter = obj->firstChild() ; iter ; iter = iter->next ) { - SPItem *tmp = dynamic_cast(iter); + for (auto& iter: obj->_children) { + SPItem *tmp = dynamic_cast(&iter); if ( tmp ) { child = tmp; break; -- cgit v1.2.3 From 9e210a6d1333c3366681547e3e81593ef69ff73e Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 12:56:49 +0200 Subject: Last part of new SPObject children list (bzr r14954.1.20) --- src/sp-item.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index ba57cec8b..53b4c0879 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -351,8 +351,8 @@ void SPItem::moveTo(SPItem *target, bool intoafter) { // Assume move to the "first" in the top node, find the top node intoafter = false; SPObject* bottom = this->document->getObjectByRepr(our_ref->root())->firstChild(); - while(!dynamic_cast(bottom->next)){ - bottom=bottom->next; + while(!dynamic_cast(bottom->getNext())){ + bottom = bottom->getNext(); } target_ref = bottom->getRepr(); } @@ -974,8 +974,8 @@ void SPItem::getSnappoints(std::vector &p, Inkscap for (std::list::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); ++o) { if (*o) { // obj is a group object, the children are the actual clippers - for (SPObject *child = (*o)->children ; child ; child = child->next) { - SPItem *item = dynamic_cast(child); + for(auto& child: (*o)->_children) { + SPItem *item = dynamic_cast(const_cast(&child)); if (item) { std::vector p_clip_or_mask; // Please note the recursive call here! @@ -1302,8 +1302,8 @@ void SPItem::adjust_stroke_width_recursive(double expansion) // A clone's child is the ghost of its original - we must not touch it, skip recursion if ( !dynamic_cast(this) ) { - for ( SPObject *o = children; o; o = o->getNext() ) { - SPItem *item = dynamic_cast(o); + for (auto& o: _children) { + SPItem *item = dynamic_cast(&o); if (item) { item->adjust_stroke_width_recursive(expansion); } @@ -1317,8 +1317,8 @@ void SPItem::freeze_stroke_width_recursive(bool freeze) // A clone's child is the ghost of its original - we must not touch it, skip recursion if ( !dynamic_cast(this) ) { - for ( SPObject *o = children; o; o = o->getNext() ) { - SPItem *item = dynamic_cast(o); + for (auto& o: _children) { + SPItem *item = dynamic_cast(&o); if (item) { item->freeze_stroke_width_recursive(freeze); } @@ -1337,10 +1337,10 @@ sp_item_adjust_rects_recursive(SPItem *item, Geom::Affine advertized_transform) rect->compensateRxRy(advertized_transform); } - for (SPObject *o = item->children; o != NULL; o = o->next) { - SPItem *item = dynamic_cast(o); - if (item) { - sp_item_adjust_rects_recursive(item, advertized_transform); + for(auto& o: item->_children) { + SPItem *itm = dynamic_cast(&o); + if (itm) { + sp_item_adjust_rects_recursive(itm, advertized_transform); } } } @@ -1357,8 +1357,8 @@ void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Af // also we do not recurse into clones, because a clone's child is the ghost of its original - // we must not touch it if (!(this && (dynamic_cast(this) || dynamic_cast(this)))) { - for (SPObject *o = children; o != NULL; o = o->next) { - SPItem *item = dynamic_cast(o); + for (auto& o: _children) { + SPItem *item = dynamic_cast(&o); if (item) { // At the level of the transformed item, t_ancestors is identity; // below it, it is the accmmulated chain of transforms from this level to the top level -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/sp-item.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 53b4c0879..69da28c66 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -308,15 +308,15 @@ bool is_item(SPObject const &object) { void SPItem::raiseToTop() { using Inkscape::Algorithms::find_last_if; - auto topmost = find_last_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); - if (topmost != parent->_children.end()) { + auto topmost = find_last_if(++parent->children.iterator_to(*this), parent->children.end(), &is_item); + if (topmost != parent->children.end()) { getRepr()->parent()->changeOrder( getRepr(), topmost->getRepr() ); } } void SPItem::raiseOne() { - auto next_higher = std::find_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); - if (next_higher != parent->_children.end()) { + auto next_higher = std::find_if(++parent->children.iterator_to(*this), parent->children.end(), &is_item); + if (next_higher != parent->children.end()) { Inkscape::XML::Node *ref = next_higher->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); } @@ -325,8 +325,8 @@ void SPItem::raiseOne() { void SPItem::lowerOne() { using Inkscape::Algorithms::find_last_if; - auto next_lower = find_last_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); - if (next_lower != parent->_children.iterator_to(*this)) { + auto next_lower = find_last_if(parent->children.begin(), parent->children.iterator_to(*this), &is_item); + if (next_lower != parent->children.iterator_to(*this)) { next_lower--; Inkscape::XML::Node *ref = next_lower->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); @@ -334,8 +334,8 @@ void SPItem::lowerOne() { } void SPItem::lowerToBottom() { - auto bottom = std::find_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); - if (bottom != parent->_children.iterator_to(*this)) { + auto bottom = std::find_if(parent->children.begin(), parent->children.iterator_to(*this), &is_item); + if (bottom != parent->children.iterator_to(*this)) { bottom--; Inkscape::XML::Node *ref = bottom->getRepr() ; parent->getRepr()->changeOrder(getRepr(), ref); @@ -705,7 +705,7 @@ Inkscape::XML::Node* SPItem::write(Inkscape::XML::Document *xml_doc, Inkscape::X // so we need to add any children from the underlying object to the new repr if (flags & SP_OBJECT_WRITE_BUILD) { GSList *l = NULL; - for (auto& child: object->_children) { + for (auto& child: object->children) { if (dynamic_cast(&child) || dynamic_cast(&child)) { Inkscape::XML::Node *crepr = child.updateRepr(xml_doc, NULL, flags); if (crepr) { @@ -719,7 +719,7 @@ Inkscape::XML::Node* SPItem::write(Inkscape::XML::Document *xml_doc, Inkscape::X l = g_slist_remove (l, l->data); } } else { - for (auto& child: object->_children) { + for (auto& child: object->children) { if (dynamic_cast(&child) || dynamic_cast(&child)) { child.updateRepr(flags); } @@ -928,7 +928,7 @@ unsigned int SPItem::pos_in_parent() const { unsigned int pos = 0; - for (auto& iter: parent->_children) { + for (auto& iter: parent->children) { if (&iter == this) { return pos; } @@ -974,7 +974,7 @@ void SPItem::getSnappoints(std::vector &p, Inkscap for (std::list::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); ++o) { if (*o) { // obj is a group object, the children are the actual clippers - for(auto& child: (*o)->_children) { + for(auto& child: (*o)->children) { SPItem *item = dynamic_cast(const_cast(&child)); if (item) { std::vector p_clip_or_mask; @@ -1302,7 +1302,7 @@ void SPItem::adjust_stroke_width_recursive(double expansion) // A clone's child is the ghost of its original - we must not touch it, skip recursion if ( !dynamic_cast(this) ) { - for (auto& o: _children) { + for (auto& o: children) { SPItem *item = dynamic_cast(&o); if (item) { item->adjust_stroke_width_recursive(expansion); @@ -1317,7 +1317,7 @@ void SPItem::freeze_stroke_width_recursive(bool freeze) // A clone's child is the ghost of its original - we must not touch it, skip recursion if ( !dynamic_cast(this) ) { - for (auto& o: _children) { + for (auto& o: children) { SPItem *item = dynamic_cast(&o); if (item) { item->freeze_stroke_width_recursive(freeze); @@ -1337,7 +1337,7 @@ sp_item_adjust_rects_recursive(SPItem *item, Geom::Affine advertized_transform) rect->compensateRxRy(advertized_transform); } - for(auto& o: item->_children) { + for(auto& o: item->children) { SPItem *itm = dynamic_cast(&o); if (itm) { sp_item_adjust_rects_recursive(itm, advertized_transform); @@ -1357,7 +1357,7 @@ void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Af // also we do not recurse into clones, because a clone's child is the ghost of its original - // we must not touch it if (!(this && (dynamic_cast(this) || dynamic_cast(this)))) { - for (auto& o: _children) { + for (auto& o: children) { SPItem *item = dynamic_cast(&o); if (item) { // At the level of the transformed item, t_ancestors is identity; @@ -1666,7 +1666,7 @@ SPItem const *sp_item_first_item_child(SPObject const *obj) SPItem *sp_item_first_item_child(SPObject *obj) { SPItem *child = 0; - for (auto& iter: obj->_children) { + for (auto& iter: obj->children) { SPItem *tmp = dynamic_cast(&iter); if ( tmp ) { child = tmp; -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/sp-item.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 9fd6e8ecc..01cb2d09f 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -13,7 +13,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "sp-item.h" @@ -33,19 +33,14 @@ #include "sp-clippath.h" #include "sp-mask.h" #include "sp-rect.h" -#include "sp-use.h" #include "sp-text.h" #include "sp-textpath.h" #include "sp-item-rm-unsatisfied-cns.h" #include "sp-pattern.h" -#include "sp-paint-server.h" #include "sp-switch.h" -#include "sp-guide-constraint.h" #include "gradient-chemistry.h" -#include "preferences.h" #include "conn-avoid-ref.h" #include "conditions.h" -#include "sp-filter-reference.h" #include "filter-chemistry.h" #include "sp-guide.h" #include "sp-title.h" @@ -53,13 +48,8 @@ #include "util/find-last-if.h" #include "util/reverse-list.h" -#include <2geom/rect.h> -#include <2geom/affine.h> -#include <2geom/transforms.h> -#include "xml/repr.h" #include "extract-uri.h" -#include "helper/geom.h" #include "live_effects/lpeobject.h" #include "live_effects/effect.h" -- cgit v1.2.3 From 812258dc01faa6b26534a2aa5d7536b4cb892c01 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 12 Sep 2016 12:28:31 +0200 Subject: Fixed out of range pointers Fixed bugs: - https://launchpad.net/bugs/1620253 (bzr r15114) --- src/sp-item.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 0ba74f9fd..e03b715c0 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -317,8 +317,11 @@ void SPItem::lowerOne() { auto next_lower = find_last_if(parent->children.begin(), parent->children.iterator_to(*this), &is_item); if (next_lower != parent->children.iterator_to(*this)) { - next_lower--; - Inkscape::XML::Node *ref = next_lower->getRepr(); + Inkscape::XML::Node *ref = nullptr; + if (next_lower != parent->children.begin()) { + next_lower--; + ref = next_lower->getRepr(); + } getRepr()->parent()->changeOrder(getRepr(), ref); } } @@ -326,8 +329,11 @@ void SPItem::lowerOne() { void SPItem::lowerToBottom() { auto bottom = std::find_if(parent->children.begin(), parent->children.iterator_to(*this), &is_item); if (bottom != parent->children.iterator_to(*this)) { - bottom--; - Inkscape::XML::Node *ref = bottom->getRepr() ; + Inkscape::XML::Node *ref = nullptr; + if (bottom != parent->children.begin()) { + bottom--; + ref = bottom->getRepr(); + } parent->getRepr()->changeOrder(getRepr(), ref); } } -- cgit v1.2.3 From f273f14eb1b54861f1b3a7eb622cb481ee33cec9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 26 Sep 2016 13:26:47 +0200 Subject: Fix undo/redo for mesh gradients. (bzr r15135) --- src/sp-item.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/sp-item.cpp') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index e03b715c0..d161562fd 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -59,6 +59,7 @@ #define noSP_ITEM_DEBUG_IDLE +//#define OBJECT_TRACE static SPItemView* sp_item_view_list_remove(SPItemView *list, SPItemView *view); @@ -691,6 +692,10 @@ void SPItem::update(SPCtx* ctx, guint flags) { void SPItem::modified(unsigned int /*flags*/) { +#ifdef OBJECT_TRACE + objectTrace( "SPItem::modified" ); + objectTrace( "SPItem::modified", false ); +#endif } Inkscape::XML::Node* SPItem::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { -- cgit v1.2.3