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 QQUICKSTATE_H
5#define QQUICKSTATE_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 <qqml.h>
19#include <qqmlproperty.h>
20#include <QtCore/qobject.h>
21#include <QtCore/qsharedpointer.h>
22#include <private/qtquickglobal_p.h>
23#include <private/qqmlabstractbinding_p.h>
24#include <private/qqmlanybinding_p.h>
25
26#include <QtCore/private/qproperty_p.h>
27
28QT_BEGIN_NAMESPACE
29
30class QQuickStateActionEvent;
31class QQmlBinding;
32class QQmlExpression;
33
34class Q_QUICK_PRIVATE_EXPORT QQuickStateAction
35{
36public:
37 QQuickStateAction();
38 QQuickStateAction(QObject *, const QString &, const QVariant &);
39 QQuickStateAction(QObject *, const QQmlProperty &property, const QString &,
40 const QVariant &);
41
42 bool restore:1;
43 bool actionDone:1;
44 bool reverseEvent:1;
45 bool deletableToBinding:1;
46
47 QQmlProperty property;
48 QVariant fromValue;
49 QVariant toValue;
50
51 QQmlAnyBinding fromBinding;
52 QQmlAnyBinding toBinding;
53 QQuickStateActionEvent *event;
54
55 //strictly for matching
56 QObject *specifiedObject;
57 QString specifiedProperty;
58
59 void deleteFromBinding();
60};
61
62class Q_AUTOTEST_EXPORT QQuickStateActionEvent
63{
64public:
65 virtual ~QQuickStateActionEvent();
66
67 enum EventType { Script, SignalHandler, ParentChange, AnchorChanges };
68
69 virtual EventType type() const = 0;
70
71 virtual void execute();
72 virtual bool isReversable();
73 virtual void reverse();
74 virtual void saveOriginals() {}
75 virtual bool needsCopy() { return false; }
76 virtual void copyOriginals(QQuickStateActionEvent *) {}
77
78 virtual bool isRewindable() { return isReversable(); }
79 virtual void rewind() {}
80 virtual void saveCurrentValues() {}
81 virtual void saveTargetValues() {}
82
83 virtual bool changesBindings();
84 virtual void clearBindings();
85 virtual bool mayOverride(QQuickStateActionEvent*other);
86};
87
88//### rename to QQuickStateChange?
89class QQuickStateGroup;
90class QQuickState;
91class QQuickStateOperationPrivate;
92class Q_QUICK_PRIVATE_EXPORT QQuickStateOperation : public QObject
93{
94 Q_OBJECT
95 QML_ANONYMOUS
96 QML_ADDED_IN_VERSION(2, 0)
97public:
98 QQuickStateOperation(QObject *parent = nullptr)
99 : QObject(parent) {}
100 typedef QList<QQuickStateAction> ActionList;
101
102 virtual ActionList actions();
103
104 QQuickState *state() const;
105 void setState(QQuickState *state);
106
107protected:
108 QQuickStateOperation(QObjectPrivate &dd, QObject *parent = nullptr);
109
110private:
111 Q_DECLARE_PRIVATE(QQuickStateOperation)
112 Q_DISABLE_COPY(QQuickStateOperation)
113};
114
115typedef QQuickStateOperation::ActionList QQuickStateActions;
116
117class QQuickTransition;
118class QQuickStatePrivate;
119class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject
120{
121 Q_OBJECT
122
123 Q_PROPERTY(QString name READ name WRITE setName FINAL)
124 Q_PROPERTY(bool when READ when WRITE setWhen FINAL)
125 Q_PROPERTY(QString extend READ extends WRITE setExtends FINAL)
126 Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes FINAL)
127 Q_CLASSINFO("DefaultProperty", "changes")
128 Q_CLASSINFO("DeferredPropertyNames", "changes")
129 QML_NAMED_ELEMENT(State)
130 QML_ADDED_IN_VERSION(2, 0)
131
132public:
133 QQuickState(QObject *parent=nullptr);
134 ~QQuickState() override;
135
136 QString name() const;
137 void setName(const QString &);
138 bool isNamed() const;
139
140 bool isWhenKnown() const;
141 bool when() const;
142 void setWhen(bool);
143
144 QString extends() const;
145 void setExtends(const QString &);
146
147 QQmlListProperty<QQuickStateOperation> changes();
148 int operationCount() const;
149 QQuickStateOperation *operationAt(int) const;
150
151 QQuickState &operator<<(QQuickStateOperation *);
152
153 void apply(QQuickTransition *, QQuickState *revert);
154 void cancel();
155
156 QQuickStateGroup *stateGroup() const;
157 void setStateGroup(QQuickStateGroup *);
158
159 bool containsPropertyInRevertList(QObject *target, const QString &name) const;
160 bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
161 bool changeBindingInRevertList(QObject *target, const QString &name, QQmlAnyBinding binding);
162 bool removeEntryFromRevertList(QObject *target, const QString &name);
163 void addEntryToRevertList(const QQuickStateAction &action);
164 void removeAllEntriesFromRevertList(QObject *target);
165 void addEntriesToRevertList(const QList<QQuickStateAction> &actions);
166 QVariant valueInRevertList(QObject *target, const QString &name) const;
167 QQmlAnyBinding bindingInRevertList(QObject *target, const QString &name) const;
168
169 bool isStateActive() const;
170
171Q_SIGNALS:
172 void completed();
173
174private:
175 Q_DECLARE_PRIVATE(QQuickState)
176 Q_DISABLE_COPY(QQuickState)
177};
178
179QT_END_NAMESPACE
180
181QML_DECLARE_TYPE(QQuickStateOperation)
182QML_DECLARE_TYPE(QQuickState)
183
184#endif // QQUICKSTATE_H
185

source code of qtdeclarative/src/quick/util/qquickstate_p.h