summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/scxml/qscxmlstatemachine.cpp15
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp21
2 files changed, 35 insertions, 1 deletions
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp
index 61a37ef..6bc7ab5 100644
--- a/src/scxml/qscxmlstatemachine.cpp
+++ b/src/scxml/qscxmlstatemachine.cpp
@@ -609,17 +609,27 @@ void QScxmlStateMachinePrivate::submitError(const QString &type, const QString &
void QScxmlStateMachinePrivate::start()
{
+ Q_Q(QScxmlStateMachine);
+
if (m_stateTable->binding == StateTable::LateBinding)
m_isFirstStateEntry.resize(m_stateTable->stateCount, true);
+ bool running = isRunnable() && !isPaused();
m_runningState = Starting;
Q_ASSERT(m_stateTable->initialTransition != StateTable::InvalidIndex);
+
+ if (!running)
+ emit q->runningChanged(true);
}
void QScxmlStateMachinePrivate::pause()
{
- if (isRunnable() && !isPaused())
+ Q_Q(QScxmlStateMachine);
+
+ if (isRunnable() && !isPaused()) {
m_runningState = Paused;
+ emit q->runningChanged(false);
+ }
}
void QScxmlStateMachinePrivate::processEvents()
@@ -1106,7 +1116,10 @@ void QScxmlStateMachinePrivate::enterStates(const OrderedSet &enabledTransitions
m_executionEngine->execute(dhc);
if (state.type == StateTable::State::Final) {
if (state.parentIsScxmlElement()) {
+ bool running = isRunnable() && !isPaused();
m_runningState = Finished;
+ if (running)
+ emit q->runningChanged(false);
} else {
const auto &parent = m_stateTable->state(state.parent);
m_executionEngine->execute(state.doneData, m_tableData->string(parent.name));
diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp
index f09ad42..99d6661 100644
--- a/tests/auto/statemachine/tst_statemachine.cpp
+++ b/tests/auto/statemachine/tst_statemachine.cpp
@@ -51,6 +51,7 @@ private Q_SLOTS:
void eventOccurred();
void doneDotStateEvent();
+ void running();
};
void tst_StateMachine::stateNames_data()
@@ -365,6 +366,26 @@ void tst_StateMachine::doneDotStateEvent()
QVERIFY(stateMachine->activeStateNames(true).contains(QLatin1String("success")));
}
+void tst_StateMachine::running()
+{
+ QScopedPointer<QScxmlStateMachine> stateMachine(
+ QScxmlStateMachine::fromFile(QString(":/tst_statemachine/statenames.scxml")));
+ QVERIFY(!stateMachine.isNull());
+
+ QSignalSpy runningChangedSpy(stateMachine.data(), SIGNAL(runningChanged(bool)));
+
+ QCOMPARE(stateMachine->isRunning(), false);
+
+ stateMachine->start();
+
+ QCOMPARE(runningChangedSpy.count(), 1);
+ QCOMPARE(stateMachine->isRunning(), true);
+
+ stateMachine->stop();
+
+ QCOMPARE(runningChangedSpy.count(), 2);
+ QCOMPARE(stateMachine->isRunning(), false);
+}
QTEST_MAIN(tst_StateMachine)