| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 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 QSTATE_H |
| 5 | #define QSTATE_H |
| 6 | |
| 7 | #include <QtCore/qlist.h> |
| 8 | #include <QtCore/qmetaobject.h> |
| 9 | |
| 10 | #include <QtStateMachine/qabstractstate.h> |
| 11 | |
| 12 | QT_REQUIRE_CONFIG(statemachine); |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QAbstractTransition; |
| 17 | class QSignalTransition; |
| 18 | |
| 19 | class QStatePrivate; |
| 20 | class Q_STATEMACHINE_EXPORT QState : public QAbstractState |
| 21 | { |
| 22 | Q_OBJECT |
| 23 | Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState |
| 24 | NOTIFY initialStateChanged BINDABLE bindableInitialState) |
| 25 | Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState |
| 26 | NOTIFY errorStateChanged BINDABLE bindableErrorState) |
| 27 | Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode |
| 28 | NOTIFY childModeChanged BINDABLE bindableChildMode) |
| 29 | public: |
| 30 | enum ChildMode { |
| 31 | ExclusiveStates, |
| 32 | ParallelStates |
| 33 | }; |
| 34 | Q_ENUM(ChildMode) |
| 35 | |
| 36 | enum RestorePolicy { |
| 37 | DontRestoreProperties, |
| 38 | RestoreProperties |
| 39 | }; |
| 40 | Q_ENUM(RestorePolicy) |
| 41 | |
| 42 | QState(QState *parent = nullptr); |
| 43 | QState(ChildMode childMode, QState *parent = nullptr); |
| 44 | ~QState(); |
| 45 | |
| 46 | QAbstractState *errorState() const; |
| 47 | void setErrorState(QAbstractState *state); |
| 48 | QBindable<QAbstractState*> bindableErrorState(); |
| 49 | |
| 50 | void addTransition(QAbstractTransition *transition); |
| 51 | QSignalTransition *addTransition(const QObject *sender, const char *signal, QAbstractState *target); |
| 52 | #ifdef Q_QDOC |
| 53 | template<typename PointerToMemberFunction> |
| 54 | QSignalTransition *addTransition(const QObject *sender, PointerToMemberFunction signal, |
| 55 | QAbstractState *target); |
| 56 | #else |
| 57 | template <typename Func> |
| 58 | QSignalTransition *addTransition(const typename QtPrivate::FunctionPointer<Func>::Object *obj, |
| 59 | Func signal, QAbstractState *target) |
| 60 | { |
| 61 | const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal); |
| 62 | return addTransition(obj, signalMetaMethod.methodSignature().constData(), target); |
| 63 | } |
| 64 | #endif // Q_QDOC |
| 65 | QAbstractTransition *addTransition(QAbstractState *target); |
| 66 | void removeTransition(QAbstractTransition *transition); |
| 67 | QList<QAbstractTransition*> transitions() const; |
| 68 | |
| 69 | QAbstractState *initialState() const; |
| 70 | void setInitialState(QAbstractState *state); |
| 71 | QBindable<QAbstractState*> bindableInitialState(); |
| 72 | |
| 73 | ChildMode childMode() const; |
| 74 | void setChildMode(ChildMode mode); |
| 75 | QBindable<QState::ChildMode> bindableChildMode(); |
| 76 | |
| 77 | #ifndef QT_NO_PROPERTIES |
| 78 | void assignProperty(QObject *object, const char *name, |
| 79 | const QVariant &value); |
| 80 | #endif |
| 81 | |
| 82 | Q_SIGNALS: |
| 83 | void finished(QPrivateSignal); |
| 84 | void propertiesAssigned(QPrivateSignal); |
| 85 | void childModeChanged(QPrivateSignal); |
| 86 | void initialStateChanged(QPrivateSignal); |
| 87 | void errorStateChanged(QPrivateSignal); |
| 88 | |
| 89 | protected: |
| 90 | void onEntry(QEvent *event) override; |
| 91 | void onExit(QEvent *event) override; |
| 92 | |
| 93 | bool event(QEvent *e) override; |
| 94 | |
| 95 | protected: |
| 96 | QState(QStatePrivate &dd, QState *parent); |
| 97 | |
| 98 | private: |
| 99 | Q_DISABLE_COPY(QState) |
| 100 | Q_DECLARE_PRIVATE(QState) |
| 101 | }; |
| 102 | |
| 103 | QT_END_NAMESPACE |
| 104 | |
| 105 | #endif |
| 106 | |