1// Copyright (C) 2016 Ford Motor Company
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef SIGNALTRANSITION_H
5#define SIGNALTRANSITION_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qstatemachineqmlglobals_p.h"
19
20#include <QtStateMachine/QSignalTransition>
21#include <QtCore/QVariant>
22#include <QtQml/QJSValue>
23
24#include <QtQml/qqmlscriptstring.h>
25#include <QtQml/qqmlparserstatus.h>
26#include <private/qqmlcustomparser_p.h>
27#include <private/qqmlrefcount_p.h>
28#include <private/qqmlboundsignal_p.h>
29#include <QtCore/private/qproperty_p.h>
30
31QT_BEGIN_NAMESPACE
32
33class Q_STATEMACHINEQML_PRIVATE_EXPORT SignalTransition : public QSignalTransition, public QQmlParserStatus
34{
35 Q_OBJECT
36 Q_INTERFACES(QQmlParserStatus)
37 Q_PROPERTY(QJSValue signal READ signal WRITE setSignal
38 NOTIFY qmlSignalChanged BINDABLE bindableSignal)
39 Q_PROPERTY(QQmlScriptString guard READ guard WRITE setGuard
40 NOTIFY guardChanged BINDABLE bindableGuard)
41 QML_ELEMENT
42 QML_ADDED_IN_VERSION(1, 0)
43 QML_CUSTOMPARSER
44
45public:
46 explicit SignalTransition(QState *parent = nullptr);
47
48 QQmlScriptString guard() const;
49 void setGuard(const QQmlScriptString &guard);
50 QBindable<QQmlScriptString> bindableGuard();
51
52 bool eventTest(QEvent *event) override;
53 void onTransition(QEvent *event) override;
54
55 const QJSValue &signal();
56 void setSignal(const QJSValue &signal);
57 QBindable<QJSValue> bindableSignal();
58
59 Q_INVOKABLE void invoke();
60
61Q_SIGNALS:
62 void guardChanged();
63 void invokeYourself();
64 /*!
65 * \internal
66 */
67 void qmlSignalChanged();
68
69private:
70 void classBegin() override { m_complete = false; }
71 void componentComplete() override { m_complete = true; connectTriggered(); }
72 void connectTriggered();
73
74 friend class SignalTransitionParser;
75
76 Q_OBJECT_COMPAT_PROPERTY(SignalTransition, QJSValue, m_signal, &SignalTransition::setSignal,
77 &SignalTransition::qmlSignalChanged);
78 Q_OBJECT_BINDABLE_PROPERTY(SignalTransition, QQmlScriptString,
79 m_guard, &SignalTransition::guardChanged);
80 bool m_complete;
81 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
82 QList<const QV4::CompiledData::Binding *> m_bindings;
83 QQmlRefPointer<QQmlBoundSignalExpression> m_signalExpression;
84};
85
86class SignalTransitionParser : public QQmlCustomParser
87{
88public:
89 void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
90 void applyBindings(QObject *object, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
91};
92
93template<>
94inline QQmlCustomParser *qmlCreateCustomParser<SignalTransition>()
95{
96 return new SignalTransitionParser;
97}
98
99QT_END_NAMESPACE
100
101#endif
102

source code of qtscxml/src/statemachineqml/signaltransition_p.h