1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKSTATE_H
41#define QQUICKSTATE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <qqml.h>
55#include <qqmlproperty.h>
56#include <QtCore/qobject.h>
57#include <QtCore/qsharedpointer.h>
58#include <private/qtquickglobal_p.h>
59#include <private/qqmlabstractbinding_p.h>
60
61QT_BEGIN_NAMESPACE
62
63class QQuickStateActionEvent;
64class QQmlBinding;
65class QQmlExpression;
66
67class Q_QUICK_PRIVATE_EXPORT QQuickStateAction
68{
69public:
70 QQuickStateAction();
71 QQuickStateAction(QObject *, const QString &, const QVariant &);
72 QQuickStateAction(QObject *, const QQmlProperty &property, const QString &,
73 const QVariant &);
74
75 bool restore:1;
76 bool actionDone:1;
77 bool reverseEvent:1;
78 bool deletableToBinding:1;
79
80 QQmlProperty property;
81 QVariant fromValue;
82 QVariant toValue;
83
84 QQmlAbstractBinding::Ptr fromBinding;
85 QQmlAbstractBinding::Ptr toBinding;
86 QQuickStateActionEvent *event;
87
88 //strictly for matching
89 QObject *specifiedObject;
90 QString specifiedProperty;
91
92 void deleteFromBinding();
93};
94
95class Q_AUTOTEST_EXPORT QQuickStateActionEvent
96{
97public:
98 virtual ~QQuickStateActionEvent();
99
100 enum EventType { Script, SignalHandler, ParentChange, AnchorChanges };
101
102 virtual EventType type() const = 0;
103
104 virtual void execute();
105 virtual bool isReversable();
106 virtual void reverse();
107 virtual void saveOriginals() {}
108 virtual bool needsCopy() { return false; }
109 virtual void copyOriginals(QQuickStateActionEvent *) {}
110
111 virtual bool isRewindable() { return isReversable(); }
112 virtual void rewind() {}
113 virtual void saveCurrentValues() {}
114 virtual void saveTargetValues() {}
115
116 virtual bool changesBindings();
117 virtual void clearBindings();
118 virtual bool mayOverride(QQuickStateActionEvent*other);
119};
120
121//### rename to QQuickStateChange?
122class QQuickStateGroup;
123class QQuickState;
124class QQuickStateOperationPrivate;
125class Q_QUICK_PRIVATE_EXPORT QQuickStateOperation : public QObject
126{
127 Q_OBJECT
128 QML_ANONYMOUS
129public:
130 QQuickStateOperation(QObject *parent = nullptr)
131 : QObject(parent) {}
132 typedef QList<QQuickStateAction> ActionList;
133
134 virtual ActionList actions();
135
136 QQuickState *state() const;
137 void setState(QQuickState *state);
138
139protected:
140 QQuickStateOperation(QObjectPrivate &dd, QObject *parent = nullptr);
141
142private:
143 Q_DECLARE_PRIVATE(QQuickStateOperation)
144 Q_DISABLE_COPY(QQuickStateOperation)
145};
146
147typedef QQuickStateOperation::ActionList QQuickStateActions;
148
149class QQuickTransition;
150class QQuickStatePrivate;
151class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject
152{
153 Q_OBJECT
154
155 Q_PROPERTY(QString name READ name WRITE setName)
156 Q_PROPERTY(bool when READ when WRITE setWhen)
157 Q_PROPERTY(QString extend READ extends WRITE setExtends)
158 Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes)
159 Q_CLASSINFO("DefaultProperty", "changes")
160 Q_CLASSINFO("DeferredPropertyNames", "changes")
161 QML_NAMED_ELEMENT(State)
162
163public:
164 QQuickState(QObject *parent=nullptr);
165 ~QQuickState() override;
166
167 QString name() const;
168 void setName(const QString &);
169 bool isNamed() const;
170
171 bool isWhenKnown() const;
172 bool when() const;
173 void setWhen(bool);
174
175 QString extends() const;
176 void setExtends(const QString &);
177
178 QQmlListProperty<QQuickStateOperation> changes();
179 int operationCount() const;
180 QQuickStateOperation *operationAt(int) const;
181
182 QQuickState &operator<<(QQuickStateOperation *);
183
184 void apply(QQuickTransition *, QQuickState *revert);
185 void cancel();
186
187 QQuickStateGroup *stateGroup() const;
188 void setStateGroup(QQuickStateGroup *);
189
190 bool containsPropertyInRevertList(QObject *target, const QString &name) const;
191 bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
192 bool changeBindingInRevertList(QObject *target, const QString &name, QQmlAbstractBinding *binding);
193 bool removeEntryFromRevertList(QObject *target, const QString &name);
194 void addEntryToRevertList(const QQuickStateAction &action);
195 void removeAllEntriesFromRevertList(QObject *target);
196 void addEntriesToRevertList(const QList<QQuickStateAction> &actions);
197 QVariant valueInRevertList(QObject *target, const QString &name) const;
198 QQmlAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const;
199
200 bool isStateActive() const;
201
202Q_SIGNALS:
203 void completed();
204
205private:
206 Q_DECLARE_PRIVATE(QQuickState)
207 Q_DISABLE_COPY(QQuickState)
208};
209
210QT_END_NAMESPACE
211
212QML_DECLARE_TYPE(QQuickStateOperation)
213QML_DECLARE_TYPE(QQuickState)
214
215#endif // QQUICKSTATE_H
216

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