diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/bundle.cpp | 4 | ||||
-rw-r--r-- | options/bundle.hpp | 6 | ||||
-rw-r--r-- | options/options.hpp | 4 | ||||
-rw-r--r-- | options/tie.hpp | 66 | ||||
-rw-r--r-- | options/value.hpp | 23 |
5 files changed, 49 insertions, 54 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp index 96291476..74e08eb9 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -199,12 +199,12 @@ OPENTRACK_OPTIONS_EXPORT bundler& singleton() } // end options::detail -OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name) +OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name) { if (name.size()) return detail::singleton().make_bundle(name); else - return std::make_shared<bundle_type>(QStringLiteral("")); + return std::make_shared<bundle_>(QStringLiteral("")); } QMutex* options::detail::bundle::get_mtx() const { return mtx; } diff --git a/options/bundle.hpp b/options/bundle.hpp index 2d7fa7f4..5bbe6f60 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -103,9 +103,9 @@ public: OPENTRACK_OPTIONS_EXPORT bundler& singleton(); } -using bundle_type = detail::bundle; -using bundle = std::shared_ptr<bundle_type>; +using bundle_ = detail::bundle; +using bundle = std::shared_ptr<bundle_>; -OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name); +OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name); } diff --git a/options/options.hpp b/options/options.hpp index ebc480f3..c1eed97c 100644 --- a/options/options.hpp +++ b/options/options.hpp @@ -6,6 +6,10 @@ */ #pragma once +#include "compat/ndebug-guard.hpp" + +#include "compat/util.hpp" + #include "defs.hpp" #include "bundle.hpp" #include "group.hpp" diff --git a/options/tie.hpp b/options/tie.hpp index accd958e..942c6098 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -31,40 +31,23 @@ inline typename std::enable_if<std::is_enum<t>::value>::type tie_setting(value<t>& v, QComboBox* cb) { - cb->setCurrentIndex(cb->findData((unsigned)static_cast<t>(v))); + cb->setCurrentIndex(cb->findData(int(static_cast<t>(v)))); v = static_cast<t>(cb->currentData().toInt()); - std::vector<int> enum_cases(unsigned(cb->count())); - - for (int i = 0; i < cb->count(); i++) - enum_cases[i] = cb->itemData(i).toInt(); - base_value::connect(cb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), &v, - [&, enum_cases](int idx) { - if (idx < 0 || idx >= (int)enum_cases.size()) - v = static_cast<t>(-1); - else - v = static_cast<t>(enum_cases[idx]); + [&v, cb](int idx) + { + run_in_thread_sync(cb, + [&]() { + v = static_cast<t>(cb->itemData(idx).toInt()); + }); }, v.DIRECT_CONNTYPE); - base_value::connect(&v, - static_cast<void (base_value::*)(int) const>(&base_value::valueChanged), - cb, - [&, enum_cases](int val) { - for (unsigned i = 0; i < enum_cases.size(); i++) - { - if (val == enum_cases[i]) - { - cb->setCurrentIndex(i); - return; - } - } - cb->setCurrentIndex(-1); - }, - // don't change or else hatire crashes -sh 20160917 - Qt::QueuedConnection); + base_value::connect(&v, static_cast<void (base_value::*)(int) const>(&base_value::valueChanged), + cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }, + v.SAFE_CONNTYPE); } template<> @@ -144,27 +127,36 @@ inline void tie_setting(value<int>& v, QTabWidget* t) template<> inline void tie_setting(value<slider_value>& v, QSlider* w) { - // we can't get these at runtime since signals cross threads - const int q_min = w->minimum(); - const int q_max = w->maximum(); + { + const int q_min = w->minimum(); + const int q_max = w->maximum(); - w->setValue(v->to_slider_pos(q_min, q_max)); - v = v->update_from_slider(w->value(), q_min, q_max); + w->setValue(v().to_slider_pos(q_min, q_max)); + v = v().update_from_slider(w->value(), q_min, q_max); + } base_value::connect(w, &QSlider::valueChanged, &v, - [=, &v](int pos) { - v = v->update_from_slider(pos, q_min, q_max); - w->setValue(v->to_slider_pos(q_min, q_max)); + [=, &v](int pos) + { + run_in_thread_sync(w, [&]() + { + const int q_min = w->minimum(); + const int q_max = w->maximum(); + v = v().update_from_slider(pos, q_min, q_max); + w->setValue(v().to_slider_pos(q_min, q_max)); + }); }, v.DIRECT_CONNTYPE); base_value::connect(&v, static_cast<void(base_value::*)(double) const>(&base_value::valueChanged), w, [=, &v](double) { - w->setValue(v->to_slider_pos(q_min, q_max)); - v = v->update_from_slider(w->value(), q_min, q_max); + const int q_min = w->minimum(); + const int q_max = w->maximum(); + w->setValue(v().to_slider_pos(q_min, q_max)); + v = v().update_from_slider(w->value(), q_min, q_max); }, v.SAFE_CONNTYPE); } diff --git a/options/value.hpp b/options/value.hpp index 3c45bf15..01746d67 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -166,14 +166,6 @@ public: { } - t get() const - { - t val = b->contains(self_name) - ? static_cast<t>(b->get<element_type>(self_name)) - : def; - return detail::value_get_traits<t>::get(val, def); - } - t default_value() const { return def; @@ -191,13 +183,20 @@ public: emit valueChanged(static_cast<detail::value_type_t<t>>(get())); } - element_type const* operator->() const + element_type operator()() const { - static thread_local element_type last; - last = get(); - return &last; + return get(); } + private: + t get() const + { + t val = b->contains(self_name) + ? static_cast<t>(b->get<element_type>(self_name)) + : def; + return detail::value_get_traits<t>::get(val, def); + } + const t def; }; |