diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-02 00:12:27 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2017-10-02 00:12:27 +0000 |
| commit | 8761f46f7b8c2a2df82203f5be89d60072998a82 (patch) | |
| tree | 98718445ab30910a8e053bcf2a0d83a1b002630d /src | |
| parent | First batch (diff) | |
| download | inkscape-8761f46f7b8c2a2df82203f5be89d60072998a82.tar.gz inkscape-8761f46f7b8c2a2df82203f5be89d60072998a82.zip | |
Second batch
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 80 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 42 | ||||
| -rw-r--r-- | src/sp-flowdiv.cpp | 107 | ||||
| -rw-r--r-- | src/sp-tspan.cpp | 33 | ||||
| -rw-r--r-- | src/sp-use.cpp | 15 | ||||
| -rw-r--r-- | src/ui/tools/gradient-tool.cpp | 85 | ||||
| -rw-r--r-- | src/ui/tools/mesh-tool.cpp | 62 | ||||
| -rw-r--r-- | src/ui/tools/tweak-tool.cpp | 13 |
8 files changed, 138 insertions, 299 deletions
diff --git a/src/main.cpp b/src/main.cpp index 71014ee35..3402bcc72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -294,7 +294,7 @@ static void resetCommandlineGlobals() { #ifdef WIN32 static bool replaceArgs( int& argc, char**& argv ); #endif -static GSList *sp_process_args(poptContext ctx); +static std::vector<gchar *> sp_process_args(poptContext ctx); struct poptOption options[] = { {"version", 'V', POPT_ARG_NONE, NULL, SP_ARG_VERSION, @@ -815,46 +815,19 @@ static void fixupSingleFilename( gchar **orig, gchar **spare ) -static GSList *fixupFilenameEncoding( GSList* fl ) +static void fixupFilenameEncoding( std::vector<gchar*> &filenames) { - GSList *newFl = NULL; - while ( fl ) { - gchar *fn = static_cast<gchar*>(fl->data); - fl = g_slist_remove( fl, fl->data ); + for (int i=0; i<filenames.size(); ++i ) { + gchar *fn = filenames[i]; gchar *newFileName = Inkscape::IO::locale_to_utf8_fallback(fn, -1, NULL, NULL, NULL); if ( newFileName ) { - - if ( 0 ) - { - gchar *safeFn = Inkscape::IO::sanitizeString(fn); - gchar *safeNewFn = Inkscape::IO::sanitizeString(newFileName); - GtkWidget *w = gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "Note: Converted '%s' to '%s'", safeFn, safeNewFn ); - gtk_dialog_run (GTK_DIALOG (w)); - gtk_widget_destroy (w); - g_free(safeNewFn); - g_free(safeFn); - } - g_free( fn ); - fn = newFileName; - newFileName = 0; - } - else - if ( 0 ) - { - gchar *safeFn = Inkscape::IO::sanitizeString(fn); - GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Error: Unable to convert '%s'", safeFn ); - gtk_dialog_run (GTK_DIALOG (w)); - gtk_widget_destroy (w); - g_free(safeFn); + filenames[i] = newFileName; } - newFl = g_slist_append( newFl, fn ); } - return newFl; } -static int sp_common_main( int argc, char const **argv, GSList **flDest ) +static int sp_common_main( int argc, char const **argv, std::vector<gchar*> *flDest ) { #ifdef ENABLE_NLS // temporarily switch gettext encoding to locale, so that help messages can be output properly @@ -866,7 +839,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) g_return_val_if_fail(ctx != NULL, 1); /* Collect own arguments */ - GSList *fl = sp_process_args(ctx); + std::vector<gchar*> fl = sp_process_args(ctx); poptFreeContext(ctx); #ifdef ENABLE_NLS @@ -877,7 +850,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) // Now let's see if the file list still holds up if ( needToRecodeParams ) { - fl = fixupFilenameEncoding( fl ); + fixupFilenameEncoding( fl ); } // Check the globals for filename-fixup @@ -916,12 +889,10 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) // Return the list if wanted, else free it up. if ( flDest ) { - *flDest = fl; - fl = 0; + flDest->insert(flDest->end(),fl.begin(),fl.end()); } else { - while ( fl ) { - g_free( fl->data ); - fl = g_slist_remove( fl, fl->data ); + for (auto i:fl) { + g_free(i); } } return 0; @@ -1020,7 +991,7 @@ sp_main_gui(int argc, char const **argv) { Gtk::Main main_instance (&argc, const_cast<char ***>(&argv)); - GSList *fl = NULL; + std::vector<gchar *> fl; int retVal = sp_common_main( argc, argv, &fl ); g_return_val_if_fail(retVal == 0, 1); @@ -1036,11 +1007,10 @@ sp_main_gui(int argc, char const **argv) /// \todo FIXME BROKEN - non-UTF-8 sneaks in here. Inkscape::Application::create(argv[0], true); - while (fl) { - if (sp_file_open((gchar *)fl->data,NULL)) { + for (auto i:fl) { + if (sp_file_open(i,NULL)) { create_new=false; } - fl = g_slist_remove(fl, fl->data); } if (create_new) { sp_file_new_default(); @@ -1060,11 +1030,11 @@ sp_main_gui(int argc, char const **argv) /** * Process file list */ -static int sp_process_file_list(GSList *fl) +static int sp_process_file_list(std::vector<gchar*> fl) { int retVal = 0; #ifdef WITH_DBUS - if (!fl) { + if (fl.empty()) { // If we've been asked to listen for D-Bus messages, enter a main loop here // The main loop may be exited by calling "exit" on the D-Bus application interface. if (sp_dbus_listen) { @@ -1074,8 +1044,7 @@ static int sp_process_file_list(GSList *fl) } #endif // WITH_DBUS - while (fl) { - const gchar *filename = (gchar *)fl->data; + for (auto filename:fl) { SPDocument *doc = NULL; try { @@ -1201,7 +1170,6 @@ static int sp_process_file_list(GSList *fl) delete doc; } - fl = g_slist_remove(fl, fl->data); } return retVal; } @@ -1258,7 +1226,7 @@ static int sp_main_shell(char const* command_name) poptContext ctx = poptGetContext(NULL, argc, const_cast<const gchar**>(argv), options, 0); poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:")); if ( ctx ) { - GSList *fl = sp_process_args(ctx); + std::vector<gchar *> fl = sp_process_args(ctx); if (sp_process_file_list(fl)) { retval = -1; } @@ -1297,11 +1265,11 @@ int sp_main_console(int argc, char const **argv) char **argv2 = const_cast<char **>(argv); gtk_init_check( &argc, &argv2 ); - GSList *fl = NULL; + std::vector<gchar*> fl; int retVal = sp_common_main( argc, argv, &fl ); g_return_val_if_fail(retVal == 0, 1); - if (fl == NULL && !sp_shell + if (fl.empty() && !sp_shell #ifdef WITH_DBUS && !sp_dbus_listen #endif // WITH_DBUS @@ -2131,10 +2099,10 @@ bool replaceArgs( int& argc, char**& argv ) } #endif // WIN32 -static GSList * +static std::vector<gchar *> sp_process_args(poptContext ctx) { - GSList *fl = NULL; + std::vector<gchar *> fl; gint a; while ((a = poptGetNextOpt(ctx)) != -1) { @@ -2142,7 +2110,7 @@ sp_process_args(poptContext ctx) case SP_ARG_FILE: { gchar const *fn = poptGetOptArg(ctx); if (fn != NULL) { - fl = g_slist_append(fl, g_strdup(fn)); + fl.push_back(g_strdup(fn)); } break; } @@ -2214,7 +2182,7 @@ sp_process_args(poptContext ctx) gchar const ** const args = poptGetArgs(ctx); if (args != NULL) { for (unsigned i = 0; args[i] != NULL; i++) { - fl = g_slist_append(fl, g_strdup(args[i])); + fl.push_back(g_strdup(args[i])); } } diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7dfe74752..be0d7c7d8 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -768,18 +768,12 @@ Inkscape::XML::Node* ObjectSet::group() { } -static gint clone_depth_descending(gconstpointer a, gconstpointer b) { +static bool clone_depth_descending(gconstpointer a, gconstpointer b) { SPUse *use_a = static_cast<SPUse *>(const_cast<gpointer>(a)); SPUse *use_b = static_cast<SPUse *>(const_cast<gpointer>(b)); int depth_a = use_a->cloneDepth(); int depth_b = use_b->cloneDepth(); - if (depth_a < depth_b) { - return 1; - } else if (depth_a == depth_b) { - return 0; - } else { - return -1; - } + return (depth_a==depth_b)?(a<b):(depth_a>depth_b); } void ObjectSet::popFromGroup(){ @@ -822,7 +816,7 @@ static void ungroup_impl(ObjectSet *set) // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. - GSList *clones_to_unlink = NULL; + std::vector<SPUse*> clones_to_unlink; for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); ++item) { SPUse *use = dynamic_cast<SPUse *>(*item); @@ -832,21 +826,19 @@ static void ungroup_impl(ObjectSet *set) } if (groups.find(original) != groups.end()) { - clones_to_unlink = g_slist_prepend(clones_to_unlink, *item); + clones_to_unlink.push_back(use); } } // Unlink clones beginning from those with highest clone depth. // This way we can be sure than no additional automatic unlinking happens, // and the items in the list remain valid - clones_to_unlink = g_slist_sort(clones_to_unlink, clone_depth_descending); + std::sort(clones_to_unlink.begin(),clones_to_unlink.end(),clone_depth_descending); - for (GSList *item = clones_to_unlink; item; item = item->next) { - SPUse *use = static_cast<SPUse *>(item->data); - std::vector<SPItem*>::iterator items_node = std::find(items.begin(),items.end(), item->data); + for (auto use:clones_to_unlink) { + std::vector<SPItem*>::iterator items_node = std::find(items.begin(),items.end(), use); *items_node = use->unlink(); } - g_slist_free(clones_to_unlink); // do the actual work for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); ++item) { @@ -2380,7 +2372,7 @@ private: template <typename D> -SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, +SPItem *next_item(SPDesktop *desktop, std::vector<SPObject *> &path, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) { typename D::Iterator children; @@ -2388,11 +2380,12 @@ SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, SPItem *found=NULL; - if (path) { - SPObject *object=reinterpret_cast<SPObject *>(path->data); + if (!path.empty()) { + SPObject *object=path.back(); + path.pop_back(); g_assert(object->parent == root); if (desktop->isLayer(object)) { - found = next_item<D>(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + found = next_item<D>(desktop, path, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); } iter = children = D::siblings_after(object); } else { @@ -2403,7 +2396,8 @@ SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, SPObject *object=D::object(iter); if (desktop->isLayer(object)) { if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers - found = next_item<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); + std::vector<SPObject *> empt; + found = next_item<D>(desktop, empt, object, only_in_viewport, inlayer, onlyvisible, onlysensitive); } } else { SPItem *item = dynamic_cast<SPItem *>(object); @@ -2440,19 +2434,19 @@ SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const &item } } - GSList *path=NULL; + std::vector<SPObject *> path; while ( current != root ) { - path = g_slist_prepend(path, current); + path.push_back(current); current = current->parent; } SPItem *next; // first, try from the current object next = next_item<D>(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); - g_slist_free(path); if (!next) { // if we ran out of objects, start over at the root - next = next_item<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); + std::vector<SPObject *> empt; + next = next_item<D>(desktop, empt, root, only_in_viewport, inlayer, onlyvisible, onlysensitive); } return next; diff --git a/src/sp-flowdiv.cpp b/src/sp-flowdiv.cpp index 17b841e37..002fcff85 100644 --- a/src/sp-flowdiv.cpp +++ b/src/sp-flowdiv.cpp @@ -26,18 +26,13 @@ void SPFlowdiv::update(SPCtx *ctx, unsigned int flags) { } childflags &= SP_OBJECT_MODIFIED_CASCADE; - GSList* l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse(l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM(child)) { SPItem const &chi = *SP_ITEM(child); @@ -64,22 +59,16 @@ void SPFlowdiv::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); } - sp_object_unref(child); } } @@ -102,7 +91,7 @@ Inkscape::XML::Node* SPFlowdiv::write(Inkscape::XML::Document *xml_doc, Inkscape repr = xml_doc->createElement("svg:flowDiv"); } - GSList *l = NULL; + std::vector<Inkscape::XML::Node *> l; for (auto& child: children) { Inkscape::XML::Node* c_repr = NULL; @@ -116,14 +105,12 @@ Inkscape::XML::Node* SPFlowdiv::write(Inkscape::XML::Document *xml_doc, Inkscape } if ( c_repr ) { - l = g_slist_prepend (l, c_repr); + l.push_back(c_repr); } } - - while ( l ) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove(l, l->data); + for (auto i=l.rbegin();i!=l.rend();++i) { + repr->addChild(*i, NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { @@ -166,19 +153,13 @@ void SPFlowtspan::update(SPCtx *ctx, unsigned int flags) { childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } childflags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList* l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM(child)) { SPItem const &chi = *SP_ITEM(child); @@ -204,23 +185,16 @@ void SPFlowtspan::modified(unsigned int flags) { } flags &= SP_OBJECT_MODIFIED_CASCADE; - - GSList *l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); } - sp_object_unref(child); } } @@ -240,7 +214,7 @@ Inkscape::XML::Node *SPFlowtspan::write(Inkscape::XML::Document *xml_doc, Inksca repr = xml_doc->createElement("svg:flowSpan"); } - GSList *l = NULL; + std::vector<Inkscape::XML::Node *> l; for (auto& child: children) { Inkscape::XML::Node* c_repr = NULL; @@ -254,14 +228,12 @@ Inkscape::XML::Node *SPFlowtspan::write(Inkscape::XML::Document *xml_doc, Inksca } if ( c_repr ) { - l = g_slist_prepend(l, c_repr); + l.push_back(c_repr); } } - - while ( l ) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove(l, l->data); + for (auto i=l.rbegin();i!=l.rend();++i) { + repr->addChild(*i, NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { @@ -306,18 +278,13 @@ void SPFlowpara::update(SPCtx *ctx, unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList* l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { if (SP_IS_ITEM(child)) { SPItem const &chi = *SP_ITEM(child); @@ -328,7 +295,6 @@ void SPFlowpara::update(SPCtx *ctx, unsigned int flags) { child->updateDisplay(ctx, flags); } } - sp_object_unref(child); } } @@ -342,22 +308,16 @@ void SPFlowpara::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = NULL; + std::vector<SPObject *> l; for (auto& child: children) { sp_object_ref(&child); - l = g_slist_prepend(l, &child); + l.push_back(&child); } - l = g_slist_reverse (l); - - while (l) { - SPObject *child = SP_OBJECT(l->data); - l = g_slist_remove(l, child); - + for(auto child:l) { if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); } - sp_object_unref(child); } } @@ -377,7 +337,7 @@ Inkscape::XML::Node *SPFlowpara::write(Inkscape::XML::Document *xml_doc, Inkscap repr = xml_doc->createElement("svg:flowPara"); } - GSList *l = NULL; + std::vector<Inkscape::XML::Node *> l; for (auto& child: children) { Inkscape::XML::Node* c_repr = NULL; @@ -391,14 +351,13 @@ Inkscape::XML::Node *SPFlowpara::write(Inkscape::XML::Document *xml_doc, Inkscap } if ( c_repr ) { - l = g_slist_prepend(l, c_repr); + l.push_back(c_repr); } } - while ( l ) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove(l, l->data); + for (auto i=l.rbegin();i!=l.rend();++i) { + repr->addChild(*i, NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 2e169ad77..d8c655c06 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -171,7 +171,7 @@ Inkscape::XML::Node* SPTSpan::write(Inkscape::XML::Document *xml_doc, Inkscape:: this->attributes.writeTo(repr); if ( flags&SP_OBJECT_WRITE_BUILD ) { - GSList *l = NULL; + std::vector<Inkscape::XML::Node *> l; for (auto& child: children) { Inkscape::XML::Node* c_repr=NULL; @@ -185,14 +185,13 @@ Inkscape::XML::Node* SPTSpan::write(Inkscape::XML::Document *xml_doc, Inkscape:: } if ( c_repr ) { - l = g_slist_prepend(l, c_repr); + l.push_back(c_repr); } } - while ( l ) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove(l, l->data); + for (auto i = l.rbegin(); i!= l.rend(); ++i) { + repr->addChild((*i), NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { @@ -395,7 +394,7 @@ Inkscape::XML::Node* SPTextPath::write(Inkscape::XML::Document *xml_doc, Inkscap } if ( flags & SP_OBJECT_WRITE_BUILD ) { - GSList *l = NULL; + std::vector<Inkscape::XML::Node *> l; for (auto& child: children) { Inkscape::XML::Node* c_repr=NULL; @@ -409,14 +408,13 @@ Inkscape::XML::Node* SPTextPath::write(Inkscape::XML::Document *xml_doc, Inkscap } if ( c_repr ) { - l = g_slist_prepend(l, c_repr); + l.push_back(c_repr); } } - while ( l ) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove(l, l->data); + for( auto i = l.rbegin(); i != l.rend(); ++i ) { + repr->addChild(*i, NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { @@ -462,24 +460,23 @@ void sp_textpath_to_text(SPObject *tp) xy *= tp->document->getDocumentScale().inverse(); // Convert to user-units. // make a list of textpath children - GSList *tp_reprs = NULL; + std::vector<Inkscape::XML::Node *> tp_reprs; for (auto& o: tp->children) { - tp_reprs = g_slist_prepend(tp_reprs, o.getRepr()); + tp_reprs.push_back(o.getRepr()); } - for ( GSList *i = tp_reprs ; i ; i = i->next ) { + for (auto i = tp_reprs.rbegin(); i != tp_reprs.rend(); ++i) { // make a copy of each textpath child - Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(text->getRepr()->document()); + Inkscape::XML::Node *copy = (*i)->duplicate(text->getRepr()->document()); // remove the old repr from under textpath - tp->getRepr()->removeChild((Inkscape::XML::Node *) i->data); + tp->getRepr()->removeChild(*i); // put its copy under text text->getRepr()->addChild(copy, NULL); // fixme: copy id } //remove textpath tp->deleteObject(); - g_slist_free(tp_reprs); // set x/y on text (to be near where it was when on path) /* fixme: Yuck, is this really the right test? */ diff --git a/src/sp-use.cpp b/src/sp-use.cpp index abb59d299..fae442cfa 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -356,22 +356,21 @@ Geom::Affine SPUse::get_root_transform() { //track the ultimate source of a chain of uses SPObject *orig = this->child; - GSList *chain = NULL; - chain = g_slist_prepend(chain, this); + std::vector<SPItem*> chain; + chain.push_back(this); while (dynamic_cast<SPUse *>(orig)) { - chain = g_slist_prepend(chain, orig); + chain.push_back(dynamic_cast<SPItem *>(orig)); orig = dynamic_cast<SPUse *>(orig)->child; } - chain = g_slist_prepend(chain, orig); - + chain.push_back(dynamic_cast<SPItem *>(orig)); // calculate the accummulated transform, starting from the original Geom::Affine t(Geom::identity()); - for (GSList *i = chain; i != NULL; i = i->next) { - SPItem *i_tem = reinterpret_cast<SPItem *>(i->data); + for (auto i=chain.rbegin(); i!=chain.rend(); ++i) { + SPItem *i_tem = *i; // "An additional transformation translate(x,y) is appended to the end (i.e., // right-side) of the transform attribute on the generated 'g', where x and y @@ -385,8 +384,6 @@ Geom::Affine SPUse::get_root_transform() { t *= i_tem->transform; } - - g_slist_free(chain); return t; } diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 95d940bd6..966183b1a 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -219,7 +219,7 @@ sp_gradient_context_is_over_line (GradientTool *rc, SPItem *item, Geom::Point ev } static std::vector<Geom::Point> -sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSList **next_stops) +sp_gradient_context_get_stop_intervals (GrDrag *drag, std::vector<SPStop *> &these_stops, std::vector<SPStop *> &next_stops) { std::vector<Geom::Point> coords; @@ -285,15 +285,15 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi } // if both adjacent draggers selected, - if (!g_slist_find(*these_stops, this_stop) && dnext && dnext->isSelected()) { + if ((std::find(these_stops.begin(),these_stops.end(),this_stop)==these_stops.end()) && dnext && dnext->isSelected()) { // remember the coords of the future dragger to select it coords.push_back(0.5*(dragger->point + dnext->point)); // do not insert a stop now, it will confuse the loop; // just remember the stops - *these_stops = g_slist_prepend (*these_stops, this_stop); - *next_stops = g_slist_prepend (*next_stops, next_stop); + these_stops.push_back(this_stop); + next_stops.push_back(next_stop); } } } @@ -307,12 +307,12 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) SPDocument *doc = NULL; GrDrag *drag = rc->_grdrag; - GSList *these_stops = NULL; - GSList *next_stops = NULL; + std::vector<SPStop *> these_stops; + std::vector<SPStop *> next_stops; - std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops); + std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, these_stops, next_stops); - if (g_slist_length(these_stops) == 0 && drag->numSelected() == 1) { + if (these_stops.empty() && drag->numSelected() == 1) { // if a single stop is selected, add between that stop and the next one GrDragger *dragger = *(drag->selected.begin()); for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end(); ++j) { @@ -330,47 +330,42 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) if (this_stop) { SPStop *next_stop = this_stop->getNextStop(); if (next_stop) { - these_stops = g_slist_prepend (these_stops, this_stop); - next_stops = g_slist_prepend (next_stops, next_stop); + these_stops.push_back(this_stop); + next_stops.push_back(next_stop); } } } } // now actually create the new stops - GSList *i = these_stops; - GSList *j = next_stops; - GSList *new_stops = NULL; + auto i = these_stops.rbegin(); + auto j = next_stops.rbegin(); + std::vector<SPStop *> new_stops; - for (; i != NULL && j != NULL; i = i->next, j = j->next) { - SPStop *this_stop = (SPStop *) i->data; - SPStop *next_stop = (SPStop *) j->data; + for (;i != these_stops.rend() && j != next_stops.rend(); ++i, ++j ) { + SPStop *this_stop = *i; + SPStop *next_stop = *j; gfloat offset = 0.5*(this_stop->offset + next_stop->offset); SPObject *parent = this_stop->parent; if (SP_IS_GRADIENT (parent)) { doc = parent->document; SPStop *new_stop = sp_vector_add_stop (SP_GRADIENT (parent), this_stop, next_stop, offset); - new_stops = g_slist_prepend (new_stops, new_stop); + new_stops.push_back(new_stop); SP_GRADIENT(parent)->ensureVector(); } } - if (g_slist_length(these_stops) > 0 && doc) { + if (!these_stops.empty() && doc) { DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); drag->updateDraggers(); // so that it does not automatically update draggers in idle loop, as this would deselect drag->local_change = true; // select the newly created stops - for (GSList *s = new_stops; s != NULL; s = s->next) { - drag->selectByStop((SPStop *)s->data); + for (auto i:new_stops) { + drag->selectByStop(i); } - } - - g_slist_free (these_stops); - g_slist_free (next_stops); - g_slist_free (new_stops); } static double sqr(double x) {return x*x;} @@ -381,26 +376,25 @@ sp_gradient_simplify(GradientTool *rc, double tolerance) SPDocument *doc = NULL; GrDrag *drag = rc->_grdrag; - GSList *these_stops = NULL; - GSList *next_stops = NULL; + std::vector<SPStop *> these_stops; + std::vector<SPStop *> next_stops; - std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, &these_stops, &next_stops); + std::vector<Geom::Point> coords = sp_gradient_context_get_stop_intervals (drag, these_stops, next_stops); - GSList *todel = NULL; + std::set<SPStop *> todel; - GSList *i = these_stops; - GSList *j = next_stops; - for (; i != NULL && j != NULL; i = i->next, j = j->next) { - SPStop *stop0 = (SPStop *) i->data; - SPStop *stop1 = (SPStop *) j->data; + auto i = these_stops.begin(); + auto j = next_stops.end(); + for (; i != these_stops.end() && j != next_stops.end(); ++i, ++j) { + SPStop *stop0 = *i; + SPStop *stop1 = *j; - gint i1 = g_slist_index(these_stops, stop1); - if (i1 != -1) { - GSList *next_next = g_slist_nth (next_stops, i1); - if (next_next) { - SPStop *stop2 = (SPStop *) next_next->data; + auto i1 = std::find(these_stops.begin(), these_stops.end(), stop1); + if (i1 != these_stops.end()) { + if (next_stops.size()>(i1-these_stops.begin())) { + SPStop *stop2 = *(next_stops.begin() + (i1-these_stops.begin())); - if (g_slist_find(todel, stop0) || g_slist_find(todel, stop2)) + if (todel.find(stop0)!=todel.end() || todel.find(stop2) != todel.end()) continue; guint32 const c0 = stop0->get_rgba32(); @@ -416,28 +410,23 @@ sp_gradient_simplify(GradientTool *rc, double tolerance) sqr(SP_RGBA32_A_F(c1) - SP_RGBA32_A_F(c1r)); if (diff < tolerance) - todel = g_slist_prepend (todel, stop1); + todel.insert(stop1); } } } - for (i = todel; i != NULL; i = i->next) { - SPStop *stop = (SPStop*) i->data; + for (auto stop : todel) { doc = stop->document; Inkscape::XML::Node * parent = stop->getRepr()->parent(); parent->removeChild( stop->getRepr() ); } - if (g_slist_length(todel) > 0) { + if (!todel.empty()) { DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Simplify gradient")); drag->local_change = true; drag->updateDraggers(); drag->selectByCoords(coords); } - - g_slist_free (todel); - g_slist_free (these_stops); - g_slist_free (next_stops); } diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index d79741270..1ded5e146 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -170,68 +170,6 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { // FIXME // We need to update mesh gradient handles. // Get gradient this drag belongs too.. - // std::cout << "mesh_selection_changed: selection: objects: " << n_obj << std::endl; - // GSList *itemList = (GSList *) selection->itemList(); - // while( itemList ) { - - // SPItem *item = SP_ITEM( itemList->data ); - // // std::cout << " item: " << SP_OBJECT(item)->getId() << std::endl; - - // SPStyle *style = item->style; - // if (style && (style->fill.isPaintserver())) { - - // SPPaintServer *server = item->style->getFillPaintServer(); - // if ( SP_IS_MESHGRADIENT(server) ) { - - // SPMeshGradient *mg = SP_MESHGRADIENT(server); - - // guint rows = 0;//mg->array.patches.size(); - // for ( guint i = 0; i < rows; ++i ) { - // guint columns = 0;//mg->array.patches[0].size(); - // for ( guint j = 0; j < columns; ++j ) { - // } - // } - // } - // } - // itemList = itemList->next; - // } - - // GList* dragger_ptr = drag->draggers; // Points to GrDragger class (group of GrDraggable) - // guint count = 0; - // while( dragger_ptr ) { - - // std::cout << "mesh_selection_changed: dragger: " << ++count << std::endl; - // GSList* draggable_ptr = ((GrDragger *) dragger_ptr->data)->draggables; - - // while( draggable_ptr ) { - - // std::cout << "mesh_selection_changed: draggable: " << draggable_ptr << std::endl; - // GrDraggable *draggable = (GrDraggable *) draggable_ptr->data; - - // gint point_type = draggable->point_type; - // gint point_i = draggable->point_i; - // bool fill_or_stroke = draggable->fill_or_stroke; - - // if( point_type == POINT_MG_CORNER ) { - - // //std::cout << "mesh_selection_changed: POINT_MG_CORNER: " << point_i << std::endl; - // // Now we must create or destroy corresponding handles. - - // if( g_list_find( drag->selected, dragger_ptr->data ) ) { - // //std::cout << "gradient_selection_changed: Selected: " << point_i << std::endl; - // // Which meshes does this point belong to? - - // } else { - // //std::cout << "mesh_selection_changed: Not Selected: " << point_i << std::endl; - // } - // } - - // draggable_ptr = draggable_ptr->next; - - // } - - // dragger_ptr = dragger_ptr->next; - // } } void MeshTool::setup() { diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index dcd9413fb..fca96a483 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -374,23 +374,20 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P } if (dynamic_cast<SPGroup *>(item) && !dynamic_cast<SPBox3D *>(item)) { - GSList *children = NULL; + std::vector<SPItem *> children; for (auto& child: item->children) { - if (dynamic_cast<SPItem *>(static_cast<SPObject *>(&child))) { - children = g_slist_prepend(children, &child); + if (dynamic_cast<SPItem *>(&child)) { + children.push_back(dynamic_cast<SPItem *>(&child)); } } - for (GSList *i = children; i; i = i->next) { - SPItem *child = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); + for (auto i = children.rbegin(); i!= children.rend(); ++i) { + SPItem *child = *i; g_assert(child != NULL); if (sp_tweak_dilate_recursive (selection, child, p, vector, mode, radius, force, fidelity, reverse)) { did = true; } } - - g_slist_free(children); - } else { if (mode == TWEAK_MODE_MOVE) { |
