From 6641c2e8c586612aad47e1296584ca6447e11b15 Mon Sep 17 00:00:00 2001 From: "Tavmjong Bah, Kamalpreet Grewal" <> Date: Mon, 25 Jul 2016 19:10:59 +0530 Subject: Add robust implementation of _getSelectorVec() (bzr r14949.1.60) --- src/document.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 9f408788b..834d54132 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1053,6 +1053,60 @@ sigc::connection SPDocument::connectIdChanged(gchar const *id, return priv->id_changed_signals[g_quark_from_string(id)].connect(slot); } +void _getObjectsByClassRecursive(Glib::ustring const &klass, SPObject *parent, std::vector &objects) +{ + if (parent) { + Glib::ustring class_attribute; + char const *temp = parent->getAttribute("class"); + if (temp) { + class_attribute = temp; + } + + if (class_attribute.find( klass ) != std::string::npos) { + objects.push_back( parent ); + } + + // Check children + for (SPObject *child = parent->children; child; child = child->next) { + _getObjectsByClassRecursive( klass, child, objects ); + } + } +} + +std::vector SPDocument::getObjectsByClass(Glib::ustring const &klass) const +{ + std::vector objects; + g_return_val_if_fail(!klass.empty(), objects); + + _getObjectsByClassRecursive(klass, root, objects); + return objects; +} + +void _getObjectsByElementRecursive(Glib::ustring const &element, SPObject *parent, + std::vector &objects) +{ + if (parent) { + Glib::ustring prefixed = "svg:" + element; + if (parent->getRepr()->name() == prefixed) { + objects.push_back(parent); + } + + // Check children + for (SPObject *child = parent->children; child; child = child->next) { + _getObjectsByElementRecursive(element, child, objects); + } + } +} + +std::vector SPDocument::getObjectsByElement(Glib::ustring const &element) const +{ + std::vector objects; + g_return_val_if_fail(!element.empty(), objects); + + _getObjectsByElementRecursive(element, root, objects); + return objects; +} + void SPDocument::bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object) { if (object) { -- cgit v1.2.3 From 11e0546b1c039fc84c1a0f86a4681df34642916b Mon Sep 17 00:00:00 2001 From: Tavmjong Bah & Kamalpreet Grewal <> Date: Mon, 15 Aug 2016 10:45:09 +0530 Subject: Add changes for compilation with trunk (bzr r14949.1.65) --- src/document.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 27fbaf8d8..bd59da501 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1060,8 +1060,8 @@ void _getObjectsByClassRecursive(Glib::ustring const &klass, SPObject *parent, s } // Check children - for (SPObject *child = parent->children; child; child = child->next) { - _getObjectsByClassRecursive( klass, child, objects ); + for (auto& child : parent->children) { + _getObjectsByClassRecursive( klass, &child, objects ); } } } @@ -1085,8 +1085,8 @@ void _getObjectsByElementRecursive(Glib::ustring const &element, SPObject *paren } // Check children - for (SPObject *child = parent->children; child; child = child->next) { - _getObjectsByElementRecursive(element, child, objects); + for (auto& child : parent->children) { + _getObjectsByElementRecursive(element, &child, objects); } } } -- cgit v1.2.3