diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2015-12-07 23:34:32 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2015-12-07 23:34:32 +0000 |
| commit | 93650897c928bfa9ca9b737cfbff55c25271d5d3 (patch) | |
| tree | 140edc7a4fdb7f1bc5944842a154681964243494 /src/ui/dialog | |
| parent | update to trunk (no conflict) (diff) | |
| download | inkscape-93650897c928bfa9ca9b737cfbff55c25271d5d3.tar.gz inkscape-93650897c928bfa9ca9b737cfbff55c25271d5d3.zip | |
cppification : GHashMaps replaced by stl maps. getResouceList now gives a std::set<SPObject *>.
Should give some performance improvements (quite a few linear lookups are now logarithmic)
(bzr r14504.1.6)
Diffstat (limited to 'src/ui/dialog')
| -rw-r--r-- | src/ui/dialog/document-properties.cpp | 64 | ||||
| -rw-r--r-- | src/ui/dialog/filter-effects-dialog.cpp | 7 | ||||
| -rw-r--r-- | src/ui/dialog/layers.cpp | 8 | ||||
| -rw-r--r-- | src/ui/dialog/svg-fonts-dialog.cpp | 6 | ||||
| -rw-r--r-- | src/ui/dialog/swatches.cpp | 27 |
5 files changed, 48 insertions, 64 deletions
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 5b63d14e1..8af744fd3 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -511,17 +511,16 @@ void DocumentProperties::linkSelectedProfile() void DocumentProperties::populate_linked_profiles_box() { _LinkedProfilesListStore->clear(); - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); - if (current) { - _emb_profiles_observer.set(SP_OBJECT(current->data)->parent); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); + if (! current.empty()) { + _emb_profiles_observer.set((*(current.begin()))->parent); } - while ( current ) { - SPObject* obj = SP_OBJECT(current->data); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj); Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append()); row[_LinkedProfilesListColumns.nameColumn] = prof->name; // row[_LinkedProfilesListColumns.previewColumn] = "Color Preview"; - current = g_slist_next(current); } } @@ -594,10 +593,9 @@ void DocumentProperties::removeSelectedProfile(){ return; } } - - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); - while ( current ) { - SPObject* obj = SP_OBJECT(current->data); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj); if (!name.compare(prof->name)){ @@ -606,7 +604,6 @@ void DocumentProperties::removeSelectedProfile(){ DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile")); break; // removing the color profile likely invalidates part of the traversed list, stop traversing here. } - current = g_slist_next(current); } populate_linked_profiles_box(); @@ -722,9 +719,9 @@ void DocumentProperties::build_cms() _LinkedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::linked_profiles_list_button_release)); cms_create_popup_menu(_LinkedProfilesList, sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile)); - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "defs" ); - if (current) { - _emb_profiles_observer.set(SP_OBJECT(current->data)->parent); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "defs" ); + if (!current.empty()) { + _emb_profiles_observer.set((*(current.begin()))->parent); } _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_linked_profiles_box)); onColorProfileSelectRow(); @@ -959,9 +956,9 @@ void DocumentProperties::build_scripting() #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) //TODO: review this observers code: - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); - if (current) { - _scripts_observer.set(SP_OBJECT(current->data)->parent); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); + if (! current.empty()) { + _scripts_observer.set((*(current.begin()))->parent); } _scripts_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_script_lists)); onEmbeddedScriptSelectRow(); @@ -1174,9 +1171,9 @@ void DocumentProperties::removeExternalScript(){ } } - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); - while ( current ) { - SPObject* obj = reinterpret_cast<SPObject *>(current->data); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; if (obj) { SPScript* script = dynamic_cast<SPScript *>(obj); if (script && (name == script->xlinkhref)) { @@ -1191,7 +1188,6 @@ void DocumentProperties::removeExternalScript(){ } } } - current = g_slist_next(current); } populate_script_lists(); @@ -1253,9 +1249,9 @@ void DocumentProperties::changeEmbeddedScript(){ } bool voidscript=true; - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); - while ( current ) { - SPObject* obj = SP_OBJECT(current->data); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; if (id == obj->getId()){ int count=0; @@ -1279,7 +1275,6 @@ void DocumentProperties::changeEmbeddedScript(){ } } } - current = g_slist_next(current); } if (voidscript) @@ -1299,9 +1294,9 @@ void DocumentProperties::editEmbeddedScript(){ } Inkscape::XML::Document *xml_doc = SP_ACTIVE_DOCUMENT->getReprDoc(); - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); - while ( current ) { - SPObject* obj = SP_OBJECT(current->data); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; if (id == obj->getId()){ //XML Tree being used directly here while it shouldn't be. @@ -1317,21 +1312,20 @@ void DocumentProperties::editEmbeddedScript(){ DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_EMBEDDED_SCRIPT, _("Edit embedded script")); } } - current = g_slist_next(current); } } void DocumentProperties::populate_script_lists(){ _ExternalScriptsListStore->clear(); _EmbeddedScriptsListStore->clear(); - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); - if (current) { - SPObject *obj = reinterpret_cast<SPObject *>(current->data); + std::set<SPObject *> current = SP_ACTIVE_DOCUMENT->getResourceList( "script" ); + if (!current.empty()) { + SPObject *obj = *(current.begin()); g_assert(obj != NULL); _scripts_observer.set(obj->parent); } - while ( current ) { - SPObject* obj = reinterpret_cast<SPObject *>(current->data); + for (std::set<SPObject *>::const_iterator it = current.begin(); it != current.end(); ++it) { + SPObject* obj = *it; SPScript* script = dynamic_cast<SPScript *>(obj); g_assert(script != NULL); if (script->xlinkhref) @@ -1344,8 +1338,6 @@ void DocumentProperties::populate_script_lists(){ Gtk::TreeModel::Row row = *(_EmbeddedScriptsListStore->append()); row[_EmbeddedScriptsListColumns.idColumn] = obj->getId(); } - - current = g_slist_next(current); } } diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 08a58291d..e3196bf59 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1589,13 +1589,14 @@ void FilterEffectsDialog::FilterModifier::update_filters() { SPDesktop* desktop = _dialog.getDesktop(); SPDocument* document = desktop->getDocument(); - const GSList* filters = document->getResourceList("filter"); + + std::set<SPObject *> filters = document->getResourceList( "filter" ); _model->clear(); - for(const GSList *l = filters; l; l = l->next) { + for (std::set<SPObject *>::const_iterator it = filters.begin(); it != filters.end(); ++it) { Gtk::TreeModel::Row row = *_model->append(); - SPFilter* f = SP_FILTER(l->data); + SPFilter* f = SP_FILTER(*it); row[_columns.filter] = f; const gchar* lbl = f->label(); const gchar* id = f->getId(); diff --git a/src/ui/dialog/layers.cpp b/src/ui/dialog/layers.cpp index 3f5e80f8d..f4152e556 100644 --- a/src/ui/dialog/layers.cpp +++ b/src/ui/dialog/layers.cpp @@ -1040,14 +1040,6 @@ void LayersPanel::setDesktop( SPDesktop* desktop ) _layersChanged(); } } -/* - GSList const *layers = _desktop->doc()->getResourceList( "layer" ); - g_message( "layers list starts at %p", layers ); - for ( GSList const *iter=layers ; iter ; iter = iter->next ) { - SPObject *layer=static_cast<SPObject *>(iter->data); - g_message(" {%s} [%s]", layer->id, layer->label() ); - } -*/ deskTrack.setBase(desktop); } diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 12b423602..46e045c14 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -266,12 +266,12 @@ void SvgFontsDialog::update_fonts() { SPDesktop* desktop = this->getDesktop(); SPDocument* document = desktop->getDocument(); - const GSList* fonts = document->getResourceList("font"); + std::set<SPObject *> fonts = document->getResourceList( "fonts" ); _model->clear(); - for(const GSList *l = fonts; l; l = l->next) { + for (std::set<SPObject *>::const_iterator it = fonts.begin(); it != fonts.end(); ++it) { Gtk::TreeModel::Row row = *_model->append(); - SPFont* f = SP_FONT(l->data); + SPFont* f = SP_FONT(*it); row[_columns.spfont] = f; row[_columns.svgfont] = new SvgFont(f); const gchar* lbl = f->label(); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 72677c07e..ed1cd2079 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -171,9 +171,9 @@ static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) SPDocument *doc = desktop ? desktop->doc() : 0; if (doc) { std::string targetName(bounceTarget->def.descr); - const GSList *gradients = doc->getResourceList("gradient"); - for (const GSList *item = gradients; item; item = item->next) { - SPGradient* grad = SP_GRADIENT(item->data); + std::set<SPObject *> gradients = doc->getResourceList("gradient"); + for (std::set<SPObject *>::const_iterator item = gradients.begin(); item != gradients.end(); ++item) { + SPGradient* grad = SP_GRADIENT(*item); if ( targetName == grad->getId() ) { editGradientImpl( desktop, grad ); break; @@ -192,10 +192,10 @@ void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer us gint index = GPOINTER_TO_INT(userData); if ( doc && (index >= 0) && (static_cast<guint>(index) < popupItems.size()) ) { Glib::ustring targetName = popupItems[index]; + std::set<SPObject *> gradients = doc->getResourceList("gradient"); + for (std::set<SPObject *>::const_iterator item = gradients.begin(); item != gradients.end(); ++item) { + SPGradient* grad = SP_GRADIENT(*item); - const GSList *gradients = doc->getResourceList("gradient"); - for (const GSList *item = gradients; item; item = item->next) { - SPGradient* grad = SP_GRADIENT(item->data); if ( targetName == grad->getId() ) { grad->setSwatch(); DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, @@ -326,10 +326,10 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(wdgt); if ( dtw && dtw->desktop ) { // Pick up all gradients with vectors - const GSList *gradients = (dtw->desktop->doc())->getResourceList("gradient"); + std::set<SPObject *> gradients = (dtw->desktop->doc())->getResourceList("gradient"); gint index = 0; - for (const GSList *curr = gradients; curr; curr = curr->next) { - SPGradient* grad = SP_GRADIENT(curr->data); + for (std::set<SPObject *>::const_iterator item = gradients.begin(); item != gradients.end(); ++item) { + SPGradient* grad = SP_GRADIENT(*item); if ( grad->hasStops() && !grad->isSwatch() ) { //gl = g_slist_prepend(gl, curr->data); processed = true; @@ -923,12 +923,11 @@ static void recalcSwatchContents(SPDocument* doc, std::map<ColorItem*, SPGradient*> &gradMappings) { std::vector<SPGradient*> newList; - - const GSList *gradients = doc->getResourceList("gradient"); - for (const GSList *item = gradients; item; item = item->next) { - SPGradient* grad = SP_GRADIENT(item->data); + std::set<SPObject *> gradients = doc->getResourceList("gradient"); + for (std::set<SPObject *>::const_iterator item = gradients.begin(); item != gradients.end(); ++item) { + SPGradient* grad = SP_GRADIENT(*item); if ( grad->isSwatch() ) { - newList.push_back(SP_GRADIENT(item->data)); + newList.push_back(SP_GRADIENT(*item)); } } |
