From a67e8630caf20e7f48151024e9e68dd9271d75c7 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 1 Jul 2022 18:07:03 +0200 Subject: 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` instance. Also fix a bug in `options/tie.hpp` where `QComboBox::setCurrentIndex` was erroneously called as `Qt::DirectConnection`. --- options/tie.hpp | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'options/tie.hpp') 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> tie_setting(value& v, QComboBox* cb) cb->setCurrentIndex(cb->findData(int(static_cast(v)))); v = static_cast(cb->currentData().toInt()); - value_::connect(cb, static_cast(&QComboBox::currentIndexChanged), - &v, [&v, cb](int idx) { v = static_cast(cb->itemData(idx).toInt()); }, - v.DIRECT_CONNTYPE); - - value_::connect(&v, value_::value_changed(), - cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }, - v.SAFE_CONNTYPE); + v.connect_from(cb, static_cast(&QComboBox::currentIndexChanged), + [&v, cb](int idx) { v = static_cast(cb->itemData(idx).toInt()); }); + v.connect_to(cb, [cb](int x) { cb->setCurrentIndex(cb->findData(x)); }); } template @@ -52,23 +48,20 @@ void tie_setting(value& 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(&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(), - cb, [cb, fn_to_index](detail::cv_qualified& v) { cb->setCurrentIndex(fn_to_index(v)); }, - v.DIRECT_CONNTYPE); + v.connect_from(cb, static_cast(&QComboBox::currentIndexChanged), + [&v, cb, fn = std::forward(fn_to_value)](int idx) { v = fn(idx, cb->currentData()); }); + v.connect_to(cb, [cb, fn = std::forward(fn_to_index)](detail::cv_qualified v) { cb->setCurrentIndex(fn(v)); }); } template void tie_setting(value& v, QLabel* lb, F&& fun) { - auto closure = [lb, fun](detail::cv_qualified v) { lb->setText(fun(v)); }; + auto closure = [lb, fn = std::forward(fun)](detail::cv_qualified v) { + lb->setText(fn(v)); + }; closure(v()); - value_::connect(&v, value_::value_changed(), - lb, closure, - v.SAFE_CONNTYPE); + v.connect_to(lb, std::move(closure)); } template @@ -78,10 +71,7 @@ void tie_setting(value& v, QObject* obj, F&& fun) abort(); fun(v()); - - value_::connect(&v, value_::value_changed(), - obj, fun, - v.DIRECT_CONNTYPE); + v.connect_to(obj, std::forward(fun)); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); -- cgit v1.2.3