summaryrefslogtreecommitdiffstats
path: root/src/document.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/document.cpp')
-rw-r--r--src/document.cpp105
1 files changed, 50 insertions, 55 deletions
diff --git a/src/document.cpp b/src/document.cpp
index 9f408788b..920e47cb8 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -37,7 +37,7 @@
#define noSP_DOCUMENT_DEBUG_UNDO
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <string>
#include <cstring>
@@ -47,7 +47,6 @@
#include "desktop.h"
#include "dir-util.h"
#include "display/drawing.h"
-#include "display/drawing-item.h"
#include "document-private.h"
#include "document-undo.h"
#include "id-clash.h"
@@ -55,18 +54,12 @@
#include "inkscape-version.h"
#include "libavoid/router.h"
#include "persp3d.h"
-#include "preferences.h"
#include "profile-manager.h"
#include "rdf.h"
#include "sp-factory.h"
-#include "sp-item-group.h"
#include "sp-namedview.h"
#include "sp-symbol.h"
-#include "transf_mat_3x4.h"
-#include "util/units.h"
-#include "xml/repr.h"
#include "xml/rebase-hrefs.h"
-#include "libcroco/cr-cascade.h"
using Inkscape::DocumentUndo;
using Inkscape::Util::unit_table;
@@ -257,9 +250,9 @@ void SPDocument::setCurrentPersp3D(Persp3D * const persp) {
void SPDocument::getPerspectivesInDefs(std::vector<Persp3D*> &list) const
{
- for (SPObject *i = root->defs->firstChild(); i; i = i->getNext() ) {
- if (SP_IS_PERSP3D(i)) {
- list.push_back(SP_PERSP3D(i));
+ for (auto& i: root->defs->children) {
+ if (SP_IS_PERSP3D(&i)) {
+ list.push_back(SP_PERSP3D(&i));
}
}
}
@@ -1259,12 +1252,12 @@ static std::vector<SPItem*> &find_items_in_area(std::vector<SPItem*> &s, SPGroup
{
g_return_val_if_fail(SP_IS_GROUP(group), s);
- for ( SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
- if ( SP_IS_ITEM(o) ) {
- if (SP_IS_GROUP(o) && (SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER || into_groups)) {
- s = find_items_in_area(s, SP_GROUP(o), dkey, area, test, take_insensitive, into_groups);
+ for (auto& o: group->children) {
+ if ( SP_IS_ITEM(&o) ) {
+ if (SP_IS_GROUP(&o) && (SP_GROUP(&o)->effectiveLayerMode(dkey) == SPGroup::LAYER || into_groups)) {
+ s = find_items_in_area(s, SP_GROUP(&o), dkey, area, test, take_insensitive, into_groups);
} else {
- SPItem *child = SP_ITEM(o);
+ SPItem *child = SP_ITEM(&o);
Geom::OptRect box = child->desktopVisualBounds();
if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
s.push_back(child);
@@ -1281,17 +1274,16 @@ Returns true if an item is among the descendants of group (recursively).
*/
static bool item_is_in_group(SPItem *item, SPGroup *group)
{
- bool inGroup = false;
- for ( SPObject *o = group->firstChild() ; o && !inGroup; o = o->getNext() ) {
- if ( SP_IS_ITEM(o) ) {
- if (SP_ITEM(o) == item) {
- inGroup = true;
- } else if ( SP_IS_GROUP(o) ) {
- inGroup = item_is_in_group(item, SP_GROUP(o));
+ for (auto& o: group->children) {
+ if ( SP_IS_ITEM(&o) ) {
+ if (SP_ITEM(&o) == item) {
+ return true;
+ } else if (SP_IS_GROUP(&o) && item_is_in_group(item, SP_GROUP(&o))) {
+ return true;
}
}
}
- return inGroup;
+ return false;
}
SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, std::vector<SPItem*> const &list,Geom::Point const &p, bool take_insensitive)
@@ -1302,21 +1294,24 @@ SPItem *SPDocument::getItemFromListAtPointBottom(unsigned int dkey, SPGroup *gro
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
- for ( SPObject *o = group->firstChild() ; o && !bottomMost; o = o->getNext() ) {
- if ( SP_IS_ITEM(o) ) {
- SPItem *item = SP_ITEM(o);
+ for (auto& o: group->children) {
+ if (bottomMost) {
+ break;
+ }
+ if (SP_IS_ITEM(&o)) {
+ SPItem *item = SP_ITEM(&o);
Inkscape::DrawingItem *arenaitem = item->get_arenaitem(dkey);
arenaitem->drawing().update();
if (arenaitem && arenaitem->pick(p, delta, 1) != NULL
&& (take_insensitive || item->isVisibleAndUnlocked(dkey))) {
- if (find(list.begin(),list.end(),item)!=list.end() ) {
+ if (find(list.begin(), list.end(), item) != list.end()) {
bottomMost = item;
}
}
- if ( !bottomMost && SP_IS_GROUP(o) ) {
+ if (!bottomMost && SP_IS_GROUP(&o)) {
// return null if not found:
- bottomMost = getItemFromListAtPointBottom(dkey, SP_GROUP(o), list, p, take_insensitive);
+ bottomMost = getItemFromListAtPointBottom(dkey, SP_GROUP(&o), list, p, take_insensitive);
}
}
}
@@ -1329,15 +1324,15 @@ The list can be persisted, which improves "find at multiple points" speed.
*/
void SPDocument::build_flat_item_list(unsigned int dkey, SPGroup *group, gboolean into_groups) const
{
- for ( SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
- if (!SP_IS_ITEM(o)) {
+ for (auto& o: group->children) {
+ if (!SP_IS_ITEM(&o)) {
continue;
}
- if (SP_IS_GROUP(o) && (SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER || into_groups)) {
- build_flat_item_list(dkey, SP_GROUP(o), into_groups);
+ if (SP_IS_GROUP(&o) && (SP_GROUP(&o)->effectiveLayerMode(dkey) == SPGroup::LAYER || into_groups)) {
+ build_flat_item_list(dkey, SP_GROUP(&o), into_groups);
} else {
- SPItem *child = SP_ITEM(o);
+ SPItem *child = SP_ITEM(&o);
if (child->isVisibleAndUnlocked(dkey)) {
_node_cache.push_front(child);
@@ -1393,18 +1388,18 @@ static SPItem *find_group_at_point(unsigned int dkey, SPGroup *group, Geom::Poin
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gdouble delta = prefs->getDouble("/options/cursortolerance/value", 1.0);
- for ( SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
- if (!SP_IS_ITEM(o)) {
+ for (auto& o: group->children) {
+ if (!SP_IS_ITEM(&o)) {
continue;
}
- if (SP_IS_GROUP(o) && SP_GROUP(o)->effectiveLayerMode(dkey) == SPGroup::LAYER) {
- SPItem *newseen = find_group_at_point(dkey, SP_GROUP(o), p);
+ if (SP_IS_GROUP(&o) && SP_GROUP(&o)->effectiveLayerMode(dkey) == SPGroup::LAYER) {
+ SPItem *newseen = find_group_at_point(dkey, SP_GROUP(&o), p);
if (newseen) {
seen = newseen;
}
}
- if (SP_IS_GROUP(o) && SP_GROUP(o)->effectiveLayerMode(dkey) != SPGroup::LAYER ) {
- SPItem *child = SP_ITEM(o);
+ if (SP_IS_GROUP(&o) && SP_GROUP(&o)->effectiveLayerMode(dkey) != SPGroup::LAYER ) {
+ SPItem *child = SP_ITEM(&o);
Inkscape::DrawingItem *arenaitem = child->get_arenaitem(dkey);
arenaitem->drawing().update();
@@ -1598,8 +1593,8 @@ static unsigned int count_objects_recursive(SPObject *obj, unsigned int count)
{
count++; // obj itself
- for ( SPObject *i = obj->firstChild(); i; i = i->getNext() ) {
- count = count_objects_recursive(i, count);
+ for (auto& i: obj->children) {
+ count = count_objects_recursive(&i, count);
}
return count;
@@ -1624,13 +1619,13 @@ static unsigned int objects_in_document(SPDocument *document)
static void vacuum_document_recursive(SPObject *obj)
{
if (SP_IS_DEFS(obj)) {
- for ( SPObject *def = obj->firstChild(); def; def = def->getNext()) {
+ for (auto& def: obj->children) {
// fixme: some inkscape-internal nodes in the future might not be collectable
- def->requestOrphanCollection();
+ def.requestOrphanCollection();
}
} else {
- for ( SPObject *i = obj->firstChild(); i; i = i->getNext() ) {
- vacuum_document_recursive(i);
+ for (auto& i: obj->children) {
+ vacuum_document_recursive(&i);
}
}
}
@@ -1758,14 +1753,14 @@ void SPDocument::importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, I
// Prevent duplicates of solid swatches by checking if equivalent swatch already exists
if (src && SP_IS_GRADIENT(src)) {
SPGradient *s_gr = SP_GRADIENT(src);
- for (SPObject *trg = this->getDefs()->firstChild() ; trg ; trg = trg->getNext()) {
- if (trg && (src != trg) && SP_IS_GRADIENT(trg)) {
- SPGradient *t_gr = SP_GRADIENT(trg);
+ for (auto& trg: getDefs()->children) {
+ if (&trg && (src != &trg) && SP_IS_GRADIENT(&trg)) {
+ SPGradient *t_gr = SP_GRADIENT(&trg);
if (t_gr && s_gr->isEquivalent(t_gr)) {
// Change object references to the existing equivalent gradient
- Glib::ustring newid = trg->getId();
+ Glib::ustring newid = trg.getId();
if(newid != defid){ // id could be the same if it is a second paste into the same document
- change_def_references(src, trg);
+ change_def_references(src, &trg);
}
gchar *longid = g_strdup_printf("%s_%9.9d", DuplicateDefString.c_str(), stagger++);
def->setAttribute("id", longid );
@@ -1829,9 +1824,9 @@ void SPDocument::importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, I
id.erase( pos );
// Check that it really is a duplicate
- for (SPObject *trg = this->getDefs()->firstChild() ; trg ; trg = trg->getNext()) {
- if( trg && SP_IS_SYMBOL(trg) && src != trg ) {
- std::string id2 = trg->getRepr()->attribute("id");
+ for (auto& trg: getDefs()->children) {
+ if(&trg && SP_IS_SYMBOL(&trg) && src != &trg ) {
+ std::string id2 = trg.getRepr()->attribute("id");
if( !id.compare( id2 ) ) {
duplicate = true;