diff options
| author | mc <> | 2015-02-18 10:25:23 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <mc> | 2015-02-18 10:25:23 +0000 |
| commit | 9e21d00fb1053897420f80d05a9815c5b2bbf312 (patch) | |
| tree | 9c0f61257c24e936d07526bd4b71a399825519b6 /src | |
| parent | OMG IT'S COMPILING. (diff) | |
| download | inkscape-9e21d00fb1053897420f80d05a9815c5b2bbf312.tar.gz inkscape-9e21d00fb1053897420f80d05a9815c5b2bbf312.zip | |
I can't really understand why, but i can now launch inkscape without it segfaulting.
That's an improvement.
Next thing: code cleaning, replacing containers with vectors
(bzr r13922.1.4)
Diffstat (limited to 'src')
| -rw-r--r-- | src/selection-chemistry.cpp | 82 | ||||
| -rw-r--r-- | src/selection.cpp | 10 | ||||
| -rw-r--r-- | src/selection.h | 4 | ||||
| -rw-r--r-- | src/splivarot.cpp | 6 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 12 | ||||
| -rw-r--r-- | src/ui/dialog/filter-effects-dialog.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/svg-fonts-dialog.cpp | 4 |
7 files changed, 53 insertions, 67 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c213e76e4..9f27ca22e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -462,13 +462,13 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to duplicate.")); return; } - SelContainer reprs(selection->reprList()); + std::vector<Inkscape::XML::Node*> reprs(selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing // them, just what we need - reprs.sort(sp_repr_compare_position_obj); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); SelContainer newsel; @@ -478,8 +478,8 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - while (!reprs.empty()) { - Inkscape::XML::Node *old_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front()); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *old_repr = (*i); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -501,7 +501,6 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) } newsel.push_front(dynamic_cast<SPObject*>(copy)); - reprs.pop_front(); Inkscape::GC::release(copy); } @@ -692,16 +691,16 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) sp_edit_select_all_full(desktop, true, true); } -static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { +static void sp_selection_group_impl(std::vector<Inkscape::XML::Node*> p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { - p.sort(sp_repr_compare_position_obj); + sort(p.begin(),p.end(),sp_repr_compare_position); // Remember the position and parent of the topmost object. gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position(); Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent(); - while (!p.empty()) { - Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front()); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();i++){ + Inkscape::XML::Node *current = (*i); if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -745,7 +744,6 @@ static void sp_selection_group_impl(SelContainer p, Inkscape::XML::Node *group, copied.clear(); } } - p.pop_front(); } // Add the new group to the topmost members' parent @@ -766,7 +764,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - SelContainer p (selection->reprList()); + std::vector<Inkscape::XML::Node*> p (selection->reprList()); selection->clear(); @@ -1027,16 +1025,14 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - SelContainer rl(selection->reprList()); - rl.sort(sp_repr_compare_position_obj); + std::vector<Inkscape::XML::Node*> rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (SelContainer::iterator l=rl.begin(); l!=rl.end();l++) { - Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l); + for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();l++) { + Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } - rl.clear(); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, _("Raise to top")); } @@ -1117,14 +1113,13 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - SelContainer rl(selection->reprList()); - rl.sort(sp_repr_compare_position_obj); - rl.reverse(); + std::vector<Inkscape::XML::Node*> rl(selection->reprList()); + sort(rl.begin(),rl.end(),sp_repr_compare_position); - for (SelContainer::const_iterator l=rl.begin();l!=rl.end();l++) { + for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { gint minpos; SPObject *pp, *pc; - Inkscape::XML::Node *repr = dynamic_cast<Inkscape::XML::Node *>(*l); + Inkscape::XML::Node *repr = (*l); pp = document->getObjectByRepr(repr->parent()); minpos = 0; g_assert(dynamic_cast<SPGroup *>(pp)); @@ -1136,8 +1131,6 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des repr->setPosition(minpos); } - rl.clear(); - DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, _("Lower to bottom")); } @@ -1691,9 +1684,9 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - SelContainer items = selection->itemList(); - for (SelContainer::const_iterator l=items.begin();l!=items.end() ;l++) { - ((Inkscape::XML::Node*)*l)->setAttribute("transform", NULL, false); + std::vector<Inkscape::XML::Node*> items = selection->reprList(); + for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;l++) { + (*l)->setAttribute("transform", NULL, false); } DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_FLATTEN, @@ -2590,17 +2583,17 @@ void sp_selection_clone(SPDesktop *desktop) return; } - SelContainer reprs (selection->reprList()); + std::vector<Inkscape::XML::Node*> reprs (selection->reprList()); selection->clear(); // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need - reprs.sort(sp_repr_compare_position_obj); + sort(reprs.begin(),reprs.end(),sp_repr_compare_position); SelContainer newsel; - while (!reprs.empty()) { - Inkscape::XML::Node *sel_repr = dynamic_cast<Inkscape::XML::Node *>(reprs.front()); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ + Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2617,7 +2610,6 @@ void sp_selection_clone(SPDesktop *desktop) parent->appendChild(clone); newsel.push_front(dynamic_cast<SPObject*>(clone)); - reprs.pop_front(); Inkscape::GC::release(clone); } @@ -3462,14 +3454,14 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - SelContainer const reprlst = selection->reprList(); + std::vector<Inkscape::XML::Node*> const reprlst = selection->reprList(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (SelContainer::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ + for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ gchar const *dpi_string; - Inkscape::XML::Node * repr = dynamic_cast<Inkscape::XML::Node *>(*i); + Inkscape::XML::Node * repr = (*i); if (filename_search) { const gchar* tmp = repr->attribute("inkscape:export-filename"); @@ -3756,22 +3748,20 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - SelContainer l=selection->reprList(); - - SelContainer p(l); + std::vector<Inkscape::XML::Node*> p(selection->reprList()); - p.sort(sp_repr_compare_position_obj); + sort(p.begin(),p.end(),sp_repr_compare_position); selection->clear(); - gint topmost = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->position(); - Inkscape::XML::Node *topmost_parent = (dynamic_cast<Inkscape::XML::Node *>(p.back()))->parent(); + int topmost = (p.back())->position(); + Inkscape::XML::Node *topmost_parent = (p.back())->parent(); Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - while (!p.empty()) { - Inkscape::XML::Node *current = dynamic_cast<Inkscape::XML::Node *>(p.front()); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();i++){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3813,7 +3803,6 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::GC::release(spnew); } } - p.pop_front(); } Inkscape::XML::Node *outer = xml_doc->createElement("svg:g"); @@ -3960,13 +3949,12 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ // make a note we should ungroup this when unsetting mask group->setAttribute("inkscape:groupmode", "maskhelper"); - SelContainer reprs_to_group; + std::vector<Inkscape::XML::Node*> reprs_to_group; for (GSList *i = apply_to_items ; NULL != i ; i = i->next) { - reprs_to_group.push_front(dynamic_cast<SPObject*>(SP_OBJECT(i->data)->getRepr())); + reprs_to_group.push_back(static_cast<SPObject*>(i->data)->getRepr()); items_to_select.remove(static_cast<SPObject*>(i->data)); } - reprs_to_group.reverse(); sp_selection_group_impl(reprs_to_group, group, xml_doc, doc); diff --git a/src/selection.cpp b/src/selection.cpp index b509f4272..cbde9a799 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -43,7 +43,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : _objs(SelContainer()), - _reprs(SelContainer()), + _reprs(std::vector<XML::Node*>()), _items(SelContainer()), _layers(layers), _desktop(desktop), @@ -296,15 +296,13 @@ SelContainer const &Selection::itemList() { return _items; } -SelContainer const &Selection::reprList() { +std::vector<XML::Node*> const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } SelContainer list = itemList(); for ( SelContainer::const_iterator iter=list.begin();iter!=list.end();iter++ ) { SPObject *obj=reinterpret_cast<SPObject *>(*iter); - _reprs.push_front(dynamic_cast<SPObject*>(obj->getRepr())); + _reprs.push_back(obj->getRepr()); } - _reprs.reverse(); - return _reprs; } @@ -343,7 +341,7 @@ SPObject *Selection::single() { SPItem *Selection::singleItem() { SelContainer const items=itemList(); - if ( !items.size()==1) { + if ( items.size()==1) { return reinterpret_cast<SPItem *>(items.front()); } else { return NULL; diff --git a/src/selection.h b/src/selection.h index 7171b8742..f85c6346b 100644 --- a/src/selection.h +++ b/src/selection.h @@ -260,7 +260,7 @@ public: /** Returns a list of the xml nodes of all selected objects. */ /// \todo only returns reprs of SPItems currently; need a separate /// method for that - std::list<SPObject*> const &reprList(); + std::vector<XML::Node*> const &reprList(); /** Returns a list of all perspectives which have a 3D box in the current selection. (these may also be nested in groups) */ @@ -377,7 +377,7 @@ private: void _releaseContext(SPObject *obj); mutable std::list<SPObject*> _objs; - mutable std::list<SPObject*> _reprs; + mutable std::vector<XML::Node*> _reprs; mutable std::list<SPObject*> _items; void add_box_perspective(SPBox3D *box); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index aec7051e0..107dfc629 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -691,11 +691,11 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } else { // find out the bottom object - SelContainer sorted(selection->reprList()); + std::vector<Inkscape::XML::Node*> sorted(selection->reprList()); - sorted.sort(sp_repr_compare_position_obj); + sort(sorted.begin(),sorted.end(),sp_repr_compare_position); - source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted.front()); + source = doc->getObjectByRepr(sorted.front()); } // adjust style properties that depend on a possible transform in the source object in order diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index fc6094c9f..0667ba721 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -817,9 +817,9 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const SelContainer reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { - Inkscape::XML::Node * repr = (Inkscape::XML::Node *)(*i); + const std::vector<XML::Node*> reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); + for(std::vector<XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = (*i); if (repr->attribute("id")) { id = repr->attribute("id"); break; @@ -1226,7 +1226,7 @@ void Export::onExport () break; } case SELECTION_SELECTION: { - SelContainer reprlst; + std::vector<XML::Node*> reprlst; SPDocument * doc = SP_ACTIVE_DOCUMENT; bool modified = false; @@ -1234,8 +1234,8 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(SelContainer::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { - Inkscape::XML::Node * repr = dynamic_cast<Inkscape::XML::Node *>(*i); + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 657d6771b..f67c1d173 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -690,7 +690,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = (Inkscape::XML::Node*) sel->reprList().front(); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 8f5601e3a..12b423602 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -524,7 +524,7 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a <b>path</b> description."); @@ -566,7 +566,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = (Inkscape::XML::Node*)(sel->reprList().front()); + Inkscape::XML::Node* node = sel->reprList().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a <b>path</b> description."); |
