aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/statemachine/signaltransition.cpp
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 /src/imports/statemachine/signaltransition.cpp
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>
Diffstat (limited to 'src/imports/statemachine/signaltransition.cpp')
-rw-r--r--src/imports/statemachine/signaltransition.cpp238
1 files changed, 238 insertions, 0 deletions
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.
+*/