summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-11-29 05:40:09 +0100
committerStanislaw Halik <sthalik@misaki.pl>2016-11-29 05:42:22 +0100
commit2e2ca6629b8c78165772ceedccfb38002beb0431 (patch)
tree4b002b216c74456e5ef810ebd1e9e3859f342a1c /options
parente766ee9b110c81e334d2e3305df563d9cff3e604 (diff)
options/tie: simplify slider usage with run_in_thread_sync()
Diffstat (limited to 'options')
-rw-r--r--options/tie.hpp37
1 files changed, 10 insertions, 27 deletions
diff --git a/options/tie.hpp b/options/tie.hpp
index bdd992d8..fcb4d60f 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<>