From 9a0822c445e56580fb3034224191ec825ea0274a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 13 Oct 2017 15:05:05 +0200 Subject: options/tie: change "tie" overloads Adjust usages. There are ODR issues with MSVC and it doesn't support C++17 "static inline constexpr" _variables_. Otherwise, "signal_fun" could be a variable and not a function. The usages in accela/ewma2 dialog are more verbose now but the original API was silly. --- options/base-value.hpp | 14 ++++++++++++++ options/tie.cpp | 16 ++++++++-------- options/tie.hpp | 27 ++++----------------------- 3 files changed, 26 insertions(+), 31 deletions(-) (limited to 'options') diff --git a/options/base-value.hpp b/options/base-value.hpp index 4f90e3fc..5106908d 100644 --- a/options/base-value.hpp +++ b/options/base-value.hpp @@ -22,13 +22,25 @@ namespace options { class OTR_OPTIONS_EXPORT base_value : public QObject { Q_OBJECT + friend class detail::connector; using comparator = bool(*)(const QVariant& val1, const QVariant& val2); + template + using signal_sig = void(base_value::*)(cv_qualified) const; public: QString name() const { return self_name; } base_value(bundle b, const QString& name, comparator cmp, std::type_index type_idx); ~base_value() override; + + // MSVC has ODR problems in 15.4 + // no C++17 "constexpr inline" for data declarations in MSVC + template + constexpr static auto signal_fun() + { + return static_cast>(&base_value::valueChanged); + } + signals: OPENTRACK_DEFINE_SIGNAL(double); OPENTRACK_DEFINE_SIGNAL(float); @@ -80,6 +92,8 @@ public slots: virtual void reload() = 0; virtual void bundle_value_changed() const = 0; virtual void set_to_default() = 0; + + friend void ::options::detail::set_base_value_to_default(base_value* val); }; } //ns options diff --git a/options/tie.cpp b/options/tie.cpp index 3cb32319..162a0f56 100644 --- a/options/tie.cpp +++ b/options/tie.cpp @@ -22,8 +22,8 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb) { cb->setCurrentText(v); v = cb->currentText(); - base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.SAFE_CONNTYPE); + base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(const QString&)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(const QString&)), cb, SLOT(setCurrentText(const QString&)), v.SAFE_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb) @@ -55,7 +55,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb) &v, [cb, &v](int idx) { v = cb->itemData(idx); }, v.DIRECT_CONNTYPE); - base_value::connect(&v, static_cast(&base_value::valueChanged), + base_value::connect(&v, base_value::signal_fun(), cb, [cb, set_idx](const QVariant& var) { run_in_thread_sync(cb, [&]() { @@ -91,21 +91,21 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* sl) { sl->setValue(v); v = sl->value(); - base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.SAFE_CONNTYPE); + base_value::connect(sl, &QSlider::valueChanged, &v, base_value::signal_fun(), v.DIRECT_CONNTYPE); + base_value::connect(&v, base_value::signal_fun(), sl, &QSlider::setValue, v.SAFE_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QLineEdit* le) { le->setText(v); base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.SAFE_CONNTYPE); + base_value::connect(&v, base_value::signal_fun(), le, &QLineEdit::setText, v.SAFE_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QLabel* lb) { lb->setText(v); - base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.SAFE_CONNTYPE); + base_value::connect(&v, base_value::signal_fun(), lb, &QLabel::setText, v.SAFE_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QTabWidget* t) @@ -141,7 +141,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* w) v.DIRECT_CONNTYPE); base_value::connect(&v, - static_cast(&base_value::valueChanged), + base_value::signal_fun(), w, [=, &v](double) { run_in_thread_sync(w, [=, &v]() diff --git a/options/tie.hpp b/options/tie.hpp index 92e98680..0a4ace74 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -52,36 +52,17 @@ tie_setting(value& v, QComboBox* cb) v.SAFE_CONNTYPE); } -template -void tie_setting(value& v, QLabel* lb, const QString& format, const xs&... args) +template +void tie_setting(value& v, QLabel* lb, F&& fun) { - auto closure = [=](const t& x) { lb->setText(format.arg(x, args...)); }; + auto closure = [=](cv_qualified x) { lb->setText(fun(x)); }; closure(v()); - base_value::connect(&v, static_cast(&base_value::valueChanged), + base_value::connect(&v, base_value::signal_fun(), lb, closure, v.SAFE_CONNTYPE); } -template -decltype((void)((std::declval())(std::declval()))) -tie_setting(value& v, QLabel* lb, F&& fun, const QString& fmt, const xs&... args) -{ - auto closure = [=](const t& x) { lb->setText(fmt.arg(fun(x), args...)); }; - - closure(v()); - base_value::connect(&v, static_cast(&base_value::valueChanged), - lb, closure, - v.SAFE_CONNTYPE); -} - -template -decltype((void)((std::declval())(std::declval()))) -tie_setting(value& v, QLabel* lb, F&& fun) -{ - tie_setting(v, lb, fun, QStringLiteral("%1")); -} - OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); -- cgit v1.2.3