From 5d554656d7f2392a0c98a4474641f997c7b47543 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 3 Feb 2019 15:13:24 +0100 Subject: options, opentrack: fix migrations with tie_setting Migrations only ran after `tie_setting()' handlers were done, clobbering the settings that were about to be migrated. Applying QSignalBlocker to few comboboxes isn't enough as it affects everything touched by `tie_setting()'. Split reload and notify phases in the options system. --- options/bundle.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'options/bundle.cpp') diff --git a/options/bundle.cpp b/options/bundle.cpp index dc0f0fcf..a17b04fb 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -29,17 +29,21 @@ bundle::bundle(const QString& group_name) : bundle::~bundle() = default; -void bundle::reload() +void bundle::reload_no_notify() { if (group_name.isEmpty()) return; - { - QMutexLocker l{&mtx}; + QMutexLocker l{&mtx}; - saved = group(group_name); - transient = saved; + saved = group(group_name); + transient = saved; +} +void bundle::notify() +{ + { + QMutexLocker l(&mtx); connector::notify_all_values(); } @@ -47,6 +51,17 @@ void bundle::reload() emit changed(); } +void bundle::reload() +{ + { + QMutexLocker l{&mtx}; + reload_no_notify(); + connector::notify_all_values(); + } + emit reloading(); + emit changed(); +} + void bundle::set_all_to_default() { connector::set_all_to_default_(); @@ -96,7 +111,7 @@ void bundle::save() emit saving(); } -void bundler::after_profile_changed_() +void bundler::reload_no_notify_() { QMutexLocker l(&implsgl_mtx); @@ -107,16 +122,38 @@ void bundler::after_profile_changed_() if (bundle_) { //qDebug() << "bundle: reverting" << kv.first << "due to profile change"; - bundle_->reload(); + bundle_->reload_no_notify(); } } } -void bundler::refresh_all_bundles() +void bundler::notify_() { - bundler_singleton().after_profile_changed_(); + QMutexLocker l(&implsgl_mtx); + + for (auto& kv : implsgl_data) + { + weak bundle = kv.second; + shared bundle_ = bundle.lock(); + if (bundle_) + { + //qDebug() << "bundle: reverting" << kv.first << "due to profile change"; + bundle_->notify(); + } + } +} + +void bundler::reload_() +{ + QMutexLocker l(&implsgl_mtx); + notify_(); + reload_no_notify_(); } +void bundler::notify() { singleton().notify_(); } +void bundler::reload_no_notify() { singleton().reload_no_notify_(); } +void bundler::reload() { singleton().reload_(); } + bundler::bundler() = default; bundler::~bundler() = default; @@ -153,7 +190,7 @@ std::shared_ptr bundler::make_bundle_(const k& key) return shr; } -bundler& bundler::bundler_singleton() +bundler& bundler::singleton() { static bundler ret; return ret; @@ -166,7 +203,7 @@ namespace options { std::shared_ptr make_bundle(const QString& name) { if (!name.isEmpty()) - return detail::bundler::bundler_singleton().make_bundle_(name); + return detail::bundler::singleton().make_bundle_(name); else return std::make_shared(QString()); } -- cgit v1.2.3