summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2016-03-24 12:16:08 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2016-03-26 17:25:40 +0000
commit69b11f636f61a2a51333fe1ef69d5fcdf7ff0b9e (patch)
treeea9da3e27cce3732c92b0fe5376d55b3f9379bb9
parent85adc13ac3e5bb82dc7eeeae17886b5d35fcd77f (diff)
Deduplicate QScxmlStateMachine ctor and remove didChange
The didChange parameter to reachedStableState() is rather confusing as a "true" does not denote that the new state is different from the previous one. It just tells us that at least one microstep was performed. This information is not very useful to users of the API, so let's drop it. Change-Id: Ia59e9ad98d813b151429fa0067ab26d007eb4c26 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
-rw-r--r--src/scxml/qscxmlstatemachine.cpp37
-rw-r--r--src/scxml/qscxmlstatemachine.h2
-rw-r--r--src/scxml/qscxmlstatemachine_p.h2
-rw-r--r--tests/auto/scion/tst_scion.cpp4
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp2
5 files changed, 25 insertions, 22 deletions
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp
index 4ab4785..23946bb 100644
--- a/src/scxml/qscxmlstatemachine.cpp
+++ b/src/scxml/qscxmlstatemachine.cpp
@@ -238,6 +238,21 @@ QScxmlStateMachinePrivate::~QScxmlStateMachinePrivate()
delete m_executionEngine;
}
+void QScxmlStateMachinePrivate::init()
+{
+ Q_Q(QScxmlStateMachine);
+ m_executionEngine = new QScxmlExecutableContent::QScxmlExecutionEngine(q);
+ setQStateMachine(new QScxmlInternal::WrappedQStateMachine(q));
+ QObject::connect(m_qStateMachine, &QStateMachine::runningChanged,
+ q, &QScxmlStateMachine::runningChanged);
+ QObject::connect(m_qStateMachine, &QStateMachine::finished,
+ q, &QScxmlStateMachine::finished);
+
+ // The final state is also a stable state.
+ QObject::connect(m_qStateMachine, &QStateMachine::finished,
+ q, &QScxmlStateMachine::reachedStableState);
+}
+
void QScxmlStateMachinePrivate::setQStateMachine(QScxmlInternal::WrappedQStateMachine *stateMachine)
{
m_qStateMachine = stateMachine;
@@ -423,27 +438,13 @@ QScxmlStateMachine::QScxmlStateMachine(QObject *parent)
: QObject(*new QScxmlStateMachinePrivate, parent)
{
Q_D(QScxmlStateMachine);
- d->m_executionEngine = new QScxmlExecutableContent::QScxmlExecutionEngine(this);
- d->setQStateMachine(new QScxmlInternal::WrappedQStateMachine(this));
- connect(d->m_qStateMachine, &QStateMachine::runningChanged, this, &QScxmlStateMachine::runningChanged);
- connect(d->m_qStateMachine, &QStateMachine::finished, this, &QScxmlStateMachine::finished);
- connect(d->m_qStateMachine, &QStateMachine::finished, [this](){
- // The final state is also a stable state.
- emit reachedStableState(true);
- });
+ d->init();
}
QScxmlStateMachine::QScxmlStateMachine(QScxmlStateMachinePrivate &dd, QObject *parent)
: QObject(dd, parent)
{
- Q_D(QScxmlStateMachine);
- d->m_executionEngine = new QScxmlExecutableContent::QScxmlExecutionEngine(this);
- connect(d->m_qStateMachine, &QStateMachine::runningChanged, this, &QScxmlStateMachine::runningChanged);
- connect(d->m_qStateMachine, &QStateMachine::finished, this, &QScxmlStateMachine::finished);
- connect(d->m_qStateMachine, &QStateMachine::finished, [this](){
- // The final state is also a stable state.
- emit reachedStableState(true);
- });
+ dd.init();
}
/*!
@@ -687,7 +688,7 @@ void QScxmlInternal::WrappedQStateMachinePrivate::processedPendingEvents(bool di
{
qCDebug(qscxmlLog) << m_stateMachine << "finishedPendingEvents" << didChange << "in state ("
<< m_stateMachine->activeStateNames() << ")";
- emit m_stateMachine->reachedStableState(didChange);
+ emit m_stateMachine->reachedStableState();
}
void QScxmlInternal::WrappedQStateMachinePrivate::beginMacrostep()
@@ -1169,7 +1170,7 @@ bool QScxmlStateMachine::isDispatchableTarget(const QString &target) const
*/
/*!
- \fn QScxmlStateMachine::reachedStableState(bool didChange)
+ \fn QScxmlStateMachine::reachedStableState()
This signal is emitted when the event queue is empty at the end of a macro step or when a final
state is reached.
diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h
index dbed8b1..0f7aeed 100644
--- a/src/scxml/qscxmlstatemachine.h
+++ b/src/scxml/qscxmlstatemachine.h
@@ -129,7 +129,7 @@ public:
Q_SIGNALS:
void runningChanged(bool running);
void log(const QString &label, const QString &msg);
- void reachedStableState(bool didChange);
+ void reachedStableState();
void finished();
void eventOccurred(const QScxmlEvent &event);
diff --git a/src/scxml/qscxmlstatemachine_p.h b/src/scxml/qscxmlstatemachine_p.h
index d21bdc1..5f2fff1 100644
--- a/src/scxml/qscxmlstatemachine_p.h
+++ b/src/scxml/qscxmlstatemachine_p.h
@@ -109,6 +109,8 @@ public:
QScxmlStateMachinePrivate();
~QScxmlStateMachinePrivate();
+ void init();
+
static QScxmlStateMachinePrivate *get(QScxmlStateMachine *t)
{ return t->d_func(); }
diff --git a/tests/auto/scion/tst_scion.cpp b/tests/auto/scion/tst_scion.cpp
index 86a4403..92dc291 100644
--- a/tests/auto/scion/tst_scion.cpp
+++ b/tests/auto/scion/tst_scion.cpp
@@ -359,7 +359,7 @@ static bool playEvent(QScxmlStateMachine *stateMachine, const QJsonObject &event
}
stateMachine->submitEvent(e);
- if (!MySignalSpy(stateMachine, SIGNAL(reachedStableState(bool))).fastWait()) {
+ if (!MySignalSpy(stateMachine, SIGNAL(reachedStableState())).fastWait()) {
qWarning() << "State machine did not reach a stable state!";
} else if (verifyStates(stateMachine, eventDescription, QLatin1String("nextConfiguration"), counter)) {
return true;
@@ -383,7 +383,7 @@ static bool playEvents(QScxmlStateMachine *stateMachine, const QJsonObject &test
bool TestScion::runTest(QScxmlStateMachine *stateMachine, const QJsonObject &testDescription)
{
- MySignalSpy stableStateSpy(stateMachine, SIGNAL(reachedStableState(bool)));
+ MySignalSpy stableStateSpy(stateMachine, SIGNAL(reachedStableState()));
MySignalSpy finishedSpy(stateMachine, SIGNAL(finished()));
if (!stateMachine->init() && stateMachine->name() != QStringLiteral("test487")) {
diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp
index 9ee9aa4..913ec86 100644
--- a/tests/auto/statemachine/tst_statemachine.cpp
+++ b/tests/auto/statemachine/tst_statemachine.cpp
@@ -110,7 +110,7 @@ void tst_StateMachine::activeStateNames()
QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(scxmlFileName));
QVERIFY(!stateMachine.isNull());
- QSignalSpy stableStateSpy(stateMachine.data(), SIGNAL(reachedStableState(bool)));
+ QSignalSpy stableStateSpy(stateMachine.data(), SIGNAL(reachedStableState()));
stateMachine->init();
stateMachine->start();