From 3e173aedbe72ba21d33eaec804bf4c9f8e9fa158 Mon Sep 17 00:00:00 2001 From: brock-alexander Date: Tue, 14 Jun 2016 12:26:58 +0200 Subject: Merging lp:~inkscape+alexander/inkscape/comments into lp:inkscape. (bzr r14986) --- src/sp-object.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index db66eb3e6..d1659eedc 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -71,13 +71,17 @@ Inkscape::XML::NodeEventVector object_event_vector = { SPObject::repr_order_changed }; -// A friend class used to set internal members on SPObject so as to not expose settors in SPObject's public API +/** + * A friend class used to set internal members on SPObject so as to not expose settors in SPObject's public API + */ class SPObjectImpl { public: /** * Null's the id member of an SPObject without attempting to free prior contents. + * + * @param[inout] obj Pointer to the object which's id shall be nulled. */ static void setIdNull( SPObject* obj ) { if (obj) { @@ -87,6 +91,9 @@ public: /** * Sets the id member of an object, freeing any prior content. + * + * @param[inout] obj Pointer to the object which's id shall be set. + * @param[in] id New id */ static void setId( SPObject* obj, gchar const* id ) { if (obj && (id != obj->id) ) { @@ -104,6 +111,9 @@ public: static gchar *sp_object_get_unique_id(SPObject *object, gchar const *defid); +/** + * Constructor, sets all attributes to default values. + */ SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), document(NULL), parent(NULL), children(NULL), _last_child(NULL), @@ -126,6 +136,9 @@ SPObject::SPObject() this->context_style = NULL; } +/** + * Destructor, frees the used memory and unreferences a potential successor of the object. + */ SPObject::~SPObject() { g_free(this->_label); g_free(this->_default_label); -- cgit v1.2.3 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-object.cpp | 124 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 55 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..36957ab49 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -7,8 +7,9 @@ * Stephen Silver * Jon A. Cruz * Abhishek Sharma + * Adrian Boguszewski * - * Copyright (C) 1999-2008 authors + * Copyright (C) 1999-2016 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -16,6 +17,7 @@ #include #include +#include #include "helper/sp-marshal.h" #include "xml/node-event-vector.h" @@ -398,13 +400,12 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) } std::vector SPObject::childList(bool add_ref, Action) { - std::vector l; - for ( SPObject *child = firstChild() ; child; child = child->getNext() ) { + std::vector l; + for (auto& child: _children) { if (add_ref) { - sp_object_ref (child); + sp_object_ref(&child); } - - l.push_back(child); + l.push_back(&child); } return l; @@ -467,9 +468,9 @@ void SPObject::requestOrphanCollection() { } void SPObject::_sendDeleteSignalRecursive() { - for (SPObject *child = firstChild(); child; child = child->getNext()) { - child->_delete_signal.emit(child); - child->_sendDeleteSignalRecursive(); + for (auto& child: _children) { + child._delete_signal.emit(&child); + child._sendDeleteSignalRecursive(); } } @@ -497,12 +498,12 @@ void SPObject::deleteObject(bool propagate, bool propagate_descendants) void SPObject::cropToObject(SPObject *except) { std::vector toDelete; - for ( SPObject *child = this->firstChild(); child; child = child->getNext() ) { - if (SP_IS_ITEM(child)) { - if (child->isAncestorOf(except)) { - child->cropToObject(except); - } else if(child != except) { - toDelete.push_back(child); + for (auto& child: _children) { + if (SP_IS_ITEM(&child)) { + if (child.isAncestorOf(except)) { + child.cropToObject(except); + } else if(&child != except) { + toDelete.push_back(&child); } } } @@ -525,6 +526,12 @@ void SPObject::attach(SPObject *object, SPObject *prev) object->parent = this; this->_updateTotalHRefCount(object->_total_hrefcount); + auto it = _children.begin(); + if (prev != nullptr) { + it = ++_children.iterator_to(*prev); + } + _children.insert(it, *object); + SPObject *next; if (prev) { next = prev->next; @@ -541,43 +548,47 @@ void SPObject::attach(SPObject *object, SPObject *prev) object->xml_space.value = this->xml_space.value; } -void SPObject::reorder(SPObject *prev) -{ - //g_return_if_fail(object != NULL); - //g_return_if_fail(SP_IS_OBJECT(object)); - g_return_if_fail(this->parent != NULL); - g_return_if_fail(this != prev); - g_return_if_fail(!prev || SP_IS_OBJECT(prev)); - g_return_if_fail(!prev || prev->parent == this->parent); +void SPObject::reorder(SPObject* obj, SPObject* prev) { + g_return_if_fail(obj != nullptr); + g_return_if_fail(obj->parent); + g_return_if_fail(obj->parent == this); + g_return_if_fail(obj != prev); + g_return_if_fail(!prev || prev->parent == obj->parent); + + auto it = _children.begin(); + if (prev != nullptr) { + it = ++_children.iterator_to(*prev); + } + + _children.splice(it, _children, _children.iterator_to(*obj)); - SPObject *const parent=this->parent; SPObject *old_prev=NULL; - for ( SPObject *child = parent->children ; child && child != this ; + for ( SPObject *child = children ; child && child != obj ; child = child->next ) { old_prev = child; } - SPObject *next=this->next; + SPObject *next=obj->next; if (old_prev) { old_prev->next = next; } else { - parent->children = next; + children = next; } if (!next) { - parent->_last_child = old_prev; + _last_child = old_prev; } if (prev) { next = prev->next; - prev->next = this; + prev->next = obj; } else { - next = parent->children; - parent->children = this; + next = children; + children = obj; } - this->next = next; + obj->next = next; if (!next) { - parent->_last_child = this; + _last_child = obj; } } @@ -589,6 +600,7 @@ void SPObject::detach(SPObject *object) g_return_if_fail(SP_IS_OBJECT(object)); g_return_if_fail(object->parent == this); + _children.erase(_children.iterator_to(*object)); object->releaseReferences(); SPObject *prev=NULL; @@ -618,14 +630,14 @@ void SPObject::detach(SPObject *object) SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr) { g_return_val_if_fail(repr != NULL, NULL); - SPObject *result = 0; + SPObject *result = nullptr; - if ( _last_child && (_last_child->getRepr() == repr) ) { - result = _last_child; // optimization for common scenario + if (_children.size() > 0 && _children.back().getRepr() == repr) { + result = &_children.back(); // optimization for common scenario } else { - for ( SPObject *child = children ; child ; child = child->next ) { - if ( child->getRepr() == repr ) { - result = child; + for (auto& child: _children) { + if (child.getRepr() == repr) { + result = &child; break; } } @@ -656,10 +668,12 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) void SPObject::release() { SPObject* object = this; - debug("id=%p, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); - while (object->children) { - object->detach(object->children); + auto tmp = _children | boost::adaptors::transformed([](SPObject& obj){return &obj;}); + std::vector toRelease(tmp.begin(), tmp.end()); + + for (auto& p: toRelease) { + object->detach(p); } } @@ -680,7 +694,7 @@ void SPObject::order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node * / SPObject *ochild = object->get_child_by_repr(child); g_return_if_fail(ochild != NULL); SPObject *prev = new_ref ? object->get_child_by_repr(new_ref) : NULL; - ochild->reorder(prev); + object->reorder(ochild, prev); ochild->_position_changed_signal.emit(ochild); } @@ -1523,33 +1537,33 @@ bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool return true; } -SPObject * SPObject::findFirstChild(gchar const *tagname) const +SPObject* SPObject::findFirstChild(gchar const *tagname) const { - for (SPObject *child = children; child; child = child->next) + for (auto& child: const_cast(this)->_children) { - if (child->repr->type() == Inkscape::XML::ELEMENT_NODE && - !strcmp(child->repr->name(), tagname)) { - return child; + if (child.repr->type() == Inkscape::XML::ELEMENT_NODE && + !strcmp(child.repr->name(), tagname)) { + return &child; } } - return NULL; + return nullptr; } char* SPObject::textualContent() const { GString* text = g_string_new(""); - for (const SPObject *child = firstChild(); child; child = child->next) + for (auto& child: _children) { - Inkscape::XML::NodeType child_type = child->repr->type(); + Inkscape::XML::NodeType child_type = child.repr->type(); if (child_type == Inkscape::XML::ELEMENT_NODE) { - char* new_string = child->textualContent(); + char* new_string = child.textualContent(); g_string_append(text, new_string); g_free(new_string); } else if (child_type == Inkscape::XML::TEXT_NODE) { - g_string_append(text, child->repr->content()); + g_string_append(text, child.repr->content()); } } return g_string_free(text, FALSE); @@ -1566,8 +1580,8 @@ void SPObject::recursivePrintTree( unsigned level ) std::cout << " "; } std::cout << (getId()?getId():"No object id") << std::endl; - for (SPObject *child = children; child; child = child->next) { - child->recursivePrintTree( level+1 ); + for (auto& child: _children) { + child.recursivePrintTree(level + 1); } } -- cgit v1.2.3 From 798cda4430354143e90fb7ce81c3593a6dc24bc5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah <> Date: Wed, 13 Jul 2016 08:12:57 +0530 Subject: Propagate changes to object tree with changes in style element (bzr r14949.1.46) --- src/sp-object.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..6d36ec833 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1043,7 +1043,9 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML } if (style) { - Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); + // Write if property set by style attribute in this object + Glib::ustring s = + style->write(SP_STYLE_FLAG_IFSET & SP_STYLE_FLAG_IFSRC, SP_STYLE_SRC_STYLE_PROP); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. -- 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-object.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 36957ab49..2babf0441 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -118,7 +118,7 @@ static gchar *sp_object_get_unique_id(SPObject *object, */ SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), - document(NULL), parent(NULL), children(NULL), _last_child(NULL), + document(NULL), parent(NULL), children(NULL), next(NULL), id(NULL), repr(NULL), refCount(1),hrefList(std::list()), _successor(NULL), _collection_policy(SPObject::COLLECT_WITH_PARENT), _label(NULL), _default_label(NULL) @@ -541,9 +541,6 @@ void SPObject::attach(SPObject *object, SPObject *prev) this->children = object; } object->next = next; - if (!next) { - this->_last_child = object; - } if (!object->xml_space.set) object->xml_space.value = this->xml_space.value; } @@ -576,9 +573,6 @@ void SPObject::reorder(SPObject* obj, SPObject* prev) { } else { children = next; } - if (!next) { - _last_child = old_prev; - } if (prev) { next = prev->next; prev->next = obj; @@ -587,9 +581,6 @@ void SPObject::reorder(SPObject* obj, SPObject* prev) { children = obj; } obj->next = next; - if (!next) { - _last_child = obj; - } } void SPObject::detach(SPObject *object) @@ -616,9 +607,6 @@ void SPObject::detach(SPObject *object) } else { this->children = next; } - if (!next) { - this->_last_child = prev; - } object->next = NULL; object->parent = NULL; @@ -856,11 +844,9 @@ void SPObject::releaseReferences() { SPObject *SPObject::getPrev() { - SPObject *prev = 0; - for ( SPObject *obj = parent->firstChild(); obj && !prev; obj = obj->getNext() ) { - if (obj->getNext() == this) { - prev = obj; - } + SPObject *prev = nullptr; + if (parent && !parent->_children.empty() && &parent->_children.front() != this) { + prev = &*(--parent->_children.iterator_to(*this)); } return prev; } -- 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-object.cpp | 66 +++++++++++++------------------------------------------ 1 file changed, 15 insertions(+), 51 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 2babf0441..587efd4f6 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -118,8 +118,7 @@ static gchar *sp_object_get_unique_id(SPObject *object, */ SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), - document(NULL), parent(NULL), children(NULL), - next(NULL), id(NULL), repr(NULL), refCount(1),hrefList(std::list()), + document(NULL), parent(NULL), id(NULL), repr(NULL), refCount(1), hrefList(std::list()), _successor(NULL), _collection_policy(SPObject::COLLECT_WITH_PARENT), _label(NULL), _default_label(NULL) { @@ -532,15 +531,6 @@ void SPObject::attach(SPObject *object, SPObject *prev) } _children.insert(it, *object); - SPObject *next; - if (prev) { - next = prev->next; - prev->next = object; - } else { - next = this->children; - this->children = object; - } - object->next = next; if (!object->xml_space.set) object->xml_space.value = this->xml_space.value; } @@ -558,29 +548,6 @@ void SPObject::reorder(SPObject* obj, SPObject* prev) { } _children.splice(it, _children, _children.iterator_to(*obj)); - - - SPObject *old_prev=NULL; - for ( SPObject *child = children ; child && child != obj ; - child = child->next ) - { - old_prev = child; - } - - SPObject *next=obj->next; - if (old_prev) { - old_prev->next = next; - } else { - children = next; - } - if (prev) { - next = prev->next; - prev->next = obj; - } else { - next = children; - children = obj; - } - obj->next = next; } void SPObject::detach(SPObject *object) @@ -594,21 +561,6 @@ void SPObject::detach(SPObject *object) _children.erase(_children.iterator_to(*object)); object->releaseReferences(); - SPObject *prev=NULL; - for ( SPObject *child = this->children ; child && child != object ; - child = child->next ) - { - prev = child; - } - - SPObject *next=object->next; - if (prev) { - prev->next = next; - } else { - this->children = next; - } - - object->next = NULL; object->parent = NULL; this->_updateTotalHRefCount(-object->_total_hrefcount); @@ -851,6 +803,15 @@ SPObject *SPObject::getPrev() return prev; } +SPObject* SPObject::getNext() +{ + SPObject *next = nullptr; + if (parent && !parent->_children.empty() && &parent->_children.back() != this) { + next = &*(++parent->_children.iterator_to(*this)); + } + return next; +} + void SPObject::repr_child_added(Inkscape::XML::Node * /*repr*/, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data) { SPObject *object = SP_OBJECT(data); @@ -1514,8 +1475,11 @@ bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool } else { // remove the current content of the 'text' or 'desc' element - SPObject *child; - while (NULL != (child = elem->firstChild())) child->deleteObject(); + auto tmp = elem->_children | boost::adaptors::transformed([](SPObject& obj) { return &obj; }); + std::vector vec(tmp.begin(), tmp.end()); + for (auto &child: vec) { + child->deleteObject(); + } } // add the new content -- 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-object.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 587efd4f6..ccd70f4cb 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -400,7 +400,7 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) std::vector SPObject::childList(bool add_ref, Action) { std::vector l; - for (auto& child: _children) { + for (auto& child: children) { if (add_ref) { sp_object_ref(&child); } @@ -467,7 +467,7 @@ void SPObject::requestOrphanCollection() { } void SPObject::_sendDeleteSignalRecursive() { - for (auto& child: _children) { + for (auto& child: children) { child._delete_signal.emit(&child); child._sendDeleteSignalRecursive(); } @@ -497,7 +497,7 @@ void SPObject::deleteObject(bool propagate, bool propagate_descendants) void SPObject::cropToObject(SPObject *except) { std::vector toDelete; - for (auto& child: _children) { + for (auto& child: children) { if (SP_IS_ITEM(&child)) { if (child.isAncestorOf(except)) { child.cropToObject(except); @@ -525,11 +525,11 @@ void SPObject::attach(SPObject *object, SPObject *prev) object->parent = this; this->_updateTotalHRefCount(object->_total_hrefcount); - auto it = _children.begin(); + auto it = children.begin(); if (prev != nullptr) { - it = ++_children.iterator_to(*prev); + it = ++children.iterator_to(*prev); } - _children.insert(it, *object); + children.insert(it, *object); if (!object->xml_space.set) object->xml_space.value = this->xml_space.value; @@ -542,12 +542,12 @@ void SPObject::reorder(SPObject* obj, SPObject* prev) { g_return_if_fail(obj != prev); g_return_if_fail(!prev || prev->parent == obj->parent); - auto it = _children.begin(); + auto it = children.begin(); if (prev != nullptr) { - it = ++_children.iterator_to(*prev); + it = ++children.iterator_to(*prev); } - _children.splice(it, _children, _children.iterator_to(*obj)); + children.splice(it, children, children.iterator_to(*obj)); } void SPObject::detach(SPObject *object) @@ -558,7 +558,7 @@ void SPObject::detach(SPObject *object) g_return_if_fail(SP_IS_OBJECT(object)); g_return_if_fail(object->parent == this); - _children.erase(_children.iterator_to(*object)); + children.erase(children.iterator_to(*object)); object->releaseReferences(); object->parent = NULL; @@ -572,10 +572,10 @@ SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr) g_return_val_if_fail(repr != NULL, NULL); SPObject *result = nullptr; - if (_children.size() > 0 && _children.back().getRepr() == repr) { - result = &_children.back(); // optimization for common scenario + if (children.size() > 0 && children.back().getRepr() == repr) { + result = &children.back(); // optimization for common scenario } else { - for (auto& child: _children) { + for (auto& child: children) { if (child.getRepr() == repr) { result = &child; break; @@ -609,7 +609,7 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) void SPObject::release() { SPObject* object = this; debug("id=%p, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); - auto tmp = _children | boost::adaptors::transformed([](SPObject& obj){return &obj;}); + auto tmp = children | boost::adaptors::transformed([](SPObject& obj){return &obj;}); std::vector toRelease(tmp.begin(), tmp.end()); for (auto& p: toRelease) { @@ -797,8 +797,8 @@ void SPObject::releaseReferences() { SPObject *SPObject::getPrev() { SPObject *prev = nullptr; - if (parent && !parent->_children.empty() && &parent->_children.front() != this) { - prev = &*(--parent->_children.iterator_to(*this)); + if (parent && !parent->children.empty() && &parent->children.front() != this) { + prev = &*(--parent->children.iterator_to(*this)); } return prev; } @@ -806,8 +806,8 @@ SPObject *SPObject::getPrev() SPObject* SPObject::getNext() { SPObject *next = nullptr; - if (parent && !parent->_children.empty() && &parent->_children.back() != this) { - next = &*(++parent->_children.iterator_to(*this)); + if (parent && !parent->children.empty() && &parent->children.back() != this) { + next = &*(++parent->children.iterator_to(*this)); } return next; } @@ -1475,7 +1475,7 @@ bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool } else { // remove the current content of the 'text' or 'desc' element - auto tmp = elem->_children | boost::adaptors::transformed([](SPObject& obj) { return &obj; }); + auto tmp = elem->children | boost::adaptors::transformed([](SPObject& obj) { return &obj; }); std::vector vec(tmp.begin(), tmp.end()); for (auto &child: vec) { child->deleteObject(); @@ -1489,7 +1489,7 @@ bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool SPObject* SPObject::findFirstChild(gchar const *tagname) const { - for (auto& child: const_cast(this)->_children) + for (auto& child: const_cast(this)->children) { if (child.repr->type() == Inkscape::XML::ELEMENT_NODE && !strcmp(child.repr->name(), tagname)) { @@ -1503,7 +1503,7 @@ char* SPObject::textualContent() const { GString* text = g_string_new(""); - for (auto& child: _children) + for (auto& child: children) { Inkscape::XML::NodeType child_type = child.repr->type(); @@ -1530,7 +1530,7 @@ void SPObject::recursivePrintTree( unsigned level ) std::cout << " "; } std::cout << (getId()?getId():"No object id") << std::endl; - for (auto& child: _children) { + for (auto& child: children) { child.recursivePrintTree(level + 1); } } -- cgit v1.2.3 From ff4fbbc93f67afd6cbf851691833a50d6c76b350 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 27 Jul 2016 12:19:03 +0200 Subject: Renamed some functions, fixed tests (bzr r14954.1.28) --- src/sp-object.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index ccd70f4cb..27c788d75 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -151,6 +151,9 @@ SPObject::~SPObject() { sp_object_unref(this->_successor, NULL); this->_successor = NULL; } + if (parent) { + parent->children.erase(parent->children.iterator_to(*this)); + } if( style == NULL ) { // style pointer could be NULL if unreffed too many times. -- cgit v1.2.3 From f35bb1f74a0ffeb5c6477a25e3c4cde87a97bcf1 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 12:06:06 +0200 Subject: Removed unused includes, decrease compilation time (bzr r15025) --- src/sp-object.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..9cb386026 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -32,12 +32,10 @@ #include "sp-script.h" #include "streq.h" #include "strneq.h" -#include "xml/repr.h" #include "xml/node-fns.h" #include "debug/event-tracker.h" #include "debug/simple-event.h" #include "debug/demangle.h" -#include "util/share.h" #include "util/format.h" #include "util/longest-common-suffix.h" -- cgit v1.2.3 From 43b49e325db73cc19b1731db6c69545664ee8fbe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 13:26:17 +0200 Subject: Reverted changes to r15024 after many building problems (bzr r15027) --- src/sp-object.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 9cb386026..d1659eedc 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -32,10 +32,12 @@ #include "sp-script.h" #include "streq.h" #include "strneq.h" +#include "xml/repr.h" #include "xml/node-fns.h" #include "debug/event-tracker.h" #include "debug/simple-event.h" #include "debug/demangle.h" +#include "util/share.h" #include "util/format.h" #include "util/longest-common-suffix.h" -- 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-object.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..9cb386026 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -32,12 +32,10 @@ #include "sp-script.h" #include "streq.h" #include "strneq.h" -#include "xml/repr.h" #include "xml/node-fns.h" #include "debug/event-tracker.h" #include "debug/simple-event.h" #include "debug/demangle.h" -#include "util/share.h" #include "util/format.h" #include "util/longest-common-suffix.h" -- cgit v1.2.3 From 4d7f1b7e727b6896ca880eacc531772d4da28bde Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 26 Sep 2016 13:25:52 +0200 Subject: Add tracing code. (bzr r15134) --- src/sp-object.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 0cd7b371e..da4367d5b 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -61,6 +61,10 @@ using std::strstr; # define debug(f, a...) /* */ #endif +// Define to enable indented tracing of SPObject. +//#define OBJECT_TRACE +unsigned SPObject::indent_level = 0; + guint update_in_progress = 0; // guard against update-during-update Inkscape::XML::NodeEventVector object_event_vector = { @@ -182,6 +186,10 @@ void SPObject::update(SPCtx* /*ctx*/, unsigned int /*flags*/) { } void SPObject::modified(unsigned int /*flags*/) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::modified (default) (empty function)" ); + objectTrace( "SPObject::modified (default)", false ); +#endif //throw; } @@ -640,6 +648,10 @@ void SPObject::order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node * / } void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::build" ); +#endif SPObject* object = this; /* Nothing specific here */ @@ -665,10 +677,17 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { sp_object_unref(child, NULL); child->invoke_build(document, rchild, object->cloned); } + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::build", false ); +#endif } void SPObject::invoke_build(SPDocument *document, Inkscape::XML::Node *repr, unsigned int cloned) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::invoke_build" ); +#endif debug("id=%p, typename=%s", this, g_type_name_from_instance((GTypeInstance*)this)); //g_assert(object != NULL); @@ -728,6 +747,10 @@ void SPObject::invoke_build(SPDocument *document, Inkscape::XML::Node *repr, uns /* Signalling (should be connected AFTER processing derived methods */ sp_repr_add_listener(repr, &object_event_vector, this); + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::invoke_build", false ); +#endif } int SPObject::getIntAttribute(char const *key, int def) @@ -835,6 +858,13 @@ void SPObject::repr_order_changed(Inkscape::XML::Node * /*repr*/, Inkscape::XML: } void SPObject::set(unsigned int key, gchar const* value) { + +#ifdef OBJECT_TRACE + std::stringstream temp; + temp << "SPObject::set: " << key << " " << (value?value:"null"); + objectTrace( temp.str() ); +#endif + g_assert(key != SP_ATTR_INVALID); SPObject* object = this; @@ -918,6 +948,9 @@ void SPObject::set(unsigned int key, gchar const* value) { default: break; } +#ifdef OBJECT_TRACE + objectTrace( "SPObject::set", false ); +#endif } void SPObject::setKeyValue(unsigned int key, gchar const *value) @@ -982,6 +1015,10 @@ static gchar const *sp_xml_get_space_string(unsigned int space) } Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::write" ); +#endif + if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) { repr = this->getRepr()->duplicate(doc); if (!( flags & SP_OBJECT_WRITE_EXT )) { @@ -1050,38 +1087,68 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML sp_style_unset_property_attrs (this); } +#ifdef OBJECT_TRACE + objectTrace( "SPObject::write", false ); +#endif return repr; } Inkscape::XML::Node * SPObject::updateRepr(unsigned int flags) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 1" ); +#endif + if ( !cloned ) { Inkscape::XML::Node *repr = getRepr(); if (repr) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 1", false ); +#endif return updateRepr(repr->document(), repr, flags); } else { g_critical("Attempt to update non-existent repr"); +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 1", false ); +#endif return NULL; } } else { /* cloned objects have no repr */ +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 1", false ); +#endif return NULL; } } Inkscape::XML::Node * SPObject::updateRepr(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) { +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 2" ); +#endif + g_assert(doc != NULL); if (cloned) { /* cloned objects have no repr */ +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateRepr 2", false ); +#endif return NULL; } if (!(flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = getRepr(); } + +#ifdef OBJECT_TRACE + Inkscape::XML::Node *node = write(doc, repr, flags); + objectTrace( "SPObject::updateRepr 2", false ); + return node; +#else return this->write(doc, repr, flags); +#endif } @@ -1101,6 +1168,10 @@ void SPObject::requestDisplayUpdate(unsigned int flags) g_return_if_fail((flags & SP_OBJECT_MODIFIED_FLAG) || (flags & SP_OBJECT_CHILD_MODIFIED_FLAG)); g_return_if_fail(!((flags & SP_OBJECT_MODIFIED_FLAG) && (flags & SP_OBJECT_CHILD_MODIFIED_FLAG))); +#ifdef OBJECT_TRACE + objectTrace( "SPObject::requestDisplayUpdate" ); +#endif + bool already_propagated = (!(this->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))); this->uflags |= flags; @@ -1115,12 +1186,21 @@ void SPObject::requestDisplayUpdate(unsigned int flags) document->requestModified(); } } + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::requestDisplayUpdate", false ); +#endif + } void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags) { g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE)); +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateDisplay" ); +#endif + update_in_progress ++; #ifdef SP_OBJECT_DEBUG_CASCADE @@ -1161,6 +1241,10 @@ void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags) } update_in_progress --; + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::updateDisplay", false ); +#endif } void SPObject::requestModified(unsigned int flags) @@ -1173,6 +1257,10 @@ void SPObject::requestModified(unsigned int flags) g_return_if_fail((flags & SP_OBJECT_MODIFIED_FLAG) || (flags & SP_OBJECT_CHILD_MODIFIED_FLAG)); g_return_if_fail(!((flags & SP_OBJECT_MODIFIED_FLAG) && (flags & SP_OBJECT_CHILD_MODIFIED_FLAG))); +#ifdef OBJECT_TRACE + objectTrace( "SPObject::requestModified" ); +#endif + bool already_propagated = (!(this->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))); this->mflags |= flags; @@ -1187,6 +1275,9 @@ void SPObject::requestModified(unsigned int flags) document->requestModified(); } } +#ifdef OBJECT_TRACE + objectTrace( "SPObject::requestModified", false ); +#endif } void SPObject::emitModified(unsigned int flags) @@ -1194,6 +1285,10 @@ void SPObject::emitModified(unsigned int flags) /* only the MODIFIED_CASCADE flag is legal here */ g_return_if_fail(!(flags & ~SP_OBJECT_MODIFIED_CASCADE)); +#ifdef OBJECT_TRACE + objectTrace( "SPObject::emitModified", true, flags ); +#endif + #ifdef SP_OBJECT_DEBUG_CASCADE g_print("Modified %s:%s %x %x %x\n", g_type_name_from_instance((GTypeInstance *) this), getId(), flags, this->uflags, this->mflags); #endif @@ -1210,6 +1305,10 @@ void SPObject::emitModified(unsigned int flags) _modified_signal.emit(this, flags); sp_object_unref(this); + +#ifdef OBJECT_TRACE + objectTrace( "SPObject::emitModified", false ); +#endif } gchar const *SPObject::getTagName(SPException *ex) const @@ -1248,10 +1347,12 @@ void SPObject::setAttribute(gchar const *key, gchar const *value, SPException *e //XML Tree being used here. getRepr()->setAttribute(key, value, false); } + void SPObject::setAttribute(char const *key, Glib::ustring const &value, SPException *ex) { setAttribute(key, value.empty() ? NULL : value.c_str(), ex); } + void SPObject::setAttribute(Glib::ustring const &key, Glib::ustring const &value, SPException *ex) { setAttribute( key.empty() ? NULL : key.c_str(), @@ -1536,6 +1637,34 @@ void SPObject::recursivePrintTree( unsigned level ) } } +// Function to allow tracing of program flow through SPObject and derived classes. +// To trace function, add at entrance ('in' = true) and exit of function ('in' = false). +void SPObject::objectTrace( std::string text, bool in, unsigned flags ) { + if( in ) { + for (unsigned i = 0; i < indent_level; ++i) { + std::cout << " "; + } + std::cout << text << ":" + << " entrance: " + << (id?id:"null") + << " uflags: " << uflags + << " mflags: " << mflags + << " flags: " << flags << std::endl; + ++indent_level; + } else { + --indent_level; + for (unsigned i = 0; i < indent_level; ++i) { + std::cout << " "; + } + std::cout << text << ":" + << " exit: " + << (id?id:"null") + << " uflags: " << uflags + << " mflags: " << mflags + << " flags: " << flags << std::endl; + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From b1d8ece63b0bdfcc2595a97af9e69147c2d37a37 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 6 Oct 2016 19:50:17 +0200 Subject: Fix on delete line (bzr r15017.1.41) --- src/sp-object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index da4367d5b..cbd7aa969 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -485,13 +485,16 @@ void SPObject::_sendDeleteSignalRecursive() { void SPObject::deleteObject(bool propagate, bool propagate_descendants) { sp_object_ref(this, NULL); + if ( SP_IS_LPE_ITEM(this) ) { + SP_LPE_ITEM(this)->removeAllPathEffects(false); + } if (propagate) { _delete_signal.emit(this); } if (propagate_descendants) { this->_sendDeleteSignalRecursive(); } - + Inkscape::XML::Node *repr = getRepr(); if (repr && repr->parent()) { sp_repr_unparent(repr); -- cgit v1.2.3 From 602f9c6600ebd89491dbe5541445ba3545cbb940 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 19 Oct 2016 16:40:29 +0200 Subject: Fix bug:1634641 crash on delete Fixed bugs: - https://launchpad.net/bugs/1634645 (bzr r15179) --- src/sp-object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index cbd7aa969..21d8bcd93 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -485,7 +485,7 @@ void SPObject::_sendDeleteSignalRecursive() { void SPObject::deleteObject(bool propagate, bool propagate_descendants) { sp_object_ref(this, NULL); - if ( SP_IS_LPE_ITEM(this) ) { + if ( SP_IS_LPE_ITEM(this) && SP_LPE_ITEM(this)->hasPathEffect()) { SP_LPE_ITEM(this)->removeAllPathEffects(false); } if (propagate) { -- cgit v1.2.3 From 71f7e3e517b5d7f87d30a27b683c57df05ab5368 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 27 Oct 2016 02:01:14 +0200 Subject: Fix regression in loop prevention Fixed bugs: - https://launchpad.net/bugs/1636533 (bzr r15193) --- src/sp-object.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 21d8bcd93..8d4c4f0d1 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -119,7 +119,7 @@ static gchar *sp_object_get_unique_id(SPObject *object, * Constructor, sets all attributes to default values. */ SPObject::SPObject() - : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), + : cloned(0), clone_original(NULL), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), document(NULL), parent(NULL), id(NULL), repr(NULL), refCount(1), hrefList(std::list()), _successor(NULL), _collection_policy(SPObject::COLLECT_WITH_PARENT), _label(NULL), _default_label(NULL) @@ -663,6 +663,8 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { object->readAttr("xml:space"); object->readAttr("inkscape:label"); object->readAttr("inkscape:collect"); + if(object->cloned) + object->clone_original = document->getObjectById(repr->attribute("id")); for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) { const std::string typeString = NodeTraits::get_type_string(*rchild); -- cgit v1.2.3 From 046b9d9b4d20894231127a6d00d327302ffd0474 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 5 Nov 2016 17:45:28 +0100 Subject: Fix last commit not working, LPE are cloned on copies (bzr r15214) --- src/sp-object.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 8d4c4f0d1..e9c60fc7d 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -112,9 +112,6 @@ public: } }; -static gchar *sp_object_get_unique_id(SPObject *object, - gchar const *defid); - /** * Constructor, sets all attributes to default values. */ @@ -1382,7 +1379,7 @@ bool SPObject::storeAsDouble( gchar const *key, double *val ) const } /** Helper */ -static gchar* +gchar * sp_object_get_unique_id(SPObject *object, gchar const *id) { -- cgit v1.2.3 From 7bedd224ace433cf4c1a829ba38f6a3c388227e6 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 5 Jan 2017 20:03:50 +0100 Subject: Adding base (bzr r15392.1.1) --- src/sp-object.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index e9c60fc7d..222626162 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -773,6 +773,21 @@ void SPObject::appendChild(Inkscape::XML::Node *child) { repr->appendChild(child); } +SPObject* SPObject::nthChild(unsigned index) { + g_assert(this->repr); + if (hasChildren()) { + std::vector l; + unsigned counter = 0; + for (auto& child: children) { + if (counter == index) { + return &child; + } + counter++; + } + } + return NULL; +} + void SPObject::addChild(Inkscape::XML::Node *child, Inkscape::XML::Node * prev) { g_assert(this->repr); -- cgit v1.2.3 From 0baa29a9f73547319d667d898c961a9fdb436c9e Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 7 Jan 2017 16:32:48 +0100 Subject: suppress warnings on symbols dialog (bzr r15398) --- src/sp-object.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index e9c60fc7d..75f4657ef 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -660,7 +660,9 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { object->readAttr("xml:space"); object->readAttr("inkscape:label"); object->readAttr("inkscape:collect"); - if(object->cloned) + if(object->cloned && (repr->attribute("id")) ) // The cases where this happens are when the "original" has no id. This happens + // if it is a SPString (a TextNode, e.g. in a ), or when importing + // stuff externally modified to have no id. object->clone_original = document->getObjectById(repr->attribute("id")); for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) { -- cgit v1.2.3 From 2fe2bf0ac3026964cbf3c76c357a37f2ab4341ef Mon Sep 17 00:00:00 2001 From: Tavmjong Bah <tavmjong@free.fr> Date: Sun, 5 Feb 2017 17:57:48 +0100 Subject: Fix styling breakage from r15471. (bzr r15478) --- src/sp-object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index cc862417d..7807703f6 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1063,7 +1063,7 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML if (style) { // Write if property set by style attribute in this object Glib::ustring s = - style->write(SP_STYLE_FLAG_IFSET & SP_STYLE_FLAG_IFSRC, SP_STYLE_SRC_STYLE_PROP); + style->write(SP_STYLE_FLAG_IFSET | SP_STYLE_FLAG_IFSRC, SP_STYLE_SRC_STYLE_PROP); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. -- cgit v1.2.3 From 52059c7c7f059a0928efd48d0ef545dabc30a3a7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah <tavmjong@free.fr> Date: Fri, 10 Feb 2017 11:06:54 +0100 Subject: Do not delete presentation attributes. Styling source is now tracked and not automatically converted to properties in a style attribute. Fixed bugs: - https://launchpad.net/bugs/1663511 (bzr r15500) --- src/sp-object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 7807703f6..9f15935ac 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1105,7 +1105,10 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML * possibly we should write property attributes instead of a style * attribute. */ - sp_style_unset_property_attrs (this); + // With the changes to preserves style source this is no longer needed + // and the above comment no longer applies. I leave it here until these + // change are well tested. + // sp_style_unset_property_attrs (this); } #ifdef OBJECT_TRACE -- cgit v1.2.3