summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
Diffstat (limited to 'options')
-rw-r--r--options/base-value.cpp7
-rw-r--r--options/slider.cpp45
-rw-r--r--options/slider.hpp36
-rw-r--r--options/tie.hpp4
4 files changed, 31 insertions, 61 deletions
diff --git a/options/base-value.cpp b/options/base-value.cpp
index d900ad0f..bcbbd1dc 100644
--- a/options/base-value.cpp
+++ b/options/base-value.cpp
@@ -2,7 +2,7 @@
using namespace options;
-value_::value_(bundle b, const QString& name, value_::comparator cmp, std::type_index type_idx) :
+value_::value_(bundle const& b, const QString& name, value_::comparator cmp, std::type_index type_idx) :
b(b),
self_name(name),
cmp(cmp),
@@ -21,11 +21,6 @@ void value_::notify() const
bundle_value_changed();
}
-void value_::store(const QVariant& datum)
-{
- b->store_kv(self_name, datum);
-}
-
namespace options::detail {
void set_base_value_to_default(value_* val)
diff --git a/options/slider.cpp b/options/slider.cpp
index 56d9ba16..5789e951 100644
--- a/options/slider.cpp
+++ b/options/slider.cpp
@@ -11,7 +11,7 @@
namespace options {
-slider_value::slider_value(double cur, double min, double max) :
+constexpr slider_value::slider_value(double cur, double min, double max) :
cur_(cur),
min_(min),
max_(max)
@@ -24,48 +24,31 @@ slider_value::slider_value(double cur, double min, double max) :
cur_ = min_;
}
-slider_value& slider_value::operator=(const slider_value& v)
+template<typename t>
+static constexpr auto abs_(t x)
{
- if (this != &v)
- {
- cur_ = v.cur();
- min_ = v.min();
- max_ = v.max();
- }
-
- return *this;
+ return x < t{0} ? -x : x;
}
-slider_value::slider_value(const slider_value& v)
+constexpr bool slider_value::operator==(const slider_value& v) const
{
- *this = v;
-}
-
-slider_value::slider_value() : slider_value(0, 0, 0)
-{
-}
-
-bool slider_value::operator==(const slider_value& v) const
-{
- using std::fabs;
-
constexpr double eps = 2e-3;
#if 1
- return (fabs(v.cur_ - cur_) < eps &&
- fabs(v.min_ - min_) < eps &&
- fabs(v.max_ - max_) < eps);
+ return (abs_(v.cur_ - cur_) < eps &&
+ abs_(v.min_ - min_) < eps &&
+ abs_(v.max_ - max_) < eps);
#else
- return (fabs(v.cur_ - cur_) < eps);
+ return (abs_(v.cur_ - cur_) < eps);
#endif
}
-bool slider_value::operator!=(const slider_value& v) const
+constexpr bool slider_value::operator!=(const slider_value& v) const
{
return !(*this == v);
}
-slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const
+constexpr slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) const
{
slider_value v(*this);
@@ -75,11 +58,11 @@ slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) con
: (((pos - q_min) * (v.max() - v.min())) / q_diff + v.min());
if (sv_pos < v.min())
- v = slider_value(v.min(), v.min(), v.max());
+ v = { v.min(), v.min(), v.max() };
else if (sv_pos > v.max())
- v = slider_value(v.max(), v.min(), v.max());
+ v = { v.max(), v.min(), v.max() };
else
- v = slider_value(sv_pos, v.min(), v.max());
+ v = { sv_pos, v.min(), v.max() };
return v;
}
diff --git a/options/slider.hpp b/options/slider.hpp
index 360c85b8..1366e390 100644
--- a/options/slider.hpp
+++ b/options/slider.hpp
@@ -22,35 +22,27 @@ namespace options
{
double cur_, min_, max_;
- template<typename t>
- using arith_conversion_t = std::enable_if_t<std::is_arithmetic_v<std::decay_t<t>>, std::decay_t<t>>;
public:
- slider_value(double cur, double min, double max);
+ constexpr slider_value(double cur, double min, double max);
- template<typename t, typename u, typename v> slider_value(t cur, u min, v max) :
+ template<typename t, typename u, typename v>
+ constexpr slider_value(t cur, u min, v max) :
cur_(double(cur)),
min_(double(min)),
max_(double(max))
{}
- template<typename t>
- cc_noinline
- operator arith_conversion_t<t>() const
- {
- return t(cur_);
- }
-
- slider_value& operator=(const slider_value& v);
-
- slider_value(const slider_value& v);
- slider_value();
- bool operator==(const slider_value& v) const;
- bool operator!=(const slider_value& v) const;
- operator double() const { return cur_; }
- double cur() const { return cur_; }
- double min() const { return min_; }
- double max() const { return max_; }
- slider_value update_from_slider(int pos, int q_min, int q_max) const;
+ slider_value& operator=(const slider_value& v) = default;
+ constexpr slider_value(const slider_value& v) = default;
+ constexpr slider_value() : slider_value{0, 0, 0} {};
+
+ constexpr bool operator==(const slider_value& v) const;
+ constexpr bool operator!=(const slider_value& v) const;
+ constexpr operator double() const { return cur_; }
+ constexpr double cur() const { return cur_; }
+ constexpr double min() const { return min_; }
+ constexpr double max() const { return max_; }
+ constexpr slider_value update_from_slider(int pos, int q_min, int q_max) const;
int to_slider_pos(int q_min, int q_max) const;
};
}
diff --git a/options/tie.hpp b/options/tie.hpp
index 59fd0da1..aa83c7cb 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -66,11 +66,11 @@ void tie_setting(value<t>& v, QComboBox* cb, From&& fn_to_index, To&& fn_to_valu
});
}, v.DIRECT_CONNTYPE);
value_::connect(&v, value_::value_changed<t>(),
- cb, [&v, cb, fn_to_index](cv_qualified<t>& v) {
+ cb, [&v, cb, fn_to_index](cv_qualified<t>& v) {
run_in_thread_sync(cb, [&] {
cb->setCurrentIndex(fn_to_index(v));
});
- });
+ }, v.DIRECT_CONNTYPE);
}
template<typename t, typename F>