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_P_H
5#define QSTATE_P_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 "qstate.h"
19#include "private/qabstractstate_p.h"
20
21#include <QtCore/qlist.h>
22#include <QtCore/qbytearray.h>
23#include <QtCore/qpointer.h>
24#include <QtCore/qvariant.h>
25#include <QtCore/private/qproperty_p.h>
26
27QT_REQUIRE_CONFIG(statemachine);
28
29QT_BEGIN_NAMESPACE
30
31#ifndef QT_NO_PROPERTIES
32
33struct QPropertyAssignment
34{
35 QPropertyAssignment()
36 : object(nullptr), explicitlySet(true) {}
37 QPropertyAssignment(QObject *o, const QByteArray &n,
38 const QVariant &v, bool es = true)
39 : object(o), propertyName(n), value(v), explicitlySet(es)
40 {}
41
42 bool objectDeleted() const { return !object; }
43 void write() const { Q_ASSERT(object != nullptr); object->setProperty(name: propertyName, value); }
44 bool hasTarget(QObject *o, const QByteArray &pn) const
45 { return object == o && propertyName == pn; }
46
47 QPointer<QObject> object;
48 QByteArray propertyName;
49 QVariant value;
50 bool explicitlySet; // false means the property is being restored to its old value
51};
52Q_DECLARE_TYPEINFO(QPropertyAssignment, Q_RELOCATABLE_TYPE);
53
54#endif // QT_NO_PROPERTIES
55
56class QAbstractTransition;
57class QHistoryState;
58
59class QState;
60class Q_STATEMACHINE_EXPORT QStatePrivate : public QAbstractStatePrivate
61{
62 Q_DECLARE_PUBLIC(QState)
63public:
64 QStatePrivate();
65 ~QStatePrivate();
66
67 static QStatePrivate *get(QState *q) { return q ? q->d_func() : nullptr; }
68 static const QStatePrivate *get(const QState *q) { return q? q->d_func() : nullptr; }
69
70 QList<QAbstractState*> childStates() const;
71 QList<QHistoryState*> historyStates() const;
72 QList<QAbstractTransition*> transitions() const;
73
74 void emitFinished();
75 void emitPropertiesAssigned();
76
77 void initialStateChanged()
78 {
79 emit q_func()->initialStateChanged(QState::QPrivateSignal());
80 }
81 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QStatePrivate, QAbstractState*, initialState,
82 nullptr, &QStatePrivate::initialStateChanged);
83
84 void errorStateChanged()
85 {
86 emit q_func()->errorStateChanged(QState::QPrivateSignal());
87 }
88 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QStatePrivate, QAbstractState*, errorState,
89 nullptr, &QStatePrivate::errorStateChanged);
90
91 void childModeChanged()
92 {
93 emit q_func()->childModeChanged(QState::QPrivateSignal());
94 }
95 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QStatePrivate, QState::ChildMode, childMode,
96 QState::ExclusiveStates, &QStatePrivate::childModeChanged);
97
98 mutable bool childStatesListNeedsRefresh;
99 mutable bool transitionsListNeedsRefresh;
100 mutable QList<QAbstractState*> childStatesList;
101 mutable QList<QAbstractTransition*> transitionsList;
102
103#ifndef QT_NO_PROPERTIES
104 QList<QPropertyAssignment> propertyAssignments;
105#endif
106};
107
108QT_END_NAMESPACE
109
110#endif
111

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