From fc54e0b1e69a0dad8e483e54a466a2aab449d87b Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Sun, 12 Dec 2021 17:51:46 +0100 Subject: [PATCH] 1.) Removed semicolon 2.) Added missing = default to deconstructor 3.) Renamed symbols of CompressingProxy more descriptive 4.) Added a text as comment, that explains how the recursive search works 5.) Fixed typos in comments --- src/control/controlcompressingproxy.cpp | 27 ++++++++++++++++--------- src/control/controlcompressingproxy.h | 4 ++-- src/test/controlobjectscripttest.cpp | 3 +-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/control/controlcompressingproxy.cpp b/src/control/controlcompressingproxy.cpp index e6a57b6cc79..5bee3f57490 100644 --- a/src/control/controlcompressingproxy.cpp +++ b/src/control/controlcompressingproxy.cpp @@ -2,23 +2,32 @@ #include "moc_controlcompressingproxy.cpp" -// Compressor +// Event queue compressing proxy CompressingProxy::CompressingProxy(QObject* parent) - : QObject(parent){}; + : QObject(parent) { +} -bool CompressingProxy::emitCheck() { - m_lastEventRecursionOngoing = true; +// This function is called recursive by QCoreApplication::sendPostedEvents, until no more events are in the queue. +// When the last event is found, QCoreApplication::sendPostedEvents returns for the isLatestEventInQueue() instance of this event, +// and m_recursiveSearchForLastEventOngoing is set to false, while returning true itself. +// All previous started instances of isLatestEventInQueue() will return false in consequence, +// because the return value depends on the member variable and not on the stack of the instance. +bool CompressingProxy::isLatestEventInQueue() { + m_recursiveSearchForLastEventOngoing = true; - // sendPostedEventstriggers recursive execution of slotValueChanged until no more events for this slot are in the queue + // sendPostedEvents recursive executes slotValueChanged until no more events for this slot are in the queue + // Each call of sendPostedEvents triggers the proccessing of the next event in the queue, + // by sending the signal to execute slotValueChanged again QCoreApplication::sendPostedEvents(this, QEvent::MetaCall); - // Execution continues here, if last event for this slot is processed - bool isLastEvent = m_lastEventRecursionOngoing; - m_lastEventRecursionOngoing = false; + // Execution continues here, when last event for this slot is processed + bool isLastEvent = m_recursiveSearchForLastEventOngoing; + m_recursiveSearchForLastEventOngoing = false; return isLastEvent; } void CompressingProxy::slotValueChanged(double value, QObject* obj) { - if (emitCheck()) + if (isLatestEventInQueue()) { emit signalValueChanged(value, obj); + } } diff --git a/src/control/controlcompressingproxy.h b/src/control/controlcompressingproxy.h index 46304b6dc35..8542c8f7604 100644 --- a/src/control/controlcompressingproxy.h +++ b/src/control/controlcompressingproxy.h @@ -6,9 +6,9 @@ class CompressingProxy : public QObject { Q_OBJECT private: - bool emitCheck(); + bool isLatestEventInQueue(); - bool m_lastEventRecursionOngoing; + bool m_recursiveSearchForLastEventOngoing; public slots: void slotValueChanged(double value, QObject* obj); diff --git a/src/test/controlobjectscripttest.cpp b/src/test/controlobjectscripttest.cpp index 9dd79275313..7d690ab2a2f 100644 --- a/src/test/controlobjectscripttest.cpp +++ b/src/test/controlobjectscripttest.cpp @@ -25,8 +25,7 @@ class MockControlObjectScript : public ControlObjectScript { QObject* pParent) : ControlObjectScript(key, logger, pParent) { } - ~MockControlObjectScript() override { - } + ~MockControlObjectScript() override = default; MOCK_METHOD2(slotValueChanged, void(double value, QObject*)); };