X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fglobalsettings.cpp;h=1a589fe9cf0459b986d88f2b5dfaa3398a1ba710;hp=c9a757c9ebb238b3b8a7d1ff4cc4d6487fb56fa6;hb=d0c0573b3ee694827a747727f862c5f91736ca05;hpb=451dc5f33fbc4f559881acdf338c476a976fcbf2 diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index c9a757c..1a589fe 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -20,13 +20,11 @@ #include "globalsettings.hpp" #include -#include #include #include -using std::function; using std::map; -using std::multimap; +using std::vector; namespace pv { @@ -42,7 +40,7 @@ const QString GlobalSettings::Key_View_DefaultDivHeight = "View_DefaultDivHeight const QString GlobalSettings::Key_View_DefaultLogicHeight = "View_DefaultLogicHeight"; const QString GlobalSettings::Key_Dec_InitialStateConfigurable = "Dec_InitialStateConfigurable"; -multimap< QString, function > GlobalSettings::callbacks_; +vector GlobalSettings::callbacks_; bool GlobalSettings::tracking_ = false; map GlobalSettings::tracked_changes_; @@ -75,10 +73,18 @@ void GlobalSettings::set_defaults_where_needed() 2 * QFontMetrics(QApplication::font()).height()); } -void GlobalSettings::register_change_handler(const QString key, - function cb) +void GlobalSettings::add_change_handler(GlobalSettingsInterface *cb) { - callbacks_.emplace(key, cb); + callbacks_.push_back(cb); +} + +void GlobalSettings::remove_change_handler(GlobalSettingsInterface *cb) +{ + for (auto cb_it = callbacks_.begin(); cb_it != callbacks_.end(); cb_it++) + if (*cb_it == cb) { + callbacks_.erase(cb_it); + break; + } } void GlobalSettings::setValue(const QString &key, const QVariant &value) @@ -90,11 +96,9 @@ void GlobalSettings::setValue(const QString &key, const QVariant &value) QSettings::setValue(key, value); - // Call all registered callbacks for this key - auto range = callbacks_.equal_range(key); - - for (auto it = range.first; it != range.second; it++) - it->second(value); + // Call all registered callbacks + for (GlobalSettingsInterface *cb : callbacks_) + cb->on_setting_changed(key, value); } void GlobalSettings::start_tracking()