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