summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2016-04-06 12:18:42 +0200
committerUlf Hermann <ulf.hermann@qt.io>2016-04-19 07:03:31 +0000
commitf648d720d0c2a5dcef02c10cfe6cfaea717a6cdc (patch)
treeb2ba0cd1b6073b75b2159a05b4744dbb7779c133
parent7c4111286b3c1f072a731ae9aa938c9e73b035e7 (diff)
Allow history states for <scxml>'s "initial" attribute
The standard doesn't seem to prohibit this and QStateMachine can handle it. Change-Id: Ia22f564c9657582199c3c67318fafd21ec4a8770 Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
-rw-r--r--src/scxml/qscxmlparser.cpp2
-rw-r--r--src/scxml/qscxmlqstates.cpp24
-rw-r--r--src/scxml/qscxmlqstates.h15
-rw-r--r--tests/auto/compiled/compiled.pro3
-rw-r--r--tests/auto/compiled/initialhistory.scxml15
-rw-r--r--tools/qscxmlc/scxmlcppdumper.cpp6
6 files changed, 60 insertions, 5 deletions
diff --git a/src/scxml/qscxmlparser.cpp b/src/scxml/qscxmlparser.cpp
index 6abe74e..eb7f016 100644
--- a/src/scxml/qscxmlparser.cpp
+++ b/src/scxml/qscxmlparser.cpp
@@ -1270,7 +1270,7 @@ private:
bool visit(DocumentModel::HistoryState *state) Q_DECL_OVERRIDE
{
- QHistoryState *newState = new QHistoryState(currentParent());
+ QHistoryState *newState = new QScxmlHistoryState(currentParent());
switch (state->type) {
case DocumentModel::HistoryState::Shallow:
newState->setHistoryType(QHistoryState::ShallowHistory);
diff --git a/src/scxml/qscxmlqstates.cpp b/src/scxml/qscxmlqstates.cpp
index 6fd1e53..d40ef20 100644
--- a/src/scxml/qscxmlqstates.cpp
+++ b/src/scxml/qscxmlqstates.cpp
@@ -196,6 +196,30 @@ QScxmlStateMachine *QScxmlFinalState::stateMachine() const {
return qobject_cast<QScxmlInternal::WrappedQStateMachine *>(machine())->stateMachine();
}
+QScxmlHistoryState::QScxmlHistoryState(QState *parent)
+ : QHistoryState(parent)
+{
+}
+
+QScxmlHistoryState::~QScxmlHistoryState()
+{
+}
+
+void QScxmlHistoryState::setAsInitialStateFor(QScxmlState *state)
+{
+ state->setInitialState(this);
+}
+
+void QScxmlHistoryState::setAsInitialStateFor(QScxmlStateMachine *stateMachine)
+{
+ QScxmlStateMachinePrivate::get(stateMachine)->m_qStateMachine->setInitialState(this);
+}
+
+QScxmlStateMachine *QScxmlHistoryState::stateMachine() const
+{
+ return qobject_cast<QScxmlInternal::WrappedQStateMachine *>(machine())->stateMachine();
+}
+
QScxmlExecutableContent::ContainerId QScxmlFinalState::doneData() const
{
Q_D(const QScxmlFinalState);
diff --git a/src/scxml/qscxmlqstates.h b/src/scxml/qscxmlqstates.h
index 63abe3b..7280a0f 100644
--- a/src/scxml/qscxmlqstates.h
+++ b/src/scxml/qscxmlqstates.h
@@ -45,6 +45,7 @@
#include <QAbstractTransition>
#include <QFinalState>
+#include <QHistoryState>
#include <QState>
QT_BEGIN_NAMESPACE
@@ -133,6 +134,20 @@ private:
Q_DECLARE_PRIVATE(QScxmlFinalState)
};
+class Q_SCXML_EXPORT QScxmlHistoryState: public QHistoryState
+{
+ Q_OBJECT
+
+public:
+ QScxmlHistoryState(QState *parent = Q_NULLPTR);
+ ~QScxmlHistoryState();
+
+ void setAsInitialStateFor(QScxmlState *state);
+ void setAsInitialStateFor(QScxmlStateMachine *stateMachine);
+
+ QScxmlStateMachine *stateMachine() const;
+};
+
class QScxmlBaseTransitionPrivate;
class Q_SCXML_EXPORT QScxmlBaseTransition: public QAbstractTransition
{
diff --git a/tests/auto/compiled/compiled.pro b/tests/auto/compiled/compiled.pro
index 53dcd8c..0fd3db9 100644
--- a/tests/auto/compiled/compiled.pro
+++ b/tests/auto/compiled/compiled.pro
@@ -17,6 +17,7 @@ STATECHARTS = \
statemachineunicodename.scxml \
anonymousstate.scxml \
submachineunicodename.scxml \
- datainnulldatamodel.scxml
+ datainnulldatamodel.scxml \
+ initialhistory.scxml
load(qscxmlc)
diff --git a/tests/auto/compiled/initialhistory.scxml b/tests/auto/compiled/initialhistory.scxml
new file mode 100644
index 0000000..9262e17
--- /dev/null
+++ b/tests/auto/compiled/initialhistory.scxml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="h">
+ <state id="b">
+ <history id="h">
+ <transition target="b2"/>
+ </history>
+
+ <state id="b2">
+ <onentry>
+ <assign location="x" expr="x * 5"/>
+ <log expr="'b2, x:' + x"/>
+ </onentry>
+ </state>
+ </state>
+</scxml>
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp
index c656376..5f37ac8 100644
--- a/tools/qscxmlc/scxmlcppdumper.cpp
+++ b/tools/qscxmlc/scxmlcppdumper.cpp
@@ -526,11 +526,11 @@ protected:
bool visit(DocumentModel::HistoryState *node) Q_DECL_OVERRIDE
{
// Includes:
- clazz.implIncludes << "QHistoryState";
+ clazz.implIncludes << "QScxmlHistoryState";
const QString stateName = mangledName(node, StateName);
// Declaration:
- clazz.classFields << QStringLiteral("QHistoryState ") + stateName + QLatin1Char(';');
+ clazz.classFields << QStringLiteral("QScxmlHistoryState ") + stateName + QLatin1Char(';');
// Initializer:
clazz.constructor.initializer << generateInitializer(node);
@@ -550,7 +550,7 @@ protected:
default:
Q_UNREACHABLE();
}
- clazz.init.impl << stateName + QStringLiteral(".setHistoryType(QHistoryState::") + depth + QStringLiteral("History);");
+ clazz.init.impl << stateName + QStringLiteral(".setHistoryType(QScxmlHistoryState::") + depth + QStringLiteral("History);");
// visit the kid:
if (Transition *t = node->defaultConfiguration()) {