From 82f388100bc2aa6244dac34699b9df078f0c8199 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Aug 2016 15:35:23 +0200 Subject: compat/util: add robust way to block qt signals --- compat/util.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'compat') 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 #include +#include #include #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 -- cgit v1.2.3