Skip to content

Commit

Permalink
1.) Removed semicolon
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoergAtGithub committed Dec 12, 2021
1 parent 6d74436 commit fc54e0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
27 changes: 18 additions & 9 deletions src/control/controlcompressingproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/control/controlcompressingproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/test/controlobjectscripttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*));
};

Expand Down

0 comments on commit fc54e0b

Please sign in to comment.