diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-10-19 03:39:44 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-10-19 03:57:28 +0200 |
commit | 3d771972612e2a9dbabec719db027c7abaa8a1a3 (patch) | |
tree | f77888ba9b43def7f2ebf0a58c69a2db04c84ce0 | |
parent | 634403a68dd710d68abcd2e063f9660e9b3e30ea (diff) |
options: add trace to valueChanged()
-rw-r--r-- | options/base-value.cpp | 20 | ||||
-rw-r--r-- | options/base-value.hpp | 4 | ||||
-rw-r--r-- | options/value.hpp | 5 |
3 files changed, 29 insertions, 0 deletions
diff --git a/options/base-value.cpp b/options/base-value.cpp index d4ec4b6c..c7691a8f 100644 --- a/options/base-value.cpp +++ b/options/base-value.cpp @@ -1,7 +1,20 @@ #include "base-value.hpp" +#include <QThread> using namespace options; +//#define OTR_TRACE_NOTIFY + +const bool value_::TRACE_NOTIFY = +#ifdef OTR_TRACE_NOTIFY + true; +#else + [] { + auto b = qgetenv("OTR_TRACE_NOTIFY"); + return !b.isEmpty() && b != "0"; + }(); +#endif + value_::value_(bundle const& b, const QString& name) noexcept : b(b), self_name(name) { @@ -12,3 +25,10 @@ value_::~value_() { b->on_value_destructed(this); } + +void value_::maybe_trace(bool x) const +{ + if (TRACE_NOTIFY) + qDebug().noquote() << "notify" << (x ? '+' : '-') + << QThread::currentThreadId() << b->name() << self_name; +} diff --git a/options/base-value.hpp b/options/base-value.hpp index 722107a4..9b2ebe53 100644 --- a/options/base-value.hpp +++ b/options/base-value.hpp @@ -40,6 +40,8 @@ public: return static_cast<signal_sig<t>>(&value_::valueChanged); } + static const bool TRACE_NOTIFY; + signals: OTR_OPTIONS_SIGNAL(double); OTR_OPTIONS_SIGNAL(float); @@ -65,6 +67,8 @@ protected: virtual void store_variant(QVariant&&) noexcept = 0; virtual void store_variant(const QVariant&) noexcept = 0; + void maybe_trace(bool x) const; + template<typename t> void store_(const t& datum) { diff --git a/options/value.hpp b/options/value.hpp index 92e2878f..10903b19 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -92,10 +92,15 @@ public: return traits::qvariant_from_value(def); } + never_inline void notify() const override { if (!is_null()) + { + maybe_trace(true); emit valueChanged(traits::storage_from_value(get())); + maybe_trace(false); + } } auto& operator=(t&& datum) noexcept |