summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-25 18:01:20 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-25 18:27:42 +0200
commitc5db801886b22c3963689ee325ed7114ab94730d (patch)
tree55119b016fbebc2efe3d6b99bafafce1c78fa491 /options
parent83867b413c449101bbe14615ff857a7785432ede (diff)
options/value-traits: fix bool storage
Using int as `stored_type' for bool made Qt signals not work. Evident when ticking the "asymmetric mapping" checkboxes in the mapping window. Remove some std::decay_t usage, there's no need for either decay or remove_cvref. In `value<t>::get()', `bundle::get_variant' of an undefined key will fall back to `return def' so remove the duplicate logic.
Diffstat (limited to 'options')
-rw-r--r--options/base-value.hpp4
-rw-r--r--options/value-traits.hpp32
2 files changed, 7 insertions, 29 deletions
diff --git a/options/base-value.hpp b/options/base-value.hpp
index 6a4709ee..14eaeb10 100644
--- a/options/base-value.hpp
+++ b/options/base-value.hpp
@@ -43,8 +43,6 @@ public:
return static_cast<signal_sig<t>>(&value_::valueChanged);
}
- void notify() const;
-
signals:
OTR_OPTIONS_SIGNAL(double);
OTR_OPTIONS_SIGNAL(float);
@@ -96,6 +94,8 @@ public slots:
virtual void bundle_value_changed() const = 0;
virtual void set_to_default() = 0;
+ void notify() const;
+
friend void ::options::detail::set_value_to_default(value_* val);
};
diff --git a/options/value-traits.hpp b/options/value-traits.hpp
index 31b6b534..f5b74f73 100644
--- a/options/value-traits.hpp
+++ b/options/value-traits.hpp
@@ -17,10 +17,9 @@ struct value_traits;
template<typename t, typename u = t, typename Enable = void>
struct default_value_traits
{
- using stored_type = std::decay_t<u>;
- using value_type = std::decay_t<t>;
-
- using self = value_traits<t>;
+ using value_type = t;
+ using stored_type = u;
+ using self = value_traits<value_type>;
static value_type value_with_default(const value_type& val, const value_type&)
{
@@ -91,33 +90,12 @@ struct value_traits<double> : default_value_traits<double>
value_type x_, y_;
- return I(std::round(std::modf(x, &x_) * K)) == I(std::round(std::modf(y, &y_) * K)) &&
- I(std::round(x_)) == I(std::round(y_));
+ return I(std::modf(x, &x_) * K) == I(std::modf(y, &y_) * K) &&
+ I(x_) == I(y_);
}
}
};
-template<> struct value_traits<bool> : default_value_traits<bool, int>
-{
- static stored_type storage_from_qvariant(const QVariant& x)
- {
- if (x.type() == QVariant::String)
- return x.toBool();
- else
- return !!x.toInt();
- }
-
- static QVariant qvariant_from_storage(const stored_type& val)
- {
- return QVariant::fromValue<int>(!!val);
- }
-
- static value_type value_from_storage(const stored_type& x)
- {
- return !!x;
- }
-};
-
template<> struct value_traits<float> : value_traits<float, double>
{
static constexpr inline value_type pass_value(const value_type& x) { return x; }