diff options
Diffstat (limited to 'options/tie.hpp')
-rw-r--r-- | options/tie.hpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/options/tie.hpp b/options/tie.hpp index 81567139..46ade075 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -37,9 +37,13 @@ std::enable_if_t<std::is_enum_v<t>> tie_setting(value<t>& v, QComboBox* cb) cb->setCurrentIndex(cb->findData(int(static_cast<t>(v)))); v = static_cast<t>(cb->currentData().toInt()); - v.connect_from(cb, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - [&v, cb](int idx) { v = static_cast<t>(cb->itemData(idx).toInt()); }); - v.connect_to(cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }); + value_::connect(cb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + &v, [&v, cb](int idx) { v = static_cast<t>(cb->itemData(idx).toInt()); }, + v.DIRECT_CONNTYPE); + + value_::connect(&v, value_::value_changed<int>(), + cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }, + v.SAFE_CONNTYPE); } template<typename t, typename From, typename To> @@ -48,20 +52,23 @@ void tie_setting(value<t>& v, QComboBox* cb, From&& fn_to_index, To&& fn_to_valu cb->setCurrentIndex(fn_to_index(v)); v = fn_to_value(cb->currentIndex(), cb->currentData()); - v.connect_from(cb, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - [&v, cb, fn = std::forward<To>(fn_to_value)](int idx) { v = fn(idx, cb->currentData()); }); - v.connect_to(cb, [cb, fn = std::forward<From>(fn_to_index)](detail::cv_qualified<t> v) { cb->setCurrentIndex(fn(v)); }); + value_::connect(cb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + &v, [&v, cb, fn_to_value](int idx) { v = fn_to_value(idx, cb->currentData()); }, + v.DIRECT_CONNTYPE); + value_::connect(&v, value_::value_changed<t>(), + cb, [cb, fn_to_index](detail::cv_qualified<t>& v) { cb->setCurrentIndex(fn_to_index(v)); }, + v.DIRECT_CONNTYPE); } template<typename t, typename F> void tie_setting(value<t>& v, QLabel* lb, F&& fun) { - auto closure = [lb, fn = std::forward<F>(fun)](detail::cv_qualified<t> v) { - lb->setText(fn(v)); - }; + auto closure = [lb, fun](detail::cv_qualified<t> v) { lb->setText(fun(v)); }; closure(v()); - v.connect_to(lb, std::move(closure)); + value_::connect(&v, value_::value_changed<t>(), + lb, closure, + v.SAFE_CONNTYPE); } template<typename t, typename F> @@ -71,7 +78,10 @@ void tie_setting(value<t>& v, QObject* obj, F&& fun) abort(); fun(v()); - v.connect_to(obj, std::forward<F>(fun)); + + value_::connect(&v, value_::value_changed<t>(), + obj, fun, + v.DIRECT_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QComboBox* cb); |