From 60d9032701e657344bafda8895bf073e28bab5ae Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Wed, 5 Jul 2017 12:10:59 +0200 Subject: Clean up color profiles code This is a late 2nd part for 86a74b4a93ab62c8ef7819dc549fe7b3ace24916 and gets rid of the non-descriptive std::pair --- src/ui/dialog/document-properties.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/ui/dialog/document-properties.cpp') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 1b074bb0c..9dfae9a15 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -386,26 +386,25 @@ void DocumentProperties::populate_available_profiles(){ _AvailableProfilesListStore->clear(); // Clear any existing items in the combo box // Iterate through the list of profiles and add the name to the combo box. - std::vector, Glib::ustring> > pairs = ColorProfile::getProfileFilesWithNames(); bool home = true; // initial value doesn't matter, it's just to avoid a compiler warning - for ( std::vector, Glib::ustring> >::const_iterator it = pairs.begin(); it != pairs.end(); ++it ) { + bool first = true; + for (auto &profile: ColorProfile::getProfileFilesWithNames()) { Gtk::TreeModel::Row row; - Glib::ustring file = it->first.first; - Glib::ustring name = it->second; // add a separator between profiles from the user's home directory and system profiles - if (it != pairs.begin() && it->first.second != home) + if (!first && profile.isInHome != home) { row = *(_AvailableProfilesListStore->append()); row[_AvailableProfilesListColumns.fileColumn] = ""; row[_AvailableProfilesListColumns.nameColumn] = ""; row[_AvailableProfilesListColumns.separatorColumn] = true; } - home = it->first.second; + home = profile.isInHome; + first = false; row = *(_AvailableProfilesListStore->append()); - row[_AvailableProfilesListColumns.fileColumn] = file; - row[_AvailableProfilesListColumns.nameColumn] = name; + row[_AvailableProfilesListColumns.fileColumn] = profile.filename; + row[_AvailableProfilesListColumns.nameColumn] = profile.name; row[_AvailableProfilesListColumns.separatorColumn] = false; } } @@ -459,10 +458,11 @@ void DocumentProperties::linkSelectedProfile() g_warning("No color profile available."); return; } - + // Read the filename and description from the list of available profiles Glib::ustring file = (*iter)[_AvailableProfilesListColumns.fileColumn]; Glib::ustring name = (*iter)[_AvailableProfilesListColumns.nameColumn]; + std::vector current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); for (std::vector::const_iterator it = current.begin(); it != current.end(); ++it) { SPObject* obj = *it; @@ -521,12 +521,18 @@ void DocumentProperties::populate_linked_profiles_box() if (! current.empty()) { _emb_profiles_observer.set((*(current.begin()))->parent); } - std::set _current (current.begin(), current.end()); - for (std::set::const_iterator it = _current.begin(); it != _current.end(); ++it) { - SPObject* obj = *it; + + std::set _current; + std::set foo; + for (auto &profile: current) { + SPObject* obj = profile; Inkscape::ColorProfile* prof = reinterpret_cast(obj); + _current.insert(prof); + } + + for (auto &profile: _current) { Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append()); - row[_LinkedProfilesListColumns.nameColumn] = prof->name; + row[_LinkedProfilesListColumns.nameColumn] = profile->name; // row[_LinkedProfilesListColumns.previewColumn] = "Color Preview"; } } -- cgit v1.2.3 From 4f14bbfdaa090344772216ad3e89e19382a74a9c Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Wed, 5 Jul 2017 13:46:26 +0200 Subject: Use std::transform instead of a for loop --- src/ui/dialog/document-properties.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/ui/dialog/document-properties.cpp') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 9dfae9a15..0fff45762 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -514,6 +514,9 @@ struct _cmp { } }; +template +struct static_caster { To * operator () (From * value) const { return static_cast(value); } }; + void DocumentProperties::populate_linked_profiles_box() { _LinkedProfilesListStore->clear(); @@ -523,12 +526,10 @@ void DocumentProperties::populate_linked_profiles_box() } std::set _current; - std::set foo; - for (auto &profile: current) { - SPObject* obj = profile; - Inkscape::ColorProfile* prof = reinterpret_cast(obj); - _current.insert(prof); - } + std::transform(current.begin(), + current.end(), + std::inserter(_current, _current.begin()), + static_caster()); for (auto &profile: _current) { Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append()); -- cgit v1.2.3