diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2015-04-29 21:14:01 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <mc@M0nst3r.bouyguesbox.fr> | 2015-04-29 21:14:01 +0000 |
| commit | 9b7af8caac08ad42a48214518bc004e258eb5873 (patch) | |
| tree | dcaaac56217eb5da334ab420f5e791cf7eb70f23 /src/path-chemistry.cpp | |
| parent | Better solution picking (diff) | |
| parent | corrected test file (diff) | |
| download | inkscape-9b7af8caac08ad42a48214518bc004e258eb5873.tar.gz inkscape-9b7af8caac08ad42a48214518bc004e258eb5873.zip | |
bzr merge lp:~mc.../inkscape/SelContainer
The main change of this branch is that the container for selections is now a std::vector and not a GSList.
This change propagates in most of the codebase.
Normally, there are no changes of semantics, except the following:
-> childList is now in the intuitive order (childList()[0] is now firstChild)
-> sp_selection_paste_impl is now in the opposite order (change is local to selection-chemistry.cpp, and simplify a few things there)
-> selection.setReprList now takes the list in the opposite order. It was always the case (the list was always reversed before handing to it)
-> a few comparison functions now work "the c++ way": the C way was to return -1 if a<b, 0 if a==b and 1 if a>b, now they return (bool)(a<b) so they can be used with std::sort
(bzr r14074)
Diffstat (limited to 'src/path-chemistry.cpp')
| -rw-r--r-- | src/path-chemistry.cpp | 117 |
1 files changed, 51 insertions, 66 deletions
diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 988559e30..8d2695b85 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -44,13 +44,22 @@ using Inkscape::DocumentUndo; + +inline bool less_than_items(SPItem const *first, SPItem const *second) +{ + return sp_repr_compare_position(first->getRepr(), + second->getRepr())<0; +} + void sp_selected_path_combine(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); + + std::vector<SPItem*> items(selection->itemList()); - if (g_slist_length((GSList *) selection->itemList()) < 1) { + if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); return; } @@ -59,28 +68,23 @@ sp_selected_path_combine(SPDesktop *desktop) // set "busy" cursor desktop->setWaitingCursor(); - GSList *items = g_slist_copy((GSList *) selection->itemList()); - items = sp_degroup_list (items); // descend into any groups in selection - GSList *to_paths = NULL; - for (GSList *i = items; i != NULL; i = i->next) { - SPItem *item = (SPItem *) i->data; - if (!dynamic_cast<SPPath *>(item) && !dynamic_cast<SPGroup *>(item)) { - to_paths = g_slist_prepend(to_paths, item); + std::vector<SPItem*> to_paths; + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) { + if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) { + to_paths.push_back(*i); } } - GSList *converted = NULL; - bool did = sp_item_list_to_curves(to_paths, &items, &converted); - g_slist_free(to_paths); - for (GSList *i = converted; i != NULL; i = i->next) - items = g_slist_prepend(items, doc->getObjectByRepr((Inkscape::XML::Node*)(i->data))); + std::vector<Inkscape::XML::Node*> converted; + bool did = sp_item_list_to_curves(to_paths, items, converted); + for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); i++) + items.push_back((SPItem*)doc->getObjectByRepr(*i)); items = sp_degroup_list (items); // converting to path may have added more groups, descend again - items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); - items = g_slist_reverse(items); - assert(items); // cannot be NULL because of list length check at top of function + sort(items.begin(),items.end(),less_than_items); + assert(!items.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one gint position = 0; @@ -97,9 +101,9 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (GSList *i = items; i != NULL; i = i->next) { // going from top to bottom + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){ - SPItem *item = (SPItem *) i->data; + SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); if (!path) { continue; @@ -136,7 +140,6 @@ sp_selected_path_combine(SPDesktop *desktop) } } - g_slist_free(items); if (did) { first->deleteObject(false); @@ -200,11 +203,10 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; - for (GSList *items = g_slist_copy((GSList *) selection->itemList()); - items != NULL; - items = items->next) { + std::vector<SPItem*> itemlist(selection->itemList()); + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){ - SPItem *item = (SPItem *) items->data; + SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); if (!path) { @@ -241,7 +243,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) curve->unref(); - GSList *reprs = NULL; + std::vector<Inkscape::XML::Node*> reprs; for (GSList *l = list; l != NULL; l = l->next) { curve = (SPCurve *) l->data; @@ -267,14 +269,12 @@ sp_selected_path_break_apart(SPDesktop *desktop) if (l == list) repr->setAttribute("id", id); - reprs = g_slist_prepend (reprs, repr); + reprs.push_back(repr); Inkscape::GC::release(repr); } - selection->setReprList(reprs); - g_slist_free(reprs); g_slist_free(list); g_free(style); g_free(path_effect); @@ -307,18 +307,15 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + std::vector<SPItem*> selected(selection->itemList()); + std::vector<Inkscape::XML::Node*> to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + std::vector<SPItem*> items(selected); - did = sp_item_list_to_curves(items, &selected, &to_select); + did = sp_item_list_to_curves(items, selected, to_select); - g_slist_free (items); selection->setReprList(to_select); selection->addList(selected); - g_slist_free (to_select); - g_slist_free (selected); if (interactive && desktop) { desktop->clearWaitingCursor(); @@ -341,33 +338,24 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - GSList *selected = g_slist_copy((GSList *) selection->itemList()); - GSList *to_select = NULL; + std::vector<SPItem*> selected(selection->itemList()); + std::vector<Inkscape::XML::Node*> to_select; selection->clear(); - GSList *items = g_slist_copy(selected); + std::vector<SPItem*> items(selected); + - sp_item_list_to_curves(items, &selected, &to_select, true); + sp_item_list_to_curves(items, selected, to_select, true); - g_slist_free(items); - items = 0; selection->setReprList(to_select); selection->addList(selected); - g_slist_free(to_select); - to_select = 0; - g_slist_free(selected); - selected = 0; } bool -sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems) +sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*>& selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems) { bool did = false; - - for (; - items != NULL; - items = items->next) { - - SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data)); + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ + SPItem *item = *i; g_assert(item != NULL); SPDocument *document = item->document; @@ -398,9 +386,9 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec Inkscape::XML::Node *repr = box3d_convert_to_group(box)->getRepr(); if (repr) { - *to_select = g_slist_prepend (*to_select, repr); + to_select.insert(to_select.begin(),repr); did = true; - *selected = g_slist_remove (*selected, item); + selected.erase(find(selected.begin(),selected.end(),item)); } continue; @@ -408,17 +396,14 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec if (group) { group->removeAllPathEffects(true); - GSList *item_list = sp_item_group_item_list(group); + std::vector<SPItem*> item_list = sp_item_group_item_list(group); - GSList *item_to_select = NULL; - GSList *item_selected = NULL; + std::vector<Inkscape::XML::Node*> item_to_select; + std::vector<SPItem*> item_selected; - if (sp_item_list_to_curves(item_list, &item_selected, &item_to_select)) + if (sp_item_list_to_curves(item_list, item_selected, item_to_select)) did = true; - g_slist_free(item_list); - g_slist_free(item_to_select); - g_slist_free(item_selected); continue; } @@ -428,7 +413,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec continue; did = true; - *selected = g_slist_remove (*selected, item); + selected.erase(find(selected.begin(),selected.end(),item)); // remember the position of the item gint pos = item->getRepr()->position(); @@ -470,7 +455,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec /* Buglet: We don't re-add the (new version of the) object to the selection of any other * desktops where it was previously selected. */ - *to_select = g_slist_prepend (*to_select, repr); + to_select.insert(to_select.begin(),repr); Inkscape::GC::release(repr); } @@ -622,9 +607,9 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - GSList *items = (GSList *) selection->itemList(); + std::vector<SPItem*> items = selection->itemList(); - if (!items) { + if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); return; } @@ -636,9 +621,9 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (GSList *i = items; i != NULL; i = i->next) { + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ - SPPath *path = dynamic_cast<SPPath *>(static_cast<SPObject *>(i->data)); + SPPath *path = dynamic_cast<SPPath *>(*i); if (!path) { continue; } |
