diff options
Diffstat (limited to 'options/value.hpp')
| -rw-r--r-- | options/value.hpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/options/value.hpp b/options/value.hpp index 92e2878f..9a7487b8 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -14,7 +14,6 @@ #include "slider.hpp" #include "base-value.hpp" #include "value-traits.hpp" -#include "compat/macros.hpp" #include <type_traits> #include <utility> @@ -38,8 +37,10 @@ namespace options { template<typename t> class value final : public value_ { - static_assert(std::is_same_v<t, remove_cvref_t<t>>); + static_assert(std::is_same_v<t, std::remove_cvref_t<t>>); + mutable QMutex mtx; const t def; + mutable t cached_value; using traits = detail::value_traits<t>; never_inline @@ -92,10 +93,42 @@ public: return traits::qvariant_from_value(def); } + never_inline + void notify_() const override + { + auto x = get(); + { + QMutexLocker l(&mtx); + cached_value = x; + } + maybe_trace("notify +"); + emit valueChanged(traits::storage_from_value(x)); + maybe_trace("notify -"); + } + + never_inline void notify() const override { - if (!is_null()) - emit valueChanged(traits::storage_from_value(get())); + if (is_null()) + return; + + auto x = get(); + { + QMutexLocker l(&mtx); + if (traits::is_equal(x, cached_value)) + { + //maybe_trace("notify ~"); + return; + } + else + { + cached_value = x; + l.unlock(); + maybe_trace("notify +"); + emit valueChanged(traits::storage_from_value(x)); + maybe_trace("notify -"); + } + } } auto& operator=(t&& datum) noexcept @@ -104,6 +137,7 @@ public: return *this; store_variant(traits::qvariant_from_value(traits::pass_value(datum))); + maybe_trace("set-value"); return *this; } @@ -126,7 +160,7 @@ public: static constexpr Qt::ConnectionType DIRECT_CONNTYPE = Qt::DirectConnection; static constexpr Qt::ConnectionType SAFE_CONNTYPE = Qt::QueuedConnection; - value(bundle b, const QString& name, t def) noexcept : value_(b, name), def(std::move(def)) + value(bundle b, const QString& name, t def) noexcept : value_(b, name), def(std::move(def)), cached_value{get()} { } |
