--- 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); +}