From 9da6dff1800d6b6598e6ad04465ee8b9cabb4167 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 13 Oct 2017 18:53:28 +0200 Subject: tracker/pt, options: fix threshold slider It's only the tie_setting(slider_value, QSlider) that has race-free slider updates. Needed to update the threshold slider representation. Remove the tie_setting(int, QSlider) overload since it doesn't have the logic. Add a migration. Add base_value::notify() for use-cases like the checkbox updating the label. --- options/base-value.cpp | 5 +++++ options/base-value.hpp | 2 ++ options/slider.hpp | 4 ++++ options/tie.cpp | 8 -------- options/tie.hpp | 14 +++++++++++++- 5 files changed, 24 insertions(+), 9 deletions(-) (limited to 'options') diff --git a/options/base-value.cpp b/options/base-value.cpp index 29f4b496..a07886bb 100644 --- a/options/base-value.cpp +++ b/options/base-value.cpp @@ -16,6 +16,11 @@ base_value::~base_value() b->on_value_destructed(self_name, this); } +void base_value::notify() const +{ + bundle_value_changed(); +} + void base_value::store(const QVariant& datum) { b->store_kv(self_name, datum); diff --git a/options/base-value.hpp b/options/base-value.hpp index 5106908d..dfb22670 100644 --- a/options/base-value.hpp +++ b/options/base-value.hpp @@ -41,6 +41,8 @@ public: return static_cast>(&base_value::valueChanged); } + void notify() const; + signals: OPENTRACK_DEFINE_SIGNAL(double); OPENTRACK_DEFINE_SIGNAL(float); diff --git a/options/slider.hpp b/options/slider.hpp index bda1d398..da6bf214 100644 --- a/options/slider.hpp +++ b/options/slider.hpp @@ -8,6 +8,9 @@ #pragma once #include "export.hpp" + +#include "compat/util.hpp" + #include #include #include @@ -31,6 +34,7 @@ namespace options slider_value& operator=(const slider_value& v); bool operator==(const slider_value& v) const; operator double() const { return cur_; } + explicit operator int() const { return iround(cur_); } double cur() const { return cur_; } double min() const { return min_; } double max() const { return max_; } diff --git a/options/tie.cpp b/options/tie.cpp index 162a0f56..c0552d71 100644 --- a/options/tie.cpp +++ b/options/tie.cpp @@ -87,14 +87,6 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QSpinBox* sb) base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.SAFE_CONNTYPE); } -OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* sl) -{ - sl->setValue(v); - v = sl->value(); - 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); diff --git a/options/tie.hpp b/options/tie.hpp index 0a4ace74..b6bf32e9 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -63,13 +63,25 @@ void tie_setting(value& v, QLabel* lb, F&& fun) v.SAFE_CONNTYPE); } +template +void tie_setting(value& v, QObject* obj, F&& fun) +{ + if (obj == nullptr) + abort(); + + fun(v()); + + base_value::connect(&v, base_value::signal_fun(), + obj, fun, + v.DIRECT_CONNTYPE); +} + 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); OTR_OPTIONS_EXPORT void tie_setting(value& v, QCheckBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QDoubleSpinBox* dsb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QSpinBox* sb); -OTR_OPTIONS_EXPORT void tie_setting(value& v, QSlider* sl); OTR_OPTIONS_EXPORT void tie_setting(value& v, QLineEdit* le); OTR_OPTIONS_EXPORT void tie_setting(value& v, QLabel* lb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QTabWidget* t); -- cgit v1.2.3