diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-07-01 18:07:03 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-07-01 18:07:03 +0200 |
commit | a67e8630caf20e7f48151024e9e68dd9271d75c7 (patch) | |
tree | e7418eabdfb4abd6ca88c0ba6a427ca5a40e7c32 /options/tie.hpp | |
parent | 74dff816c07737b7e697e5d63222e59a9fefe23e (diff) |
options/value: add `QObject::connect` wrapper
This is useful not just to save on complexity in call sites, but also
because I plan on using the Verdigris library to remove needless
`valueChanged()` and `setValue()` overloads from each `value<t>`
instance.
Also fix a bug in `options/tie.hpp` where `QComboBox::setCurrentIndex`
was erroneously called as `Qt::DirectConnection`.
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); |