From c5db801886b22c3963689ee325ed7114ab94730d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 25 Oct 2018 18:01:20 +0200 Subject: 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::get()', `bundle::get_variant' of an undefined key will fall back to `return def' so remove the duplicate logic. --- options/base-value.hpp | 4 ++-- options/value-traits.hpp | 32 +++++--------------------------- 2 files changed, 7 insertions(+), 29 deletions(-) (limited to 'options') 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>(&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 struct default_value_traits { - using stored_type = std::decay_t; - using value_type = std::decay_t; - - using self = value_traits; + using value_type = t; + using stored_type = u; + using self = value_traits; static value_type value_with_default(const value_type& val, const value_type&) { @@ -91,33 +90,12 @@ struct value_traits : default_value_traits 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 : default_value_traits -{ - 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(!!val); - } - - static value_type value_from_storage(const stored_type& x) - { - return !!x; - } -}; - template<> struct value_traits : value_traits { static constexpr inline value_type pass_value(const value_type& x) { return x; } -- cgit v1.2.3