diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-15 15:35:23 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-16 00:03:42 +0200 |
commit | 82f388100bc2aa6244dac34699b9df078f0c8199 (patch) | |
tree | 5d8d97baa6c50aab4b6ee336161d526973f37586 /compat/util.hpp | |
parent | 77451f10565a622e1ca7f3d39937aae40ec9331d (diff) |
compat/util: add robust way to block qt signals
Diffstat (limited to 'compat/util.hpp')
-rw-r--r-- | compat/util.hpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compat/util.hpp b/compat/util.hpp index 1217e654..d2aaa572 100644 --- a/compat/util.hpp +++ b/compat/util.hpp @@ -8,6 +8,7 @@ #include <thread> #include <condition_variable> +#include <QObject> #include <QDebug> #define progn(...) ([&]() { __VA_ARGS__ }()) @@ -22,6 +23,24 @@ void run_in_thread_async(QObject* obj, F&& fun) QObject::connect(&src, &QObject::destroyed, obj, std::move(fun), Qt::AutoConnection); } +class inhibit_qt_signals final +{ + QObject& val; + bool operate_p; + +public: + inhibit_qt_signals(QObject& val) : val(val), operate_p(!val.signalsBlocked()) + { + if (operate_p) + val.blockSignals(true); + } + ~inhibit_qt_signals() + { + if (operate_p) + val.blockSignals(false); + } +}; + namespace detail { template<typename t> |