diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2015-12-05 11:33:26 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2015-12-05 11:33:26 +0000 |
| commit | 151733327589217e84c5ac7006b9076f428c53a0 (patch) | |
| tree | 795008ca0e01c65760a1dea3258c5d0ae89522ed /src | |
| parent | added comment + simpler rounding (diff) | |
| download | inkscape-151733327589217e84c5ac7006b9076f428c53a0.tar.gz inkscape-151733327589217e84c5ac7006b9076f428c53a0.zip | |
cppification: GSList replaced by vectors (mostly related to guides and grids)
(bzr r14504.1.1)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.cpp | 2 | ||||
| -rw-r--r-- | src/guide-snapper.cpp | 9 | ||||
| -rw-r--r-- | src/satisfied-guide-cns.cpp | 4 | ||||
| -rw-r--r-- | src/snap.cpp | 9 | ||||
| -rw-r--r-- | src/sp-guide.cpp | 56 | ||||
| -rw-r--r-- | src/sp-guide.h | 4 | ||||
| -rw-r--r-- | src/sp-mask.cpp | 39 | ||||
| -rw-r--r-- | src/sp-namedview.cpp | 155 | ||||
| -rw-r--r-- | src/sp-namedview.h | 9 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.cpp | 22 |
10 files changed, 130 insertions, 179 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index 7b20bcb9f..5e9401ee0 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1474,7 +1474,7 @@ bool SPDesktop::colorProfAdjustEnabled() void SPDesktop::toggleGrids() { - if (namedview->grids) { + if (! namedview->grids.empty()) { if(gridgroup) { showGrids(!grids_visible); } diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 960caed67..17f2d9583 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -44,11 +44,10 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Poi } SPGuide const *guide_to_ignore = _snapmanager->getGuideToIgnore(); - - for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) { - SPGuide const *g = SP_GUIDE(l->data); - if (g != guide_to_ignore) { - s.push_back(std::pair<Geom::Point, Geom::Point>(g->getNormal(), g->getPoint())); + std::vector<SPGuide *> guides = _snapmanager->getNamedView()->guides; + for(std::vector<SPGuide *>::const_iterator it = guides.begin() ; it != guides.end(); ++it) { + if ((*it) != guide_to_ignore) { + s.push_back(std::pair<Geom::Point, Geom::Point>((*it)->getNormal(), (*it)->getPoint())); } } diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp index 028a22405..a83417865 100644 --- a/src/satisfied-guide-cns.cpp +++ b/src/satisfied-guide-cns.cpp @@ -10,8 +10,8 @@ void satisfied_guide_cns(SPDesktop const &desktop, std::vector<SPGuideConstraint> &cns) { SPNamedView const &nv = *desktop.getNamedView(); - for (GSList const *l = nv.guides; l != NULL; l = l->next) { - SPGuide &g = *SP_GUIDE(l->data); + for(std::vector<SPGuide *>::const_iterator it = nv.guides.begin(); it != nv.guides.end(); ++it) { + SPGuide &g = *(*it); for (unsigned int i = 0; i < snappoints.size(); ++i) { if (Geom::are_near(g.getDistanceFrom(snappoints[i].getPoint()), 0, 1e-2)) { cns.push_back(SPGuideConstraint(&g, i)); diff --git a/src/snap.cpp b/src/snap.cpp index 4721283c3..7f0e8d9dc 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -69,9 +69,8 @@ SnapManager::SnapperList SnapManager::getGridSnappers() const SnapperList s; if (_desktop && _desktop->gridsEnabled() && snapprefs.isTargetSnappable(Inkscape::SNAPTARGET_GRID)) { - for ( GSList const *l = _named_view->grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; - s.push_back(grid->snapper); + for(std::vector<Inkscape::CanvasGrid *>::const_iterator it = _named_view->grids.begin(); it != _named_view->grids.end(); ++it) { + s.push_back((*it)->snapper); } } @@ -173,8 +172,8 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t, Geom::Point c // Cannot use getGridSnappers() because we need both the grids AND their snappers // Therefore we iterate through all grids manually - for (GSList const *l = _named_view->grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; + for (std::vector<Inkscape::CanvasGrid *>::const_iterator it = _named_view->grids.begin(); it != _named_view->grids.end(); ++it) { + Inkscape::CanvasGrid *grid = (*it); const Inkscape::Snapper* snapper = grid->snapper; if (snapper && snapper->ThisSnapperMightSnap()) { // To find the nearest multiple of the grid pitch for a given translation t, we diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index bbdf5f260..06eaee001 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -51,7 +51,6 @@ using std::vector; SPGuide::SPGuide() : SPObject() , label(NULL) - , views(NULL) , normal_to_line(Geom::Point(0.,1.)) , point_on_line(Geom::Point(0.,0.)) , color(0x0000ff7f) @@ -62,8 +61,8 @@ void SPGuide::setColor(guint32 c) { color = c; - for (GSList *l = this->views; l != NULL; l = l->next) { - sp_guideline_set_color(SP_GUIDELINE(l->data), this->color); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_guideline_set_color(*it, this->color); } } @@ -82,10 +81,10 @@ void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr) void SPGuide::release() { - while (this->views) { - sp_guideline_delete(SP_GUIDELINE(this->views->data)); - this->views = g_slist_remove(this->views, this->views->data); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_guideline_delete(*it); } + this->views.clear(); if (this->document) { // Unregister ourselves @@ -272,14 +271,14 @@ void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this); - views = g_slist_prepend(views, item); + views.push_back(SP_GUIDELINE(item)); } void SPGuide::showSPGuide() { - for (GSList *v = views; v != NULL; v = v->next) { - sp_canvas_item_show(SP_CANVAS_ITEM(v->data)); - sp_canvas_item_show(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_canvas_item_show(SP_CANVAS_ITEM(*it)); + sp_canvas_item_show(SP_CANVAS_ITEM((*it)->origin)); } } @@ -287,11 +286,10 @@ void SPGuide::hideSPGuide(SPCanvas *canvas) { g_assert(canvas != NULL); g_assert(SP_IS_CANVAS(canvas)); - - for (GSList *l = views; l != NULL; l = l->next) { - if (canvas == SP_CANVAS_ITEM(l->data)->canvas) { - sp_guideline_delete(SP_GUIDELINE(l->data)); - views = g_slist_remove(views, l->data); + for(std::vector<SPGuideLine *>::iterator it = this->views.begin(); it != this->views.end(); ++it) { + if (canvas == SP_CANVAS_ITEM(*it)->canvas) { + sp_guideline_delete(*it); + views.erase(it); return; } } @@ -301,9 +299,9 @@ void SPGuide::hideSPGuide(SPCanvas *canvas) void SPGuide::hideSPGuide() { - for (GSList *v = views; v != NULL; v = v->next) { - sp_canvas_item_hide(SP_CANVAS_ITEM(v->data)); - sp_canvas_item_hide(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_canvas_item_hide(SP_CANVAS_ITEM(*it)); + sp_canvas_item_hide(SP_CANVAS_ITEM((*it)->origin)); } } @@ -312,9 +310,9 @@ void SPGuide::sensitize(SPCanvas *canvas, bool sensitive) g_assert(canvas != NULL); g_assert(SP_IS_CANVAS(canvas)); - for (GSList *l = views; l != NULL; l = l->next) { - if (canvas == SP_CANVAS_ITEM(l->data)->canvas) { - sp_guideline_set_sensitive(SP_GUIDELINE(l->data), sensitive); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + if (canvas == SP_CANVAS_ITEM(*it)->canvas) { + sp_guideline_set_sensitive(*it, sensitive); return; } } @@ -339,8 +337,8 @@ double SPGuide::getDistanceFrom(Geom::Point const &pt) const */ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) { - for (GSList *l = views; l != NULL; l = l->next) { - sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_guideline_set_position(*it, point_on_line); } /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit @@ -385,8 +383,8 @@ void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) */ void SPGuide::set_normal(Geom::Point const normal_to_line, bool const commit) { - for (GSList *l = this->views; l != NULL; l = l->next) { - sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line); + for(std::vector<SPGuideLine *>::const_iterator it = this->views.begin(); it != this->views.end(); ++it) { + sp_guideline_set_normal(*it, normal_to_line); } /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit @@ -411,8 +409,8 @@ void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bo { this->color = (r << 24) | (g << 16) | (b << 8) | 0x7f; - if (views) { - sp_guideline_set_color(SP_GUIDELINE(views->data), this->color); + if (! views.empty()) { + sp_guideline_set_color(views[0], this->color); } if (commit) { @@ -425,8 +423,8 @@ void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bo void SPGuide::set_label(const char* label, bool const commit) { - if (views) { - sp_guideline_set_label(SP_GUIDELINE(views->data), label); + if (!views.empty()) { + sp_guideline_set_label(views[0], label); } if (commit) { diff --git a/src/sp-guide.h b/src/sp-guide.h index 382ea56f0..bcd1e57b6 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -28,7 +28,7 @@ extern "C" { class SPDesktop; struct SPCanvas; struct SPCanvasGroup; - +struct SPGuideLine; #define SP_GUIDE(obj) (dynamic_cast<SPGuide*>((SPObject*)obj)) #define SP_IS_GUIDE(obj) (dynamic_cast<const SPGuide*>((SPObject*)obj) != NULL) @@ -77,7 +77,7 @@ protected: virtual void set(unsigned int key, const char* value); char* label; - GSList *views; // contains an object of type SPGuideline (see display/guideline.cpp for definition) + std::vector<SPGuideLine *> views; // contains an object of type SPGuideline (see display/guideline.cpp for definition) Geom::Point normal_to_line; Geom::Point point_on_line; diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index 5f7a2ec26..7b9ab11c3 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -138,23 +138,18 @@ void SPMask::update(SPCtx* ctx, unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = NULL; - for (SPObject *child = this->firstChild(); child; child = child->getNext()) { - sp_object_ref(child); - l = g_slist_prepend (l, child); + std::vector<SPObject *> children = this->childList(false); + for (std::vector<SPObject *>::const_iterator child = children.begin();child != children.end();child++) { + sp_object_ref(*child); } - l = g_slist_reverse (l); - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - - if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - child->updateDisplay(ctx, flags); + for (std::vector<SPObject *>::const_iterator child = children.begin();child != children.end();child++) { + if (flags || ((*child)->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + (*child)->updateDisplay(ctx, flags); } - sp_object_unref(child); + sp_object_unref(*child); } for (SPMaskView *v = this->display; v != NULL; v = v->next) { @@ -177,23 +172,17 @@ void SPMask::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = NULL; - for (SPObject *child = this->firstChild(); child; child = child->getNext()) { - sp_object_ref(child); - l = g_slist_prepend(l, child); + std::vector<SPObject *> children = this->childList(false); + for (std::vector<SPObject *>::const_iterator child = children.begin();child != children.end();child++) { + sp_object_ref(*child); } - l = g_slist_reverse(l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - child->emitModified(flags); + for (std::vector<SPObject *>::const_iterator child = children.begin();child != children.end();child++) { + if (flags || ((*child)->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + (*child)->emitModified(flags); } - sp_object_unref(child); + sp_object_unref(*child); } } diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index b8554f352..fa62cf169 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -60,7 +60,7 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) { this->zoom = 0; this->guidecolor = 0; this->guidehicolor = 0; - this->views = NULL; + this->views.clear(); this->borderlayer = 0; this->page_size_units = NULL; this->window_x = 0; @@ -83,9 +83,9 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) { this->showborder = TRUE; this->showpageshadow = TRUE; - this->guides = NULL; + this->guides.clear(); this->viewcount = 0; - this->grids = NULL; + this->grids.clear(); this->default_layer_id = 0; @@ -245,7 +245,7 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) { for (SPObject *o = this->firstChild() ; o; o = o->getNext() ) { if (SP_IS_GUIDE(o)) { SPGuide * g = SP_GUIDE(o); - this->guides = g_slist_prepend(this->guides, g); + this->guides.push_back(g); //g_object_set(G_OBJECT(g), "color", nv->guidecolor, "hicolor", nv->guidehicolor, NULL); g->setColor(this->guidecolor); g->setHiColor(this->guidehicolor); @@ -268,18 +268,12 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) { } void SPNamedView::release() { - if (this->guides) { - g_slist_free(this->guides); - this->guides = NULL; - } + this->guides.clear(); // delete grids: - while ( this->grids ) { - Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)this->grids->data; // get first entry - delete gr; - this->grids = g_slist_remove_link(this->grids, this->grids); // deletes first entry - } - + for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=this->grids.begin();it!=this->grids.end();++it ) + delete *it; + this->grids.clear(); SPObjectGroup::release(); } @@ -325,10 +319,9 @@ void SPNamedView::set(unsigned int key, const gchar* value) { this->guidecolor = (this->guidecolor & 0xff) | sp_svg_read_color(value, this->guidecolor); } - for (GSList *l = this->guides; l != NULL; l = l->next) { - SPGuide * g = SP_GUIDE(l->data); - g->setColor(this->guidecolor); - g->readAttr("inkscape:color"); + for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->setColor(this->guidecolor); + (*it)->readAttr("inkscape:color"); } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -337,10 +330,9 @@ void SPNamedView::set(unsigned int key, const gchar* value) { this->guidecolor = (this->guidecolor & 0xffffff00) | (DEFAULTGUIDECOLOR & 0xff); sp_nv_read_opacity(value, &this->guidecolor); - for (GSList *l = this->guides; l != NULL; l = l->next) { - SPGuide * g = SP_GUIDE(l->data); - g->setColor(this->guidecolor); - g->readAttr("inkscape:color"); + for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->setColor(this->guidecolor); + (*it)->readAttr("inkscape:color"); } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -351,10 +343,8 @@ void SPNamedView::set(unsigned int key, const gchar* value) { if (value) { this->guidehicolor = (this->guidehicolor & 0xff) | sp_svg_read_color(value, this->guidehicolor); } - - for (GSList *l = this->guides; l != NULL; l = l->next) { - //g_object_set(G_OBJECT(l->data), "hicolor", nv->guidehicolor, NULL); - SP_GUIDE(l->data)->setHiColor(this->guidehicolor); + for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->setHiColor(this->guidehicolor); } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -362,10 +352,8 @@ void SPNamedView::set(unsigned int key, const gchar* value) { case SP_ATTR_GUIDEHIOPACITY: this->guidehicolor = (this->guidehicolor & 0xffffff00) | (DEFAULTGUIDEHICOLOR & 0xff); sp_nv_read_opacity(value, &this->guidehicolor); - - for (GSList *l = this->guides; l != NULL; l = l->next) { - //g_object_set(G_OBJECT(l->data), "hicolor", nv->guidehicolor, NULL); - SP_GUIDE(l->data)->setHiColor(this->guidehicolor); + for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->setHiColor(this->guidehicolor); } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -614,10 +602,9 @@ static Inkscape::CanvasGrid* sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *desktop) { Inkscape::CanvasGrid* grid = NULL; //check if namedview already has an object for this grid - for (GSList *l = nv->grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid* g = (Inkscape::CanvasGrid*) l->data; - if (repr == g->repr) { - grid = g; + for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=nv->grids.begin();it!=nv->grids.end();++it ) { + if (repr == (*it)->repr) { + grid = (*it); break; } } @@ -630,14 +617,13 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des return NULL; } grid = Inkscape::CanvasGrid::NewGrid(nv, repr, nv->document, gridtype); - nv->grids = g_slist_append(nv->grids, grid); + nv->grids.push_back(grid); } if (!desktop) { //add canvasitem to all desktops - for (GSList *l = nv->views; l != NULL; l = l->next) { - SPDesktop *dt = static_cast<SPDesktop*>(l->data); - grid->createCanvasItem(dt); + for(std::vector<SPDesktop *>::const_iterator it=nv->views.begin();it!=nv->views.end();++it ) { + grid->createCanvasItem(*it); } } else { //add canvasitem only for specified desktop @@ -660,7 +646,7 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r if (SP_IS_GUIDE(no)) { SPGuide *g = (SPGuide *) no; - this->guides = g_slist_prepend(this->guides, g); + this->guides.push_back(g); //g_object_set(G_OBJECT(g), "color", this->guidecolor, "hicolor", this->guidehicolor, NULL); g->setColor(this->guidecolor); @@ -668,11 +654,11 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r g->readAttr("inkscape:color"); if (this->editable) { - for (GSList *l = this->views; l != NULL; l = l->next) { - g->SPGuide::showSPGuide(static_cast<SPDesktop*>(l->data)->guides, (GCallback) sp_dt_guide_event); + for(std::vector<SPDesktop *>::const_iterator it=this->views.begin();it!=this->views.end();++it ) { + g->SPGuide::showSPGuide((*it)->guides, (GCallback) sp_dt_guide_event); - if (static_cast<SPDesktop*>(l->data)->guides_active) { - g->sensitize((static_cast<SPDesktop*> (l->data))->getCanvas(), TRUE); + if ((*it)->guides_active) { + g->sensitize((*it)->getCanvas(), TRUE); } sp_namedview_show_single_guide(SP_GUIDE(g), this->showguides); @@ -684,27 +670,20 @@ void SPNamedView::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *r void SPNamedView::remove_child(Inkscape::XML::Node *child) { if (!strcmp(child->name(), "inkscape:grid")) { - for ( GSList *iter = this->grids ; iter ; iter = iter->next ) { - Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)iter->data; - - if ( gr->repr == child ) { - delete gr; - this->grids = g_slist_remove_link(this->grids, iter); + for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) { + if ( (*it)->repr == child ) { + delete (*it); + this->grids.erase(it); break; } } } else { - GSList **ref = &this->guides; - for ( GSList *iter = this->guides ; iter ; iter = iter->next ) { - - if ( reinterpret_cast<SPObject *>(iter->data)->getRepr() == child ) { - *ref = iter->next; - iter->next = NULL; - g_slist_free_1(iter); + for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) { + if ( (*it)->getRepr() == child ) { + delete (*it); + this->guides.erase(it); break; - } - - ref = &iter->next; + } } } @@ -727,15 +706,15 @@ Inkscape::XML::Node* SPNamedView::write(Inkscape::XML::Document *xml_doc, Inksca void SPNamedView::show(SPDesktop *desktop) { - for (GSList *l = guides; l != NULL; l = l->next) { - SP_GUIDE(l->data)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event); + for(std::vector<SPGuide *>::const_iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event); if (desktop->guides_active) { - SP_GUIDE(l->data)->sensitize(desktop->getCanvas(), TRUE); + (*it)->sensitize(desktop->getCanvas(), TRUE); } - sp_namedview_show_single_guide(SP_GUIDE(l->data), showguides); + sp_namedview_show_single_guide((*it), showguides); } - views = g_slist_prepend(views, desktop); + views.push_back(desktop); // generate grids specified in SVG: Inkscape::XML::Node *repr = this->getRepr(); @@ -924,31 +903,28 @@ void sp_namedview_document_from_window(SPDesktop *desktop) void SPNamedView::hide(SPDesktop const *desktop) { g_assert(desktop != NULL); - g_assert(g_slist_find(views, desktop)); - - for (GSList *l = guides; l != NULL; l = l->next) { - SP_GUIDE(l->data)->hideSPGuide(desktop->getCanvas()); + g_assert(std::find(views.begin(),views.end(),desktop)!=views.end()); + for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->hideSPGuide(desktop->getCanvas()); } - - views = g_slist_remove(views, desktop); + views.erase(std::remove(views.begin(),views.end(),desktop),views.end()); } void SPNamedView::activateGuides(void* desktop, bool active) { g_assert(desktop != NULL); - g_assert(g_slist_find(views, desktop)); + g_assert(std::find(views.begin(),views.end(),desktop)!=views.end()); SPDesktop *dt = static_cast<SPDesktop*>(desktop); - - for (GSList *l = guides; l != NULL; l = l->next) { - SP_GUIDE(l->data)->sensitize(dt->getCanvas(), active); + for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) { + (*it)->sensitize(dt->getCanvas(), active); } } static void sp_namedview_setup_guides(SPNamedView *nv) { - for (GSList *l = nv->guides; l != NULL; l = l->next) { - sp_namedview_show_single_guide(SP_GUIDE(l->data), nv->showguides); + for(std::vector<SPGuide *>::iterator it=nv->guides.begin();it!=nv->guides.end();++it ) { + sp_namedview_show_single_guide(*it, nv->showguides); } } @@ -1010,7 +986,7 @@ guint SPNamedView::getViewCount() return ++viewcount; } -GSList const *SPNamedView::getViewList() const +std::vector<SPDesktop *> const SPNamedView::getViewList() const { return views; } @@ -1144,18 +1120,17 @@ Inkscape::Util::Unit const & SPNamedView::getSVGUnit() const */ Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview) { - for (GSList const * l = namedview->grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data; - if (grid->isEnabled()) - return grid; + for(std::vector<Inkscape::CanvasGrid *>::const_iterator it=namedview->grids.begin();it!=namedview->grids.end();++it ) { + if ((*it)->isEnabled()) + return (*it); } return NULL; } void SPNamedView::translateGuides(Geom::Translate const &tr) { - for (GSList *l = guides; l != NULL; l = l->next) { - SPGuide &guide = *SP_GUIDE(l->data); + for(std::vector<SPGuide *>::iterator it=this->guides.begin();it!=this->guides.end();++it ) { + SPGuide &guide = *(*it); Geom::Point point_on_line = guide.getPoint(); point_on_line *= tr; guide.moveto(point_on_line, true); @@ -1163,19 +1138,15 @@ void SPNamedView::translateGuides(Geom::Translate const &tr) { } void SPNamedView::translateGrids(Geom::Translate const &tr) { - for (GSList *l = grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid* g = reinterpret_cast<Inkscape::CanvasGrid*>(l->data); - if (g) { - g->setOrigin(g->origin * tr); - } + for(std::vector<Inkscape::CanvasGrid *>::iterator it=this->grids.begin();it!=this->grids.end();++it ) { + (*it)->setOrigin((*it)->origin * tr); } } void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) { - for(GSList *l = views; l; l = l->next) { - SPDesktop *desktop = static_cast<SPDesktop *>(l->data); - desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling); - } + for(std::vector<SPDesktop *>::iterator it=this->views.begin();it!=this->views.end();++it ) { + (*it)->scroll_world_in_svg_coords(dx, dy, is_scrolling); + } } diff --git a/src/sp-namedview.h b/src/sp-namedview.h index f1ecc12d3..8db253d25 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -21,6 +21,7 @@ #include "snap.h" #include "document.h" #include "util/units.h" +#include <vector> namespace Inkscape { class CanvasGrid; @@ -58,7 +59,7 @@ public: int window_maximized; SnapManager snap_manager; - GSList * grids; + std::vector<Inkscape::CanvasGrid *> grids; bool grids_visible; Inkscape::Util::Unit const *svg_units; // Units used for the values in SVG @@ -75,8 +76,8 @@ public: guint32 pagecolor; guint32 pageshadow; - GSList *guides; - GSList *views; + std::vector<SPGuide *> guides; + std::vector<SPDesktop *> views; int viewcount; @@ -85,7 +86,7 @@ public: void activateGuides(void* desktop, bool active); char const *getName() const; unsigned int getViewCount(); - GSList const *getViewList() const; + std::vector<SPDesktop *> const getViewList() const; Inkscape::Util::Unit const * getDisplayUnit() const; Inkscape::Util::Unit const & getSVGUnit() const; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index b04e8ecc1..5b63d14e1 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1364,12 +1364,11 @@ void DocumentProperties::update_gridspage() //add tabs bool grids_present = false; - for (GSList const * l = nv->grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data; - if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added - Glib::ustring name(grid->repr->attribute("id")); + for(std::vector<Inkscape::CanvasGrid *>::const_iterator it = nv->grids.begin(); it != nv->grids.end(); ++it) { + if (!(*it)->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added + Glib::ustring name((*it)->repr->attribute("id")); const char *icon = NULL; - switch (grid->getGridType()) { + switch ((*it)->getGridType()) { case GRID_RECTANGULAR: icon = "grid-rectangular"; break; @@ -1379,7 +1378,7 @@ void DocumentProperties::update_gridspage() default: break; } - _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon)); + _grids_notebook.append_page(*(*it)->newWidget(), _createPageTabLabel(name, icon)); grids_present = true; } _grids_notebook.show_all(); @@ -1639,14 +1638,9 @@ void DocumentProperties::onRemoveGrid() SPDesktop *dt = getDesktop(); SPNamedView *nv = dt->getNamedView(); Inkscape::CanvasGrid * found_grid = NULL; - int i = 0; - for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works. - Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data; - if (pagenum == i) { - found_grid = grid; - break; // break out of for-loop - } - } + if( pagenum < nv->grids.size()) + found_grid = nv->grids[pagenum]; + if (found_grid) { // delete the grid that corresponds with the selected tab // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer! |
