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 QABSTRACTTRANSITION_H
5#define QABSTRACTTRANSITION_H
6
7#include <QtCore/qlist.h>
8#include <QtCore/qobject.h>
9
10#include <QtStateMachine/qstatemachineglobal.h>
11
12QT_REQUIRE_CONFIG(statemachine);
13
14QT_BEGIN_NAMESPACE
15
16class QEvent;
17class QAbstractState;
18class QState;
19class QStateMachine;
20
21#if QT_CONFIG(animation)
22class QAbstractAnimation;
23#endif
24
25class QAbstractTransitionPrivate;
26class Q_STATEMACHINE_EXPORT QAbstractTransition : public QObject
27{
28 Q_OBJECT
29 Q_PROPERTY(QState* sourceState READ sourceState)
30 Q_PROPERTY(QAbstractState* targetState READ targetState WRITE setTargetState NOTIFY targetStateChanged)
31 Q_PROPERTY(QList<QAbstractState*> targetStates READ targetStates WRITE setTargetStates NOTIFY targetStatesChanged)
32 Q_PROPERTY(TransitionType transitionType READ transitionType WRITE setTransitionType
33 BINDABLE bindableTransitionType REVISION(1, 1))
34public:
35 enum TransitionType {
36 ExternalTransition,
37 InternalTransition
38 };
39 Q_ENUM(TransitionType)
40
41 QAbstractTransition(QState *sourceState = nullptr);
42 virtual ~QAbstractTransition();
43
44 QState *sourceState() const;
45 QAbstractState *targetState() const;
46 void setTargetState(QAbstractState* target);
47 QList<QAbstractState*> targetStates() const;
48 void setTargetStates(const QList<QAbstractState*> &targets);
49
50 TransitionType transitionType() const;
51 void setTransitionType(TransitionType type);
52 QBindable<QAbstractTransition::TransitionType> bindableTransitionType();
53
54 QStateMachine *machine() const;
55
56#if QT_CONFIG(animation)
57 void addAnimation(QAbstractAnimation *animation);
58 void removeAnimation(QAbstractAnimation *animation);
59 QList<QAbstractAnimation*> animations() const;
60#endif
61
62Q_SIGNALS:
63 void triggered(QPrivateSignal);
64 void targetStateChanged(QPrivateSignal);
65 void targetStatesChanged(QPrivateSignal);
66
67protected:
68 virtual bool eventTest(QEvent *event) = 0;
69
70 virtual void onTransition(QEvent *event) = 0;
71
72 bool event(QEvent *e) override;
73
74protected:
75 QAbstractTransition(QAbstractTransitionPrivate &dd, QState *parent);
76
77private:
78 Q_DISABLE_COPY(QAbstractTransition)
79 Q_DECLARE_PRIVATE(QAbstractTransition)
80};
81
82QT_END_NAMESPACE
83
84#endif
85

source code of qtscxml/src/statemachine/qabstracttransition.h