src/basics.cpp

changeset 1389
3fb8ad4d27b1
parent 1364
f6a3640b1818
child 1390
3eace926af7f
--- a/src/basics.cpp	Thu May 10 15:54:26 2018 +0300
+++ b/src/basics.cpp	Sat May 26 17:28:15 2018 +0300
@@ -180,3 +180,15 @@
 {
 	return superscript(numerator) + "⁄" + subscript(denominator);
 }
+
+/*
+ * Temporarily blocks the signals of `object` and calls `function`. Returns whatever `function`
+ * returns. Assumes that the function does not change the signal blocking status of `object`.
+ */
+void withSignalsBlocked(QObject* object, std::function<void()> function)
+{
+	bool wasBlockingSignals = object->signalsBlocked();
+	object->blockSignals(true);
+	function();
+	object->blockSignals(wasBlockingSignals);
+}

mercurial