diff options
Diffstat (limited to 'src/imports/statemachine')
-rw-r--r-- | src/imports/statemachine/childrenprivate.h | 108 | ||||
-rw-r--r-- | src/imports/statemachine/finalstate.cpp | 85 | ||||
-rw-r--r-- | src/imports/statemachine/finalstate.h | 73 | ||||
-rw-r--r-- | src/imports/statemachine/plugin.cpp | 77 | ||||
-rw-r--r-- | src/imports/statemachine/plugins.qmltypes | 163 | ||||
-rw-r--r-- | src/imports/statemachine/qmldir | 4 | ||||
-rw-r--r-- | src/imports/statemachine/signaltransition.cpp | 238 | ||||
-rw-r--r-- | src/imports/statemachine/signaltransition.h | 86 | ||||
-rw-r--r-- | src/imports/statemachine/statebase.cpp | 244 | ||||
-rw-r--r-- | src/imports/statemachine/statebase.h | 77 | ||||
-rw-r--r-- | src/imports/statemachine/statemachine.cpp | 223 | ||||
-rw-r--r-- | src/imports/statemachine/statemachine.h | 91 | ||||
-rw-r--r-- | src/imports/statemachine/statemachine.pro | 24 | ||||
-rw-r--r-- | src/imports/statemachine/timeouttransition.cpp | 114 | ||||
-rw-r--r-- | src/imports/statemachine/timeouttransition.h | 76 |
15 files changed, 1683 insertions, 0 deletions
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 |