From 2e2ca6629b8c78165772ceedccfb38002beb0431 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 29 Nov 2016 05:40:09 +0100 Subject: options/tie: simplify slider usage with run_in_thread_sync() --- options/tie.hpp | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'options/tie.hpp') 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::value>::type tie_setting(value& v, QComboBox* cb) { - cb->setCurrentIndex(cb->findData((unsigned)static_cast(v))); + cb->setCurrentIndex(cb->findData(int(static_cast(v)))); v = static_cast(cb->currentData().toInt()); - std::vector 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(&QComboBox::currentIndexChanged), &v, - [&, enum_cases](int idx) { - if (idx < 0 || idx >= (int)enum_cases.size()) - v = static_cast(-1); - else - v = static_cast(enum_cases[idx]); + [&v, cb](int idx) + { + run_in_thread_sync(cb, + [&]() { + v = static_cast(cb->itemData(idx).toInt()); + }); }, v.DIRECT_CONNTYPE); - base_value::connect(&v, - static_cast(&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(&base_value::valueChanged), + cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }, + v.SAFE_CONNTYPE); } template<> -- cgit v1.2.3