aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Stottlemyer <bstottle@ford.com>2014-07-31 09:45:14 +0300
committerBrett Stottlemyer <bstottle@ford.com>2014-08-08 20:03:36 +0200
commitd239b72fcf0ecd361b24024ed303dfd874e605f2 (patch)
tree6c10337da5f702a68074f71874205746649b1846
parentca43c4121dde6c8f5d4eabfcf128ff6214996d54 (diff)
Say hello to the Declarative State Machine Framework
The Declarative State Machine Framework extends Qt's State Machine Framework (QSM) into QML to provide types for creating and executing state graphs in QML. This gives you the power of deterministic state machines, but declaratively and without having to write all of the boilerplate code. It is an alternative to the existing QML State type, intended for more complex models. [ChangeLog][QtQML] The Declarative State Machine Framework extends Qt's State Machine Framework (QSM) into QML. This gives you the power of deterministic state machines, but declaratively. Change-Id: I02390ba7f1baed50935364530925bd75087299cb Reviewed-by: Sebastian Sauer <sebastian.sauer@kdab.com> Reviewed-by: BogDan Vatra <bogdan@kde.org> Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
-rw-r--r--src/imports/imports.pro3
-rw-r--r--src/imports/statemachine/childrenprivate.h108
-rw-r--r--src/imports/statemachine/finalstate.cpp85
-rw-r--r--src/imports/statemachine/finalstate.h73
-rw-r--r--src/imports/statemachine/plugin.cpp77
-rw-r--r--src/imports/statemachine/plugins.qmltypes163
-rw-r--r--src/imports/statemachine/qmldir4
-rw-r--r--src/imports/statemachine/signaltransition.cpp238
-rw-r--r--src/imports/statemachine/signaltransition.h86
-rw-r--r--src/imports/statemachine/statebase.cpp244
-rw-r--r--src/imports/statemachine/statebase.h77
-rw-r--r--src/imports/statemachine/statemachine.cpp223
-rw-r--r--src/imports/statemachine/statemachine.h91
-rw-r--r--src/imports/statemachine/statemachine.pro24
-rw-r--r--src/imports/statemachine/timeouttransition.cpp114
-rw-r--r--src/imports/statemachine/timeouttransition.h76
-rw-r--r--src/qml/doc/images/statemachine-button-history.pngbin0 -> 8074 bytes
-rw-r--r--src/qml/doc/images/statemachine-button-nested.pngbin0 -> 7051 bytes
-rw-r--r--src/qml/doc/images/statemachine-button.pngbin0 -> 4233 bytes
-rw-r--r--src/qml/doc/images/statemachine-finished.pngbin0 -> 5518 bytes
-rw-r--r--src/qml/doc/images/statemachine-nonparallel.pngbin0 -> 5350 bytes
-rw-r--r--src/qml/doc/images/statemachine-parallel.pngbin0 -> 8631 bytes
-rw-r--r--src/qml/doc/qtqml.qdocconf3
-rw-r--r--src/qml/doc/snippets/qml/statemachine/Button.qml88
-rw-r--r--src/qml/doc/snippets/qml/statemachine/basicstate.qml55
-rw-r--r--src/qml/doc/snippets/qml/statemachine/finalstate.qml63
-rw-r--r--src/qml/doc/snippets/qml/statemachine/historystate.qml85
-rw-r--r--src/qml/doc/snippets/qml/statemachine/signaltransition.qml77
-rw-r--r--src/qml/doc/snippets/qml/statemachine/signaltransitionsignal.qml62
-rw-r--r--src/qml/doc/snippets/qml/statemachine/simplestatemachine.qml68
-rw-r--r--src/qml/doc/snippets/qml/statemachine/statemachine-button-history.qml150
-rw-r--r--src/qml/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml135
-rw-r--r--src/qml/doc/snippets/qml/statemachine/statemachine-button-nested.qml127
-rw-r--r--src/qml/doc/snippets/qml/statemachine/statemachine-button.qml100
-rw-r--r--src/qml/doc/snippets/qml/statemachine/timeouttransition.qml69
-rw-r--r--src/qml/doc/src/qtqml.qdoc5
-rw-r--r--src/qml/doc/src/statemachine.qdoc317
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h2
-rw-r--r--tests/auto/qmltest/statemachine/tst_anonymousstate.qml52
-rw-r--r--tests/auto/qmltest/statemachine/tst_historystate.qml102
-rw-r--r--tests/auto/qmltest/statemachine/tst_initialstate.qml65
-rw-r--r--tests/auto/qmltest/statemachine/tst_nestedinitialstates.qml74
-rw-r--r--tests/auto/qmltest/statemachine/tst_parallelmachine.qml90
-rw-r--r--tests/auto/qmltest/statemachine/tst_trafficlight.qml157
44 files changed, 3629 insertions, 3 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
index f1d262a6c3..d0d47aa38c 100644
--- a/src/imports/imports.pro
+++ b/src/imports/imports.pro
@@ -4,7 +4,8 @@ SUBDIRS += \
folderlistmodel \
localstorage \
models \
- settings
+ settings \
+ statemachine
qtHaveModule(quick) {
SUBDIRS += \
diff --git a/src/imports/statemachine/childrenprivate.h b/src/imports/statemachine/childrenprivate.h
new file mode 100644
index 0000000000..7e7b7f37ef
--- /dev/null
+++ b/src/imports/statemachine/childrenprivate.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLCHILDRENPRIVATE_H
+#define QQMLCHILDRENPRIVATE_H
+
+#include <QAbstractState>
+#include <QAbstractTransition>
+#include <QStateMachine>
+#include <QQmlInfo>
+#include <QQmlListProperty>
+
+template <class T>
+class ChildrenPrivate
+{
+public:
+ ChildrenPrivate()
+ {}
+
+ static void append(QQmlListProperty<QObject> *prop, QObject *item)
+ {
+ QAbstractState *state = qobject_cast<QAbstractState*>(item);
+ if (state) {
+ if (qobject_cast<QStateMachine*>(item))
+ qmlInfo(static_cast<T *>(prop->object)) << "StateMachines should not be nested.";
+
+ item->setParent(prop->object);
+ } else {
+ QAbstractTransition *trans = qobject_cast<QAbstractTransition*>(item);
+ if (trans)
+ static_cast<T *>(prop->object)->addTransition(trans);
+ }
+ static_cast<ChildrenPrivate<T>*>(prop->data)->children.append(item);
+ emit static_cast<T *>(prop->object)->childrenChanged();
+ }
+
+ static void appendNoTransition(QQmlListProperty<QObject> *prop, QObject *item)
+ {
+ QAbstractState *state = qobject_cast<QAbstractState*>(item);
+ if (state) {
+ if (qobject_cast<QStateMachine*>(item))
+ qmlInfo(static_cast<T *>(prop->object)) << "StateMachines should not be nested.";
+
+ item->setParent(prop->object);
+ }
+ static_cast<ChildrenPrivate<T>*>(prop->data)->children.append(item);
+ emit static_cast<T *>(prop->object)->childrenChanged();
+ }
+
+ static int count(QQmlListProperty<QObject> *prop)
+ {
+ return static_cast<ChildrenPrivate<T>*>(prop->data)->children.count();
+ }
+
+ static QObject *at(QQmlListProperty<QObject> *prop, int index)
+ {
+ return static_cast<ChildrenPrivate<T>*>(prop->data)->children.at(index);
+ }
+
+ static void clear(QQmlListProperty<QObject> *prop)
+ {
+ static_cast<ChildrenPrivate<T>*>(prop->data)->children.clear();
+ emit static_cast<T *>(prop->object)->childrenChanged();
+ }
+
+private:
+ QList<QObject *> children;
+};
+
+#endif
diff --git a/src/imports/statemachine/finalstate.cpp b/src/imports/statemachine/finalstate.cpp
new file mode 100644
index 0000000000..1852a533c6
--- /dev/null
+++ b/src/imports/statemachine/finalstate.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "finalstate.h"
+
+#include <QQmlContext>
+#include <QQmlEngine>
+#include <QQmlInfo>
+
+FinalState::FinalState(QState *parent)
+ : QFinalState(parent)
+{
+}
+
+QQmlListProperty<QObject> FinalState::children()
+{
+ return QQmlListProperty<QObject>(this, &m_children, m_children.appendNoTransition, m_children.count, m_children.at, m_children.clear);
+}
+
+/*!
+ \qmltype FinalState
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QAbstractState
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief Provides a final state.
+
+
+ A final state is used to communicate that (part of) a StateMachine has
+ finished its work. When a final top-level state is entered, the state
+ machine's \l{StateBase::finished}{finished}() signal is emitted. In
+ general, when a final substate (a child of a State) is entered, the parent
+ state's \l{StateBase::finished}{finished}() signal is emitted. FinalState
+ is part of \l{The Declarative State Machine Framework}.
+
+ To use a final state, you create a FinalState object and add a transition
+ to it from another state.
+
+ \section1 Example Usage
+
+ \snippet qml/statemachine/finalstate.qml document
+
+ \clearfloat
+
+ \sa StateMachine, StateBase
+*/
diff --git a/src/imports/statemachine/finalstate.h b/src/imports/statemachine/finalstate.h
new file mode 100644
index 0000000000..6086b1b8a2
--- /dev/null
+++ b/src/imports/statemachine/finalstate.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLFINALSTATE_H
+#define QQMLFINALSTATE_H
+
+#include "childrenprivate.h"
+#include "statemachine.h"
+
+#include <QtCore/QFinalState>
+#include <QtQml/QQmlListProperty>
+
+
+QT_BEGIN_NAMESPACE
+
+class FinalState : public QFinalState
+{
+ Q_OBJECT
+ Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged)
+ Q_CLASSINFO("DefaultProperty", "children")
+
+public:
+ explicit FinalState(QState *parent = 0);
+
+ QQmlListProperty<QObject> children();
+
+Q_SIGNALS:
+ void childrenChanged();
+
+private:
+ ChildrenPrivate<FinalState> m_children;
+};
+
+QT_END_NAMESPACE
+#endif
diff --git a/src/imports/statemachine/plugin.cpp b/src/imports/statemachine/plugin.cpp
new file mode 100644
index 0000000000..2a266f9dfb
--- /dev/null
+++ b/src/imports/statemachine/plugin.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "finalstate.h"
+#include "signaltransition.h"
+#include "statebase.h"
+#include "statemachine.h"
+#include "timeouttransition.h"
+
+#include <QHistoryState>
+#include <QQmlExtensionPlugin>
+#include <qqml.h>
+
+QT_BEGIN_NAMESPACE
+
+class QtQmlStateMachinePlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.org.Qt.QtQml.StateMachine/1.0")
+
+public:
+ void registerTypes(const char *uri)
+ {
+ qmlRegisterType<StateBase>(uri, 1, 0, "StateBase");
+ qmlRegisterType<StateMachine>(uri, 1, 0, "StateMachine");
+ qmlRegisterType<QHistoryState>(uri, 1, 0, "HistoryState");
+ qmlRegisterType<FinalState>(uri, 1, 0, "FinalState");
+ qmlRegisterUncreatableType<QState>(uri, 1, 0, "QState", "Don't use this, use StateBase instead");
+ qmlRegisterUncreatableType<QAbstractState>(uri, 1, 0, "QAbstractState", "Don't use this, use StateBase instead");
+ qmlRegisterUncreatableType<QSignalTransition>(uri, 1, 0, "QSignalTransition", "Don't use this, use SignalTransition instead");
+ qmlRegisterType<SignalTransition>(uri, 1, 0, "SignalTransition");
+ qmlRegisterType<TimeoutTransition>(uri, 1, 0, "TimeoutTransition");
+ qmlProtectModule(uri, 1);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
diff --git a/src/imports/statemachine/plugins.qmltypes b/src/imports/statemachine/plugins.qmltypes
new file mode 100644
index 0000000000..a53d68f8e8
--- /dev/null
+++ b/src/imports/statemachine/plugins.qmltypes
@@ -0,0 +1,163 @@
+import QtQuick.tooling 1.1
+
+// This file describes the plugin-supplied types contained in the library.
+// It is used for QML tooling purposes only.
+//
+// This file was auto-generated by:
+// 'qmlplugindump -nonrelocatable QtQml.StateMachine 1.0'
+
+Module {
+ Component {
+ name: "FinalState"
+ defaultProperty: "children"
+ prototype: "QFinalState"
+ exports: ["QtQml.StateMachine/FinalState 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "children"; type: "QObject"; isList: true; isReadonly: true }
+ }
+ Component {
+ name: "QAbstractState"
+ prototype: "QObject"
+ exports: ["QtQml.StateMachine/QAbstractState 1.0"]
+ isCreatable: false
+ exportMetaObjectRevisions: [0]
+ Property { name: "active"; type: "bool"; isReadonly: true }
+ Signal { name: "entered" }
+ Signal { name: "exited" }
+ Signal {
+ name: "activeChanged"
+ Parameter { name: "active"; type: "bool" }
+ }
+ }
+ Component {
+ name: "QAbstractTransition"
+ prototype: "QObject"
+ Property { name: "sourceState"; type: "QState"; isReadonly: true; isPointer: true }
+ Property { name: "targetState"; type: "QAbstractState"; isPointer: true }
+ Property { name: "targetStates"; type: "QList<QAbstractState*>" }
+ Signal { name: "triggered" }
+ }
+ Component { name: "QFinalState"; prototype: "QAbstractState" }
+ Component {
+ name: "QHistoryState"
+ prototype: "QAbstractState"
+ exports: ["QtQml.StateMachine/HistoryState 1.0"]
+ exportMetaObjectRevisions: [0]
+ Enum {
+ name: "HistoryType"
+ values: {
+ "ShallowHistory": 0,
+ "DeepHistory": 1
+ }
+ }
+ Property { name: "defaultState"; type: "QAbstractState"; isPointer: true }
+ Property { name: "historyType"; type: "HistoryType" }
+ }
+ Component {
+ name: "QSignalTransition"
+ prototype: "QAbstractTransition"
+ exports: ["QtQml.StateMachine/QSignalTransition 1.0"]
+ isCreatable: false
+ exportMetaObjectRevisions: [0]
+ Property { name: "senderObject"; type: "QObject"; isPointer: true }
+ Property { name: "signal"; type: "QByteArray" }
+ }
+ Component {
+ name: "QState"
+ prototype: "QAbstractState"
+ exports: ["QtQml.StateMachine/QState 1.0"]
+ isCreatable: false
+ exportMetaObjectRevisions: [0]
+ Enum {
+ name: "ChildMode"
+ values: {
+ "ExclusiveStates": 0,
+ "ParallelStates": 1
+ }
+ }
+ Enum {
+ name: "RestorePolicy"
+ values: {
+ "DontRestoreProperties": 0,
+ "RestoreProperties": 1
+ }
+ }
+ Property { name: "initialState"; type: "QAbstractState"; isPointer: true }
+ Property { name: "errorState"; type: "QAbstractState"; isPointer: true }
+ Property { name: "childMode"; type: "ChildMode" }
+ Signal { name: "finished" }
+ Signal { name: "propertiesAssigned" }
+ }
+ Component {
+ name: "QStateMachine"
+ prototype: "QState"
+ Property { name: "errorString"; type: "string"; isReadonly: true }
+ Property { name: "globalRestorePolicy"; type: "QState::RestorePolicy" }
+ Property { name: "running"; type: "bool" }
+ Property { name: "animated"; type: "bool" }
+ Signal { name: "started" }
+ Signal { name: "stopped" }
+ Signal {
+ name: "runningChanged"
+ Parameter { name: "running"; type: "bool" }
+ }
+ Method { name: "start" }
+ Method { name: "stop" }
+ Method {
+ name: "setRunning"
+ Parameter { name: "running"; type: "bool" }
+ }
+ }
+ Component {
+ name: "QTimer"
+ prototype: "QObject"
+ Property { name: "singleShot"; type: "bool" }
+ Property { name: "interval"; type: "int" }
+ Property { name: "remainingTime"; type: "int"; isReadonly: true }
+ Property { name: "timerType"; type: "Qt::TimerType" }
+ Property { name: "active"; type: "bool"; isReadonly: true }
+ Signal { name: "timeout" }
+ Method {
+ name: "start"
+ Parameter { name: "msec"; type: "int" }
+ }
+ Method { name: "start" }
+ Method { name: "stop" }
+ }
+ Component {
+ name: "SignalTransition"
+ prototype: "QSignalTransition"
+ exports: ["QtQml.StateMachine/SignalTransition 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "signal"; type: "QJSValue" }
+ Property { name: "guard"; type: "bool" }
+ Signal { name: "invokeYourself" }
+ Signal { name: "qmlSignalChanged" }
+ Method { name: "invoke" }
+ }
+ Component {
+ name: "StateBase"
+ defaultProperty: "children"
+ prototype: "QState"
+ exports: ["QtQml.StateMachine/StateBase 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "children"; type: "QObject"; isList: true; isReadonly: true }
+ }
+ Component {
+ name: "StateMachine"
+ defaultProperty: "children"
+ prototype: "QStateMachine"
+ exports: ["QtQml.StateMachine/StateMachine 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "children"; type: "QObject"; isList: true; isReadonly: true }
+ Property { name: "running"; type: "bool" }
+ Signal { name: "qmlRunningChanged" }
+ }
+ Component {
+ name: "TimeoutTransition"
+ prototype: "QSignalTransition"
+ exports: ["QtQml.StateMachine/TimeoutTransition 1.0"]
+ exportMetaObjectRevisions: [0]
+ Property { name: "timeout"; type: "int" }
+ }
+}
diff --git a/src/imports/statemachine/qmldir b/src/imports/statemachine/qmldir
new file mode 100644
index 0000000000..8bc3831208
--- /dev/null
+++ b/src/imports/statemachine/qmldir
@@ -0,0 +1,4 @@
+module QtQml.StateMachine
+plugin qtqmlstatemachine
+classname QtQmlStateMachinePlugin
+typeinfo plugins.qmltypes
diff --git a/src/imports/statemachine/signaltransition.cpp b/src/imports/statemachine/signaltransition.cpp
new file mode 100644
index 0000000000..c3dc183472
--- /dev/null
+++ b/src/imports/statemachine/signaltransition.cpp
@@ -0,0 +1,238 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "signaltransition.h"
+
+#include <QStateMachine>
+#include <QMetaProperty>
+#include <QQmlInfo>
+#include <QQmlEngine>
+#include <QQmlContext>
+
+#include <private/qv4qobjectwrapper_p.h>
+#include <private/qv8engine_p.h>
+#include <private/qjsvalue_p.h>
+#include <private/qv4scopedvalue_p.h>
+
+SignalTransition::SignalTransition(QState *parent)
+ : QSignalTransition(this, SIGNAL(invokeYourself()), parent)
+ , m_guard(true)
+{
+ connect(this, SIGNAL(signalChanged()), SIGNAL(qmlSignalChanged()));
+}
+
+bool SignalTransition::eventTest(QEvent *event)
+{
+ Q_ASSERT(event);
+ if (!QSignalTransition::eventTest(event))
+ return false;
+
+ return m_guard;
+}
+
+const QJSValue& SignalTransition::signal()
+{
+ return m_signal;
+}
+
+void SignalTransition::setSignal(const QJSValue &signal)
+{
+ if (m_signal.strictlyEquals(signal))
+ return;
+
+ m_signal = signal;
+
+ QV4::ExecutionEngine *jsEngine = QV8Engine::getV4(QQmlEngine::contextForObject(this)->engine());
+ QV4::Scope scope(jsEngine);
+
+ QV4::Scoped<QV4::FunctionObject> function(scope, QJSValuePrivate::get(m_signal)->getValue(jsEngine));
+ Q_ASSERT(function);
+
+ QV4::Scoped<QV4::QObjectMethod> qobjectSignal(scope, function->as<QV4::QObjectMethod>());
+ Q_ASSERT(qobjectSignal);
+
+ QObject *sender = qobjectSignal->object();
+ Q_ASSERT(sender);
+ QMetaMethod metaMethod = sender->metaObject()->method(qobjectSignal->methodIndex());
+
+ QSignalTransition::setSenderObject(sender);
+ QSignalTransition::setSignal(metaMethod.methodSignature());
+}
+
+bool SignalTransition::guard() const
+{
+ return m_guard;
+}
+
+void SignalTransition::setGuard(bool guard)
+{
+ if (guard != m_guard) {
+ m_guard = guard;
+ emit guardChanged();
+ }
+}
+
+void SignalTransition::invoke()
+{
+ emit invokeYourself();
+}
+
+/*!
+ \qmltype QAbstractTransition
+ \inqmlmodule QtStateMachine 1.0
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The QAbstractTransition type is the base type of transitions between QAbstractState objects.
+
+ The QAbstractTransition type is the abstract base type of transitions
+ between states (QAbstractState objects) of a StateMachine.
+ QAbstractTransition is part of \l{The Declarative State Machine Framework}.
+
+ The sourceState() property has the source of the transition. The
+ targetState and targetStates properties return the target(s) of the
+ transition.
+
+ The triggered() signal is emitted when the transition has been triggered.
+
+ Do not use QAbstractTransition directly; use SignalTransition or
+ TimeoutTransition instead.
+
+ \sa SignalTransition, TimeoutTransition
+*/
+
+/*!
+ \qmlproperty bool QAbstractTransition::sourceState
+ \readonly sourceState
+
+ \brief The source state (parent) of this transition.
+*/
+
+/*!
+ \qmlproperty QAbstractState QAbstractTransition::targetState
+
+ \brief The target state of this transition.
+
+ If a transition has no target state, the transition may still be
+ triggered, but this will not cause the state machine's configuration to
+ change (i.e. the current state will not be exited and re-entered).
+*/
+
+/*!
+ \qmlproperty list<QAbstractState> QAbstractTransition::targetStates
+
+ \brief The target states of this transition.
+
+ If multiple states are specified, they all must be descendants of the
+ same parallel group state.
+*/
+
+/*!
+ \qmlsignal QAbstractTransition::triggered()
+
+ This signal is emitted when the transition has been triggered.
+
+ The corresponding handler is \c onTriggered.
+*/
+
+/*!
+ \qmltype QSignalTransition
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QAbstractTransition
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The QSignalTransition type provides a transition based on a Qt signal.
+
+ Do not use QSignalTransition directly; use SignalTransition or
+ TimeoutTransition instead.
+
+ \sa SignalTransition, TimeoutTransition
+*/
+
+/*!
+ \qmlproperty string QSignalTransition::signal
+
+ \brief The signal which is associated with this signal transition.
+*/
+
+/*!
+ \qmlproperty QObject QSignalTransition::senderObject
+
+ \brief The sender object which is associated with this signal transition.
+*/
+
+
+/*!
+ \qmltype SignalTransition
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QSignalTransition
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The SignalTransition type provides a transition based on a Qt signal.
+
+ SignalTransition is part of \l{The Declarative State Machine Framework}.
+
+ \section1 Example Usage
+
+ \snippet qml/statemachine/signaltransition.qml document
+
+ \clearfloat
+
+ \sa StateMachine, FinalState, TimeoutTransition
+*/
+
+/*!
+ \qmlproperty signal SignalTransition::signal
+
+ \brief The signal which is associated with this signal transition.
+
+ \snippet qml/statemachine/signaltransitionsignal.qml document
+*/
+
+/*!
+ \qmlproperty bool SignalTransition::guard
+
+ Guard conditions affect the behavior of a state machine by enabling
+ transitions only when they evaluate to true and disabling them when
+ they evaluate to false.
+*/
diff --git a/src/imports/statemachine/signaltransition.h b/src/imports/statemachine/signaltransition.h
new file mode 100644
index 0000000000..614a6064a5
--- /dev/null
+++ b/src/imports/statemachine/signaltransition.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIGNALTRANSITION_H
+#define SIGNALTRANSITION_H
+
+#include <QtCore/QSignalTransition>
+#include <QtCore/QVariant>
+#include <QtQml/QJSValue>
+
+QT_BEGIN_NAMESPACE
+
+class SignalTransition : public QSignalTransition
+{
+ Q_OBJECT
+ Q_PROPERTY(QJSValue signal READ signal WRITE setSignal NOTIFY qmlSignalChanged)
+ Q_PROPERTY(bool guard READ guard WRITE setGuard NOTIFY guardChanged)
+
+public:
+ explicit SignalTransition(QState *parent = Q_NULLPTR);
+
+ bool guard() const;
+ void setGuard(bool guard);
+
+ bool eventTest(QEvent *event);
+
+ const QJSValue &signal();
+ void setSignal(const QJSValue &signal);
+
+ Q_INVOKABLE void invoke();
+
+Q_SIGNALS:
+ void guardChanged();
+ void invokeYourself();
+ /*!
+ * \internal
+ */
+ void qmlSignalChanged();
+
+private:
+ QByteArray m_data;
+ QJSValue m_signal;
+ bool m_guard;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/imports/statemachine/statebase.cpp b/src/imports/statemachine/statebase.cpp
new file mode 100644
index 0000000000..fa475df604
--- /dev/null
+++ b/src/imports/statemachine/statebase.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "statebase.h"
+
+#include <QQmlContext>
+#include <QQmlEngine>
+#include <QQmlInfo>
+
+StateBase::StateBase(QState *parent)
+ : QState(parent)
+{
+}
+
+void StateBase::componentComplete()
+{
+ if (this->machine() == NULL) {
+ static bool once = false;
+ if (!once) {
+ once = true;
+ qmlInfo(this) << "No top level StateMachine found. Nothing will run without a StateMachine.";
+ }
+ }
+}
+
+QQmlListProperty<QObject> StateBase::children()
+{
+ return QQmlListProperty<QObject>(this, &m_children, m_children.append, m_children.count, m_children.at, m_children.clear);
+}
+
+/*!
+ \qmltype QAbstractState
+ \inqmlmodule QtStateMachine 1.0
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The QAbstractState type is the base type of States of a StateMachine.
+
+ Do not use QAbstractState directly; use StateBase, FinalState or
+ StateMachine instead.
+
+ \sa StateMachine, StateBase
+*/
+
+/*!
+ \qmlproperty bool QAbstractState::active
+ \readonly active
+
+ The active property of this state. A state is active between
+ entered() and exited() signals. This property is readonly.
+
+ \sa entered, exited
+*/
+
+/*!
+ \qmlsignal QAbstractState::entered()
+
+ This signal is emitted when the State becomes active.
+
+ The corresponding handler is \c onEntered.
+
+ \sa active, exited
+*/
+
+/*!
+ \qmlsignal QAbstractState::exited()
+
+ This signal is emitted when the State becomes inactive.
+
+ The corresponding handler is \c onExited.
+
+ \sa active, entered
+*/
+
+/*!
+ \qmltype StateBase
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QAbstractState
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief Provides a general-purpose state for StateMachine.
+
+
+ StateBase objects can have child states as well as transitions to other
+ states. StateBase is part of \l{The Declarative State Machine Framework}.
+
+ \section1 States with Child States
+
+ The childMode property determines how child states are treated. For
+ non-parallel state groups, the initialState property must be used to
+ set the initial state. The child states are mutually exclusive states,
+ and the state machine needs to know which child state to enter when the
+ parent state is the target of a transition.
+
+ The state emits the StateBase::finished() signal when a final child state
+ (FinalState) is entered.
+
+ The errorState sets the state's error state. The error state is the state
+ that the state machine will transition to if an error is detected when
+ attempting to enter the state (e.g. because no initial state has been set).
+
+ \section1 Example Usage
+
+ \snippet qml/statemachine/basicstate.qml document
+
+ \clearfloat
+
+ \sa StateMachine, FinalState
+*/
+
+/*!
+ \qmlproperty enumeration StateBase::childMode
+
+ \brief The child mode of this state
+
+ The default value of this property is QState.ExclusiveStates.
+
+ This enum specifies how a state's child states are treated:
+ \list
+ \li QState.ExclusiveStates The child states are mutually exclusive and an initial state must be set by setting initialState property.
+ \li QState.ParallelStates The child states are parallel. When the parent state is entered, all its child states are entered in parallel.
+ \endlist
+*/
+
+/*!
+ \qmlproperty QAbstractState StateBase::errorState
+
+ \brief The error state of this state.
+*/
+
+/*!
+ \qmlproperty QAbstractState StateBase::initialState
+
+ \brief The initial state of this state (one of its child states).
+*/
+
+/*!
+ \qmlsignal StateBase::finished()
+
+ This signal is emitted when a final child state of this state is entered.
+
+ The corresponding handler is \c onFinished.
+
+ \sa QAbstractState::active, QAbstractState::entered, QAbstractState::exited
+*/
+
+/*!
+ \qmltype HistoryState
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QAbstractState
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The HistoryState type provides a means of returning to a previously active substate.
+
+ A history state is a pseudo-state that represents the child state that the
+ parent state was in the last time the parent state was exited. A transition
+ with a history state as its target is in fact a transition to one of the
+ other child states of the parent state.
+ HistoryState is part of \l{The Declarative State Machine Framework}.
+
+ Use the defaultState property to set the state that should be entered
+ if the parent state has never been entered.
+
+ \section1 Example Usage
+
+ \snippet qml/statemachine/historystate.qml document
+
+ \clearfloat
+
+ By default, a history state is shallow, meaning that it will not remember
+ nested states. This can be configured through the historyType property.
+
+ \sa StateMachine, StateBase
+*/
+
+/*!
+ \qmlproperty QAbstractState HistoryState::defaultState
+
+ \brief The default state of this history state.
+
+ The default state indicates the state to transition to if the parent
+ state has never been entered before.
+*/
+
+/*!
+ \qmlproperty enumeration HistoryState::historyType
+
+ \brief The type of history that this history state records.
+
+ The default value of this property is QHistoryState.ShallowHistory.
+
+ This enum specifies the type of history that a QHistoryState records.
+ \list
+ \li QHistoryState.ShallowHistory Only the immediate child states of the
+ parent state are recorded. In this case, a transition with the history
+ state as its target will end up in the immediate child state that the
+ parent was in the last time it was exited. This is the default.
+ \li QHistoryState.DeepHistory Nested states are recorded. In this case
+ a transition with the history state as its target will end up in the
+ most deeply nested descendant state the parent was in the last time
+ it was exited.
+ \endlist
+*/
+
diff --git a/src/imports/statemachine/statebase.h b/src/imports/statemachine/statebase.h
new file mode 100644
index 0000000000..e3084238ef
--- /dev/null
+++ b/src/imports/statemachine/statebase.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATE_H
+#define STATE_H
+
+#include "childrenprivate.h"
+
+#include <QtCore/QState>
+#include <QtQml/QQmlParserStatus>
+#include <QtQml/QQmlListProperty>
+
+QT_BEGIN_NAMESPACE
+
+class StateBase : public QState, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_INTERFACES(QQmlParserStatus)
+ Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged)
+ Q_CLASSINFO("DefaultProperty", "children")
+
+public:
+ explicit StateBase(QState *parent = 0);
+
+ void classBegin() {}
+ void componentComplete();
+
+ QQmlListProperty<QObject> children();
+
+Q_SIGNALS:
+ void childrenChanged();
+
+private:
+ ChildrenPrivate<StateBase> m_children;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/imports/statemachine/statemachine.cpp b/src/imports/statemachine/statemachine.cpp
new file mode 100644
index 0000000000..31d98b7094
--- /dev/null
+++ b/src/imports/statemachine/statemachine.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "statemachine.h"
+
+#include <QAbstractTransition>
+#include <QQmlContext>
+#include <QQmlEngine>
+#include <QQmlInfo>
+
+#include <private/qqmlopenmetaobject_p.h>
+#include <private/qqmlengine_p.h>
+
+StateMachine::StateMachine(QObject *parent)
+ : QStateMachine(parent), m_completed(false), m_running(false)
+{
+ connect(this, SIGNAL(runningChanged(bool)), SIGNAL(qmlRunningChanged()));
+}
+
+bool StateMachine::isRunning() const
+{
+ return QStateMachine::isRunning();
+}
+
+void StateMachine::setRunning(bool running)
+{
+ if (m_completed)
+ QStateMachine::setRunning(running);
+ else
+ m_running = running;
+}
+
+void StateMachine::componentComplete()
+{
+ if (QStateMachine::initialState() == NULL && childMode() == QState::ExclusiveStates)
+ qmlInfo(this) << "No initial state set for StateMachine";
+
+ // Everything is proper setup, now start the state-machine if we got
+ // asked to do so.
+ m_completed = true;
+ if (m_running)
+ setRunning(true);
+}
+
+QQmlListProperty<QObject> StateMachine::children()
+{
+ return QQmlListProperty<QObject>(this, &m_children, m_children.append, m_children.count, m_children.at, m_children.clear);
+}
+
+/*!
+ \qmltype StateMachine
+ \inqmlmodule QtStateMachine 1.0
+ \inherits StateBase
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief Provides a hierarchical finite state machine.
+
+ StateMachine is based on the concepts and notation of
+ \l{http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf}{Statecharts}.
+ StateMachine is part of \l{The Declarative State Machine Framework}.
+
+ A state machine manages a set of states and transitions between those
+ states; these states and transitions define a state graph. Once a state
+ graph has been built, the state machine can execute it. StateMachine's
+ execution algorithm is based on the \l{http://www.w3.org/TR/scxml/}{State Chart XML (SCXML)}
+ algorithm. The framework's \l{The Declarative State Machine Framework}{overview}
+ gives several state graphs and the code to build them.
+
+ Before the machine can be started, the \l{StateBase::initialState}{initialState}
+ must be set. The initial state is the state that the
+ machine enters when started. You can then set running property to true
+ or start() the state machine. The started signal is emitted when the
+ initial state is entered.
+
+ The state machine processes events and takes transitions until a
+ top-level final state is entered; the state machine then emits the
+ finished() signal. You can also stop() the state machine
+ explicitly (you can also set running property to false).
+ The stopped signal is emitted in this case.
+
+ \section1 Example Usage
+ The following snippet shows a state machine that will finish when a button
+ is clicked:
+
+ \snippet qml/statemachine/simplestatemachine.qml document
+
+ If an error is encountered, the machine will look for an
+ \l{StateBase::errorState}{errorState}, and if one is available, it will
+ enter this state. After the error state is entered, the type of the error
+ can be retrieved with error(). The execution of the state graph will not
+ stop when the error state is entered. If no error state applies to the
+ erroneous state, the machine will stop executing and an error message will
+ be printed to the console.
+
+ \clearfloat
+
+ \sa QAbstractState, StateBase, SignalTransition, TimeoutTransition, HistoryState {The Declarative State Machine Framework}
+*/
+
+/*!
+ \qmlproperty enumeration StateMachine::globalRestorePolicy
+
+ \brief The restore policy for states of this state machine.
+
+ The default value of this property is QState.DontRestoreProperties.
+
+ This enum specifies the restore policy type. The restore policy
+ takes effect when the machine enters a state which sets one or more
+ properties. If the restore policy is set to QState.RestoreProperties,
+ the state machine will save the original value of the property before the
+ new value is set.
+
+ Later, when the machine either enters a state which does not set a
+ value for the given property, the property will automatically be restored
+ to its initial value.
+
+ Only one initial value will be saved for any given property. If a value
+ for a property has already been saved by the state machine, it will not be
+ overwritten until the property has been successfully restored.
+
+ \list
+ \li QState.DontRestoreProperties The state machine should not save the initial values of properties and restore them later.
+ \li QState.RestoreProperties The state machine should save the initial values of properties and restore them later.
+ \endlist
+*/
+
+/*!
+ \qmlproperty bool StateMachine::running
+
+ \brief The running state of this state machine.
+ \sa start(), stop()
+*/
+
+/*!
+ \qmlproperty string StateMachine::errorString
+ \readonly errorString
+
+ \brief The error string of this state machine.
+*/
+
+
+/*!
+ \qmlmethod StateMachine::start()
+
+ Starts this state machine. The machine will reset its configuration and
+ transition to the initial state. When a final top-level state (FinalState)
+ is entered, the machine will emit the finished() signal.
+
+ \note A state machine will not run without a running event loop, such as
+ the main application event loop started with QCoreApplication::exec() or
+ QApplication::exec().
+
+ \sa started, StateBase::finished, stop(), StateBase::initialState, running
+*/
+
+/*!
+ \qmlsignal StateMachine::started()
+
+ This signal is emitted when the state machine has entered its initial state
+ (StateBase::initialState).
+
+ The corresponding handler is \c onStarted.
+
+ \sa running, start(), StateBase::finished
+*/
+
+/*!
+ \qmlmethod StateMachine::stop()
+
+ Stops this state machine. The state machine will stop processing events
+ and then emit the stopped signal.
+
+ \sa stopped, start(), running
+*/
+
+/*!
+ \qmlsignal StateMachine::stopped()
+
+ This signal is emitted when the state machine has stopped.
+
+ The corresponding handler is \c onStopped.
+
+ \sa running, stop(), StateBase::finished
+*/
diff --git a/src/imports/statemachine/statemachine.h b/src/imports/statemachine/statemachine.h
new file mode 100644
index 0000000000..5bce986230
--- /dev/null
+++ b/src/imports/statemachine/statemachine.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATEMACHINE_H
+#define STATEMACHINE_H
+
+#include "childrenprivate.h"
+
+#include <QtCore/QStateMachine>
+#include <QtQml/QQmlParserStatus>
+#include <QtQml/QQmlListProperty>
+
+QT_BEGIN_NAMESPACE
+
+class QQmlOpenMetaObject;
+
+class StateMachine : public QStateMachine, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_INTERFACES(QQmlParserStatus)
+ Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged)
+
+ // Override to delay execution after componentComplete()
+ Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY qmlRunningChanged)
+
+ Q_CLASSINFO("DefaultProperty", "children")
+
+public:
+ explicit StateMachine(QObject *parent = 0);
+
+ void classBegin() {}
+ void componentComplete();
+ QQmlListProperty<QObject> children();
+
+ bool isRunning() const;
+ void setRunning(bool running);
+
+Q_SIGNALS:
+ void childrenChanged();
+ /*!
+ * \internal
+ */
+ void qmlRunningChanged();
+
+private:
+ ChildrenPrivate<StateMachine> m_children;
+ bool m_completed;
+ bool m_running;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/imports/statemachine/statemachine.pro b/src/imports/statemachine/statemachine.pro
new file mode 100644
index 0000000000..4cc7089a32
--- /dev/null
+++ b/src/imports/statemachine/statemachine.pro
@@ -0,0 +1,24 @@
+CXX_MODULE = qml
+TARGET = qtqmlstatemachine
+TARGETPATH = QtQml/StateMachine
+IMPORT_VERSION = 1.0
+
+QT = core-private qml-private
+
+SOURCES = \
+ $$PWD/finalstate.cpp \
+ $$PWD/signaltransition.cpp \
+ $$PWD/statebase.cpp \
+ $$PWD/statemachine.cpp \
+ $$PWD/timeouttransition.cpp \
+ $$PWD/plugin.cpp
+
+HEADERS = \
+ $$PWD/childrenprivate.h \
+ $$PWD/finalstate.h \
+ $$PWD/signaltransition.h \
+ $$PWD/statebase.h \
+ $$PWD/statemachine.h \
+ $$PWD/timeouttransition.h
+
+load(qml_plugin)
diff --git a/src/imports/statemachine/timeouttransition.cpp b/src/imports/statemachine/timeouttransition.cpp
new file mode 100644
index 0000000000..eb946e38ad
--- /dev/null
+++ b/src/imports/statemachine/timeouttransition.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "timeouttransition.h"
+
+#include <QQmlInfo>
+#include <QTimer>
+#include <QState>
+
+TimeoutTransition::TimeoutTransition(QState* parent)
+ : QSignalTransition((m_timer = new QTimer), SIGNAL(timeout()), parent)
+{
+ m_timer->setSingleShot(true);
+ m_timer->setInterval(1000);
+}
+
+TimeoutTransition::~TimeoutTransition()
+{
+ delete m_timer;
+}
+
+int TimeoutTransition::timeout() const
+{
+ return m_timer->interval();
+}
+
+void TimeoutTransition::setTimeout(int timeout)
+{
+ if (timeout != m_timer->interval()) {
+ m_timer->setInterval(timeout);
+ emit timeoutChanged();
+ }
+}
+
+void TimeoutTransition::componentComplete()
+{
+ QState *state = qobject_cast<QState*>(parent());
+ if (!state) {
+ qmlInfo(this) << "Parent needs to be a State";
+ return;
+ }
+
+ connect(state, SIGNAL(entered()), m_timer, SLOT(start()));
+ connect(state, SIGNAL(exited()), m_timer, SLOT(stop()));
+ if (state->active())
+ m_timer->start();
+}
+
+/*!
+ \qmltype TimeoutTransition
+ \inqmlmodule QtStateMachine 1.0
+ \inherits QSignalTransition
+ \ingroup qmlstatemachine
+ \since 5.4
+
+ \brief The TimeoutTransition type provides a transition based on a timer.
+
+ \l{Timer} type can be combined with SignalTransition to enact more complex
+ timeout based transitions.
+
+ TimeoutTransition is part of \l{The Declarative State Machine Framework}.
+
+ \section1 Example Usage
+
+ \snippet qml/statemachine/timeouttransition.qml document
+
+ \clearfloat
+
+ \sa StateMachine, SignalTransition, FinalState, HistoryState
+*/
+
+/*!
+ \qmlproperty int TimeoutTransition::timeout
+
+ \brief The timeout interval in milliseconds.
+*/
diff --git a/src/imports/statemachine/timeouttransition.h b/src/imports/statemachine/timeouttransition.h
new file mode 100644
index 0000000000..9b166f8886
--- /dev/null
+++ b/src/imports/statemachine/timeouttransition.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TIMEOUTTRANSITION_H
+#define TIMEOUTTRANSITION_H
+
+#include <QtCore/QSignalTransition>
+#include <QtQml/QQmlParserStatus>
+
+QT_BEGIN_NAMESPACE
+class QTimer;
+
+class TimeoutTransition : public QSignalTransition, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged)
+ Q_INTERFACES(QQmlParserStatus)
+
+public:
+ TimeoutTransition(QState *parent = Q_NULLPTR);
+ ~TimeoutTransition();
+
+ int timeout() const;
+ void setTimeout(int timeout);
+
+ void classBegin() {}
+ void componentComplete();
+
+Q_SIGNALS:
+ void timeoutChanged();
+
+private:
+ QTimer *m_timer;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/qml/doc/images/statemachine-button-history.png b/src/qml/doc/images/statemachine-button-history.png
new file mode 100644
index 0000000000..0462b3b99b
--- /dev/null
+++ b/src/qml/doc/images/statemachine-button-history.png
Binary files differ
diff --git a/src/qml/doc/images/statemachine-button-nested.png b/src/qml/doc/images/statemachine-button-nested.png
new file mode 100644
index 0000000000..762ac14df1
--- /dev/null
+++ b/src/qml/doc/images/statemachine-button-nested.png
Binary files differ
diff --git a/src/qml/doc/images/statemachine-button.png b/src/qml/doc/images/statemachine-button.png
new file mode 100644
index 0000000000..10102bdf2c
--- /dev/null
+++ b/src/qml/doc/images/statemachine-button.png
Binary files differ
diff --git a/src/qml/doc/images/statemachine-finished.png b/src/qml/doc/images/statemachine-finished.png
new file mode 100644
index 0000000000..0ac081d6ba
--- /dev/null
+++ b/src/qml/doc/images/statemachine-finished.png
Binary files differ
diff --git a/src/qml/doc/images/statemachine-nonparallel.png b/src/qml/doc/images/statemachine-nonparallel.png
new file mode 100644
index 0000000000..f9850a74a6
--- /dev/null
+++ b/src/qml/doc/images/statemachine-nonparallel.png
Binary files differ
diff --git a/src/qml/doc/images/statemachine-parallel.png b/src/qml/doc/images/statemachine-parallel.png
new file mode 100644
index 0000000000..a65c297f5b
--- /dev/null
+++ b/src/qml/doc/images/statemachine-parallel.png
Binary files differ
diff --git a/src/qml/doc/qtqml.qdocconf b/src/qml/doc/qtqml.qdocconf
index 418a330d2c..6e07fd173b 100644
--- a/src/qml/doc/qtqml.qdocconf
+++ b/src/qml/doc/qtqml.qdocconf
@@ -40,7 +40,8 @@ headerdirs += .. \
../../imports/models
sourcedirs += .. \
- ../../imports/models
+ ../../imports/models \
+ ../../imports/statemachine
exampledirs += ../../../examples/qml \
../ \
diff --git a/src/qml/doc/snippets/qml/statemachine/Button.qml b/src/qml/doc/snippets/qml/statemachine/Button.qml
new file mode 100644
index 0000000000..2baad4cbfb
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/Button.qml
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.1
+import QtQuick.Window 2.1
+
+Item {
+ id: container
+
+ property alias text: buttonLabel.text
+ property alias label: buttonLabel
+ signal clicked
+ property alias containsMouse: mouseArea.containsMouse
+ property alias pressed: mouseArea.pressed
+ implicitHeight: Math.max(Screen.pixelDensity * 7, buttonLabel.implicitHeight * 1.2)
+ implicitWidth: Math.max(Screen.pixelDensity * 11, buttonLabel.implicitWidth * 1.3)
+ height: implicitHeight
+ width: implicitWidth
+ property bool checkable: false
+ property bool checked: false
+
+ SystemPalette { id: palette }
+
+ Rectangle {
+ id: frame
+ anchors.fill: parent
+ color: palette.button
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: mouseArea.pressed ? Qt.darker(palette.button, 1.3) : palette.button }
+ GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) }
+ }
+ antialiasing: true
+ radius: height / 6
+ border.color: Qt.darker(palette.button, 1.5)
+ border.width: 1
+ }
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ onClicked: container.clicked()
+ hoverEnabled: true
+ }
+
+ Text {
+ id: buttonLabel
+ text: container.text
+ color: palette.buttonText
+ anchors.centerIn: parent
+ }
+}
diff --git a/src/qml/doc/snippets/qml/statemachine/basicstate.qml b/src/qml/doc/snippets/qml/statemachine/basicstate.qml
new file mode 100644
index 0000000000..dd9d100e9d
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/basicstate.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ StateBase {
+ id: state
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/finalstate.qml b/src/qml/doc/snippets/qml/statemachine/finalstate.qml
new file mode 100644
index 0000000000..d03a4bce40
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/finalstate.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ StateBase {
+ id: state
+ TimeoutTransition {
+ targetState: finalState
+ timeout: 200
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ onFinished: console.log("state finished")
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/historystate.qml b/src/qml/doc/snippets/qml/statemachine/historystate.qml
new file mode 100644
index 0000000000..237cf57175
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/historystate.qml
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Press me"
+ StateMachine {
+ id: stateMachine
+ initialState: parentState
+ running: true
+ StateBase {
+ id: parentState
+ initialState: child2
+ onEntered: console.log("parentState entered")
+ onExited: console.log("parentState exited")
+ StateBase {
+ id: child1
+ onEntered: console.log("child1 entered")
+ onExited: console.log("child1 exited")
+ }
+ StateBase {
+ id: child2
+ onEntered: console.log("child2 entered")
+ onExited: console.log("child2 exited")
+ }
+ HistoryState {
+ id: historyState
+ defaultState: child1
+ }
+ SignalTransition {
+ targetState: historyState
+
+ // Clicking the button will cause the state machine to enter the child state
+ // that parentState was in the last time parentState was exited, or the history state's default
+ // state if parentState has never been entered.
+ signal: button.clicked
+ }
+ }
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/signaltransition.qml b/src/qml/doc/snippets/qml/statemachine/signaltransition.qml
new file mode 100644
index 0000000000..7402ac089f
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/signaltransition.qml
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ StateBase {
+ id: state
+ SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ guard: guardButton.checked
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ onFinished: Qt.quit()
+ }
+ Row {
+ spacing: 2
+ Button {
+ id: button
+ text: "Finish state"
+ }
+
+ Button {
+ id: guardButton
+ checkable: true
+ text: checked ? "Press to block the SignalTransition" : "Press to unblock the SignalTransition"
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/signaltransitionsignal.qml b/src/qml/doc/snippets/qml/statemachine/signaltransitionsignal.qml
new file mode 100644
index 0000000000..44608fed36
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/signaltransitionsignal.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ StateMachine {
+ StateBase {
+ SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/simplestatemachine.qml b/src/qml/doc/snippets/qml/statemachine/simplestatemachine.qml
new file mode 100644
index 0000000000..f5c6923cd1
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/simplestatemachine.qml
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Finish state"
+ StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ StateBase {
+ id: state
+ SignalTransition {
+ targetState: finalState
+ signal: button.clicked
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ onFinished: Qt.quit()
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/statemachine-button-history.qml b/src/qml/doc/snippets/qml/statemachine/statemachine-button-history.qml
new file mode 100644
index 0000000000..10595a9398
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/statemachine-button-history.qml
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+//![0]
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : s13.active ? "s13" : "s3"
+ }
+ Button {
+ id: interruptButton
+ text: s1.active ? "Interrupt" : "Resume"
+ }
+ Button {
+ id: quitButton
+ // change the button label to the active state id
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ StateBase {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ StateBase {
+ id: s11
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+ StateBase {
+ id: s12
+ // create a transition from s2 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+ StateBase {
+ id: s13
+ // create a transition from s3 to s1 when the button is clicked
+ SignalTransition {
+ targetState: s1
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+
+ // create a transition from s1 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s3
+ signal: interruptButton.clicked
+ }
+ HistoryState {
+ id: s1h
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ StateBase {
+ id: s3
+ SignalTransition {
+ targetState: s1h
+ signal: interruptButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s3 entered")
+ onExited: console.log("s3 exited")
+ }
+ onFinished: Qt.quit()
+ }
+//![0]
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml b/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml
new file mode 100644
index 0000000000..00f9cd3871
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested-ignore-quit.qml
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : "s13"
+ }
+ Button {
+ id: quitButton
+ // change the button label to the active state id
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ StateBase {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ StateBase {
+ id: s11
+ // create a transition from s11 to s12 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+//![0]
+ StateBase {
+ id: s12
+ // create a transition from s12 to s13 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+
+ // ignore Quit button when we are in state 12
+ SignalTransition {
+ targetState: s12
+ signal: quitButton.clicked
+ }
+
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+//![0]
+
+ StateBase {
+ id: s13
+ // create a transition from s13 to s11 when the button is clicked
+ SignalTransition {
+ targetState: s11
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ onFinished: Qt.quit()
+ }
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested.qml b/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested.qml
new file mode 100644
index 0000000000..68bd57d85f
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/statemachine-button-nested.qml
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+//![0]
+ Row {
+ anchors.fill: parent
+ spacing: 2
+ Button {
+ id: button
+ // change the button label to the active state id
+ text: s11.active ? "s11" : s12.active ? "s12" : "s13"
+ }
+ Button {
+ id: quitButton
+ // change the button label to the active state id
+ text: "quit"
+ }
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ StateBase {
+ id: s1
+ // set the initial state
+ initialState: s11
+
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: quitButton.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ StateBase {
+ id: s11
+ // create a transition from s11 to s12 when the button is clicked
+ SignalTransition {
+ targetState: s12
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s11 entered")
+ onExited: console.log("s11 exited")
+ }
+
+ StateBase {
+ id: s12
+ // create a transition from s12 to s13 when the button is clicked
+ SignalTransition {
+ targetState: s13
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s12 entered")
+ onExited: console.log("s12 exited")
+ }
+ StateBase {
+ id: s13
+ // create a transition from s13 to s11 when the button is clicked
+ SignalTransition {
+ targetState: s11
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s13 entered")
+ onExited: console.log("s13 exited")
+ }
+ }
+ FinalState {
+ id: s2
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ onFinished: Qt.quit()
+ }
+//![0]
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/statemachine-button.qml b/src/qml/doc/snippets/qml/statemachine/statemachine-button.qml
new file mode 100644
index 0000000000..f2817ead8b
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/statemachine-button.qml
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+//![0]
+ Button {
+ anchors.fill: parent
+ id: button
+
+ // change the button label to the active state id
+ text: s1.active ? "s1" : s2.active ? "s2" : "s3"
+ }
+
+ StateMachine {
+ id: stateMachine
+ // set the initial state
+ initialState: s1
+
+ // start the state machine
+ running: true
+
+ StateBase {
+ id: s1
+ // create a transition from s1 to s2 when the button is clicked
+ SignalTransition {
+ targetState: s2
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s1 entered")
+ onExited: console.log("s1 exited")
+ }
+
+ StateBase {
+ id: s2
+ // create a transition from s2 to s3 when the button is clicked
+ SignalTransition {
+ targetState: s3
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s2 entered")
+ onExited: console.log("s2 exited")
+ }
+ StateBase {
+ id: s3
+ // create a transition from s3 to s1 when the button is clicked
+ SignalTransition {
+ targetState: s1
+ signal: button.clicked
+ }
+ // do something when the state enters/exits
+ onEntered: console.log("s3 entered")
+ onExited: console.log("s3 exited")
+ }
+ }
+//![0]
+}
+//! [document]
diff --git a/src/qml/doc/snippets/qml/statemachine/timeouttransition.qml b/src/qml/doc/snippets/qml/statemachine/timeouttransition.qml
new file mode 100644
index 0000000000..b15c99cd22
--- /dev/null
+++ b/src/qml/doc/snippets/qml/statemachine/timeouttransition.qml
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [document]
+import QtQml.StateMachine 1.0
+import QtQuick 2.0
+
+Rectangle {
+ Button {
+ anchors.fill: parent
+ id: button
+ text: "Finish state"
+ enabled: !stateMachine.running
+ onClicked: stateMachine.running = true
+ StateMachine {
+ id: stateMachine
+ initialState: state
+ running: true
+ StateBase {
+ id: state
+ TimeoutTransition {
+ targetState: finalState
+ timeout: 1000
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ }
+ }
+}
+//! [document]
diff --git a/src/qml/doc/src/qtqml.qdoc b/src/qml/doc/src/qtqml.qdoc
index b9c008edf1..ae2cac7275 100644
--- a/src/qml/doc/src/qtqml.qdoc
+++ b/src/qml/doc/src/qtqml.qdoc
@@ -126,6 +126,11 @@ the QML code to interact with C++ code.
\li \l{Integrating QML and C++}
\endlist
+\section1 Additional Frameworks
+\list
+\li \l{The Declarative State Machine Framework}
+\endlist
+
\section1 Guides and Other Information
Further information for writing QML applications:
diff --git a/src/qml/doc/src/statemachine.qdoc b/src/qml/doc/src/statemachine.qdoc
new file mode 100644
index 0000000000..5a37ef8026
--- /dev/null
+++ b/src/qml/doc/src/statemachine.qdoc
@@ -0,0 +1,317 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \group qmlstatemachine
+ \page qmlstatemachine.html
+ \title The Declarative State Machine Framework
+ \brief An overview of the Declarative State Machine Framework for constructing and executing state graphs.
+
+ \ingroup frameworks-technologies
+
+ \tableofcontents
+
+ The Declarative State Machine Framework provides classes for creating and executing
+ state graphs in QML. The concepts and notation are based on those from Harel's
+ \l{http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf}
+ {Statecharts: A visual formalism for complex systems}, which
+ is also the basis of UML state diagrams. The semantics of state machine
+ execution are based on \l{State Chart XML: State Machine Notation for
+ Control Abstraction}{State Chart XML (SCXML)}.
+
+ Statecharts provide a graphical way of modeling how a system reacts to
+ stimuli. This is done by defining the possible \e states that the system can
+ be in, and how the system can move from one state to another (\e transitions
+ between states). A key characteristic of event-driven systems (such as Qt
+ applications) is that behavior often depends not only on the last or current
+ event, but also the events that preceded it. With statecharts, this
+ information is easy to express.
+
+ The Declarative State Machine Framework provides an API and execution model that can
+ be used to effectively embed the elements and semantics of statecharts in Qml
+ applications. The framework integrates tightly with Qt's meta-object system;
+ for example, transitions between states can be triggered by signals, and
+ states can be configured to set properties and invoke methods on QObjects.
+ Qt's event system is used to drive the state machines.
+
+ The state graph in the Declarative State Machine Framework is hierarchical. States
+ can be nested inside of other states, and the current configuration of the
+ state machine consists of the set of states which are currently active.
+ All the states in a valid configuration of the state machine will
+ have a common ancestor.
+
+ For user interfaces with multiple visual states, independent of the
+ application's logical state, consider using QML States and Transitions.
+
+ \section1 QML types in the Declarative State Machine Framework
+
+ These QML types are provided by QML for creating event-driven state machines.
+
+ \annotatedlist qmlstatemachine
+
+ \section1 A Simple State Machine
+
+ To demonstrate the core functionality of the State Machine API, let's look
+ at a small example: A state machine with three states, \c s1, \c s2 and \c
+ s3. The state machine is controlled by a single QPushButton; when the button
+ is clicked, the machine transitions to another state. Initially, the state
+ machine is in state \c s1. The statechart for this machine is as follows:
+
+ \image statemachine-button.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The following snippet shows the code needed to create such a state machine.
+
+ \snippet qml/statemachine/statemachine-button.qml 0
+
+ The state machine executes asynchronously, i.e. it becomes part of your
+ application's event loop.
+
+ \section1 State Machines That Finish
+
+ The state machine defined in the previous section never finishes. In order
+ for a state machine to be able to finish, it needs to have a top-level \e
+ final state (FinalState object). When the state machine enters a top-level
+ final state, the machine will emit the \l{StateBase::finished}{finished}
+ signal and halt.
+
+ All you need to do to introduce a final state in the graph is create a
+ FinalState object and use it as the target of one or more transitions.
+
+ \section1 Sharing Transitions By Grouping States
+
+ Assume we wanted the user to be able to quit the application at any time by
+ clicking a Quit button. In order to achieve this, we need to create a final
+ state and make it the target of a transition associated with the Quit
+ button's clicked() signal. We could add a transition from each of \c s1, \c
+ s2 and \c s3; however, this seems redundant, and one would also have to
+ remember to add such a transition from every new state that is added in the
+ future.
+
+ We can achieve the same behavior (namely that clicking the Quit button quits
+ the state machine, regardless of which state the state machine is in) by
+ grouping states \c s1, \c s2 and \c s3. This is done by creating a new
+ top-level state and making the three original states children of the new
+ state. The following diagram shows the new state machine.
+
+ \image statemachine-button-nested.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The three original states have been renamed \c s11, \c s12 and \c s13 to
+ reflect that they are now children of the new top-level state, \c s1. Child
+ states implicitly inherit the transitions of their parent state. This means
+ it is now sufficient to add a single transition from \c s1 to the final
+ state \c s2. New states added to \c s1 will also automatically inherit this
+ transition.
+
+ All that's needed to group states is to specify the proper parent when the
+ state is created. You also need to specify which of the child states is the
+ initial one (i.e. which child state the state machine should enter when the
+ parent state is the target of a transition).
+
+ \snippet qml/statemachine/statemachine-button-nested.qml 0
+
+ In this case we want the application to quit when the state machine is
+ finished, so the machine's finished() signal is connected to the
+ application's quit() slot.
+
+ A child state can override an inherited transition. For example, the
+ following code adds a transition that effectively causes the Quit button to
+ be ignored when the state machine is in state \c s12.
+
+ \snippet qml/statemachine/statemachine-button-nested-ignore-quit.qml 0
+
+ A transition can have any state as its target, i.e. the target state does
+ not have to be on the same level in the state hierarchy as the source state.
+
+ \section1 Using History States to Save and Restore the Current State
+
+ Imagine that we wanted to add an "interrupt" mechanism to the example
+ discussed in the previous section; the user should be able to click a button
+ to have the state machine perform some non-related task, after which the
+ state machine should resume whatever it was doing before (i.e. return to the
+ old state, which is one of \c s11, \c s12 and \c s13 in this case).
+
+ Such behavior can easily be modeled using \e{history states}. A history
+ state (HistoryState object) is a pseudo-state that represents the child
+ state that the parent state was in the last time the parent state was
+ exited.
+
+ A history state is created as a child of the state for which we wish to
+ record the current child state; when the state machine detects the presence
+ of such a state at runtime, it automatically records the current (real)
+ child state when the parent state is exited. A transition to the history
+ state is in fact a transition to the child state that the state machine had
+ previously saved; the state machine automatically "forwards" the transition
+ to the real child state.
+
+ The following diagram shows the state machine after the interrupt mechanism
+ has been added.
+
+ \image statemachine-button-history.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The following code shows how it can be implemented; in this example we
+ simply display a message box when \c s3 is entered, then immediately return
+ to the previous child state of \c s1 via the history state.
+
+ \snippet qml/statemachine/statemachine-button-history.qml 0
+
+ \section1 Using Parallel States to Avoid a Combinatorial Explosion of States
+
+ Assume that you wanted to model a set of mutually exclusive properties of a
+ car in a single state machine. Let's say the properties we are interested in
+ are Clean vs Dirty, and Moving vs Not moving. It would take four mutually
+ exclusive states and eight transitions to be able to represent and freely
+ move between all possible combinations.
+
+ \image statemachine-nonparallel.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ If we added a third property (say, Red vs Blue), the total number of states
+ would double, to eight; and if we added a fourth property (say, Enclosed vs
+ Convertible), the total number of states would double again, to 16.
+
+ Using parallel states, the total number of states and transitions grows
+ linearly as we add more properties, instead of exponentially. Furthermore,
+ states can be added to or removed from the parallel state without affecting
+ any of their sibling states.
+
+ \image statemachine-parallel.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ To create a parallel state group, set childMode to QState.ParallelStates.
+
+ \qml
+ StateBase {
+ id: s1
+ childMode: QState.ParallelStates
+ StateBase {
+ id: s11
+ }
+ StateBase {
+ id: s12
+ }
+ }
+ \endqml
+
+ When a parallel state group is entered, all its child states will be
+ simultaneously entered. Transitions within the individual child states
+ operate normally. However, any of the child states may take a transition which exits the parent
+ state. When this happens, the parent state and all of its child states are exited.
+
+ The parallelism in the State Machine framework follows an interleaved semantics. All parallel
+ operations will be executed in a single, atomic step of the event processing, so no event can
+ interrupt the parallel operations. However, events will still be processed sequentially, since
+ the machine itself is single threaded. As an example: Consider the situation where there are two
+ transitions that exit the same parallel state group, and their conditions become true
+ simultaneously. In this case, the event that is processed last of the two will not have any
+ effect, since the first event will already have caused the machine to exit from the parallel
+ state.
+
+ \section1 Detecting that a Composite State has Finished
+
+ A child state can be final (a FinalState object); when a final child state
+ is entered, the parent state emits the StateBase::finished signal. The
+ following diagram shows a composite state \c s1 which does some processing
+ before entering a final state:
+
+ \image statemachine-finished.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ When \c s1 's final state is entered, \c s1 will automatically emit
+ \l{StateBase::finished}{finished}. We use a signal transition to cause this event to
+ trigger a state change:
+
+ \qml
+ StateBase {
+ id: s1
+ SignalTransition {
+ targetState: s2
+ signal: s1.finished
+ }
+ }
+ \endqml
+
+ Using final states in composite states is useful when you want to hide the
+ internal details of a composite state; i.e. the only thing the outside world
+ should be able to do is enter the state, and get a notification when the
+ state has completed its work. This is a very powerful abstraction and
+ encapsulation mechanism when building complex (deeply nested) state
+ machines. (In the above example, you could of course create a transition
+ directly from \c s1 's \c done state rather than relying on \c s1 's
+ finished() signal, but with the consequence that implementation details of
+ \c s1 are exposed and depended on).
+
+ For parallel state groups, the StateBase::finished signal is emitted when \e
+ all the child states have entered final states.
+
+ \section1 Targetless Transitions
+
+ A transition need not have a target state. A transition without a target can
+ be triggered the same way as any other transition; the difference is that
+ when a targetless transition is triggered, it doesn't cause any state
+ changes. This allows you to react to a signal or event when your machine is
+ in a certain state, without having to leave that state. Example:
+
+ \qml
+ Button {
+ id: button
+ text: "button"
+ StateMachine {
+ id: stateMachine
+ initialState: s1
+ running: true
+ StateBase {
+ id: s1
+ SignalTransition {
+ signal: button.clicked
+ onTriggered: console.log("button pressed")
+ }
+ }
+ }
+ }
+ \endqml
+
+ The "button pressed" message will be displayed each time the button is clicked, but the
+ state machine will remain in its current state (s1). If the target state
+ were explicitly set to s1, however, s1 would be exited and re-entered each
+ time (e.g. the QAbstractState::entered and QAbstractState::exited
+ signals would be emitted).
+*/
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index a774917713..f60640c9fa 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -123,7 +123,7 @@ private:
static ReturnedValue method_disconnect(CallContext *ctx);
};
-struct QObjectMethod : public QV4::FunctionObject
+struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject
{
struct Data : QV4::FunctionObject::Data {
Data(QV4::ExecutionContext *scope, QObject *object, int index, const ValueRef qmlGlobal);
diff --git a/tests/auto/qmltest/statemachine/tst_anonymousstate.qml b/tests/auto/qmltest/statemachine/tst_anonymousstate.qml
new file mode 100644
index 0000000000..cd20f67c20
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_anonymousstate.qml
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+ StateMachine {
+ StateBase {
+ }
+ }
+ name: "anonymousState"
+ // no real tests, just make sure it runs
+}
diff --git a/tests/auto/qmltest/statemachine/tst_historystate.qml b/tests/auto/qmltest/statemachine/tst_historystate.qml
new file mode 100644
index 0000000000..86e63af5b0
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_historystate.qml
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+
+ StateMachine {
+ id: stateMachine
+ initialState: historyState1
+
+ StateBase {
+ id: state1
+ SignalTransition {
+ id: st1
+ targetState: state2
+ }
+ }
+
+ StateBase {
+ id: state2
+ initialState: historyState2
+ HistoryState {
+ id: historyState2
+ defaultState: state21
+ }
+ StateBase {
+ id: state21
+ }
+ }
+
+ HistoryState {
+ id: historyState1
+ defaultState: state1
+ }
+ }
+
+ SignalSpy {
+ id: state1SpyActive
+ target: state1
+ signalName: "activeChanged"
+ }
+
+ SignalSpy {
+ id: state2SpyActive
+ target: state2
+ signalName: "activeChanged"
+ }
+
+
+ function test_historyStateAsInitialState()
+ {
+ stateMachine.start();
+ tryCompare(stateMachine, "running", true);
+ tryCompare(state1SpyActive, "count" , 1);
+ tryCompare(state2SpyActive, "count" , 0);
+ st1.invoke();
+ tryCompare(state1SpyActive, "count" , 2);
+ tryCompare(state2SpyActive, "count" , 1);
+ tryCompare(state21, "active", true);
+ tryCompare(state1, "active", false);
+ }
+}
diff --git a/tests/auto/qmltest/statemachine/tst_initialstate.qml b/tests/auto/qmltest/statemachine/tst_initialstate.qml
new file mode 100644
index 0000000000..660bfcb327
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_initialstate.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+ StateMachine {
+ id: myStateMachine
+ initialState: myState;
+ running: true
+ StateBase {
+ id: myState
+ }
+ }
+
+ name: "initialStateTest"
+ function test_initialState() {
+ tryCompare(myStateMachine, "running", true);
+ compare(myState.active, true);
+ myStateMachine.running = false;
+ tryCompare(myStateMachine, "running", false);
+ myStateMachine.running = true;
+ tryCompare(myStateMachine, "running", true);
+ tryCompare(myState, "active", true);
+ }
+}
diff --git a/tests/auto/qmltest/statemachine/tst_nestedinitialstates.qml b/tests/auto/qmltest/statemachine/tst_nestedinitialstates.qml
new file mode 100644
index 0000000000..60230f1e86
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_nestedinitialstates.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+ StateMachine {
+ id: myStateMachine
+ initialState: parentState
+ StateBase {
+ id: parentState
+ initialState: childState1
+ StateBase {
+ id: childState1
+ }
+ StateBase {
+ id: childState2
+ }
+ }
+ }
+ name: "nestedInitalStates"
+
+ function test_nestedInitalStates() {
+ // uncomment me after vm problems are fixed.
+ // compare(myStateMachine.running, false);
+ compare(parentState.active, false);
+ compare(childState1.active, false);
+ compare(childState2.active, false);
+ myStateMachine.start();
+ tryCompare(myStateMachine, "running", true);
+ tryCompare(parentState, "active", true);
+ tryCompare(childState1, "active", true);
+ compare(childState2.active, false);
+ }
+}
diff --git a/tests/auto/qmltest/statemachine/tst_parallelmachine.qml b/tests/auto/qmltest/statemachine/tst_parallelmachine.qml
new file mode 100644
index 0000000000..99ef49860c
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_parallelmachine.qml
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+ StateMachine {
+ id: myStateMachine
+ childMode: StateBase.ParallelStates
+ StateBase {
+ id: childState1
+ childMode: StateBase.ParallelStates
+ StateBase {
+ id: childState11
+ }
+ StateBase {
+ id: childState12
+ }
+ }
+ StateBase {
+ id: childState2
+ initialState: childState21
+ StateBase {
+ id: childState21
+ }
+ StateBase {
+ id: childState22
+ }
+ }
+ }
+ name: "nestedParallelMachineStates"
+
+ function test_nestedInitalStates() {
+ // uncomment me after vm problems are fixed.
+ // compare(myStateMachine.running, false);
+ compare(childState1.active, false);
+ compare(childState11.active, false);
+ compare(childState12.active, false);
+ compare(childState2.active, false);
+ compare(childState21.active, false);
+ compare(childState22.active, false);
+ myStateMachine.start();
+ tryCompare(myStateMachine, "running", true);
+ tryCompare(childState1, "active", true);
+ tryCompare(childState11, "active", true);
+ tryCompare(childState12, "active", true);
+ tryCompare(childState2, "active", true);
+ tryCompare(childState21, "active", true);
+ tryCompare(childState22, "active", false);
+ }
+}
diff --git a/tests/auto/qmltest/statemachine/tst_trafficlight.qml b/tests/auto/qmltest/statemachine/tst_trafficlight.qml
new file mode 100644
index 0000000000..7b02cd0597
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_trafficlight.qml
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.StateMachine 1.0
+import QtTest 1.0
+
+TestCase {
+ StateMachine {
+ id: machine
+ initialState: red
+ FinalState {
+ id: finalState
+ }
+
+ StateBase {
+ id: red
+ initialState: justRed
+ StateBase {
+ id: justRed
+ SignalTransition {
+ id: e1
+ targetState: waitingForGreen
+ }
+ SignalTransition {
+ id: finalSignal
+ targetState: finalState
+ }
+ }
+ StateBase {
+ id: waitingForGreen
+ TimeoutTransition {
+ id: e2
+ targetState: yellowred
+ timeout: 30
+ }
+ }
+ }
+ StateBase {
+ id: yellowred
+ TimeoutTransition {
+ id: e3
+ targetState: green
+ timeout: 10
+ }
+ }
+ StateBase {
+ id: green
+ TimeoutTransition {
+ id: e4
+ targetState: yellow
+ timeout: 50
+ }
+ }
+ StateBase {
+ id: yellow
+ TimeoutTransition {
+ id: e5
+ targetState: red
+ timeout: 10
+ }
+ }
+ }
+
+ SignalSpy {
+ id: machineSpyRunning
+ target: machine
+ signalName: "runningChanged"
+ }
+
+ SignalSpy {
+ id: redSpyActive
+ target: red
+ signalName: "activeChanged"
+ }
+
+ SignalSpy {
+ id: yellowredSpyActive
+ target: yellowred
+ signalName: "activeChanged"
+ }
+
+ SignalSpy {
+ id: greenSpyActive
+ target: green
+ signalName: "activeChanged"
+ }
+
+ SignalSpy {
+ id: yellowSpyActive
+ target: yellow
+ signalName: "activeChanged"
+ }
+
+
+ name: "testTrafficLight"
+ function test_trafficLight()
+ {
+ var i = 1;
+ machine.start();
+ tryCompare(machine, "running", true);
+ tryCompare(machineSpyRunning, "count", 1);
+ tryCompare(redSpyActive, "count", 1);
+ for (; i <= 5; ++i) {
+ e1.invoke();
+ tryCompare(yellowredSpyActive, "count", i * 2);
+ tryCompare(greenSpyActive, "count", i * 2);
+ tryCompare(redSpyActive, "count", i * 2 + 1);
+ tryCompare(yellowSpyActive, "count", i * 2);
+ }
+ finalSignal.guard = false;
+ finalSignal.invoke();
+ wait(100);
+ tryCompare(machine, "running", true);
+ finalSignal.guard = true;
+ finalSignal.invoke();
+ tryCompare(machine, "running", false);
+ tryCompare(redSpyActive, "count", i * 2);
+ }
+}