Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquicktransitionmanager.cpp
Go to the documentation of this file.
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
5
7#include "qquickstate_p_p.h"
8
9#include <private/qqmlbinding_p.h>
10#include <private/qqmlglobal_p.h>
11#include <private/qqmlproperty_p.h>
12
13#include <QtCore/qdebug.h>
14#include <private/qanimationjobutil_p.h>
15
17
19
33
38
39void QQuickTransitionManager::setState(QQuickState *s)
40{
41 d->state = s;
42}
43
45{
46 delete d->transitionInstance;
47 d->transitionInstance = nullptr;
48 delete d; d = nullptr;
49}
50
55
56void QQuickTransitionManager::complete()
57{
58 d->applyBindings();
59
60 // Explicitly take a copy in case the write action triggers a script that modifies the list.
62 for (const QQuickSimpleAction &action : std::as_const(completeListCopy))
63 action.property().write(action.value());
64
66
67 if (d->state)
68 static_cast<QQuickStatePrivate*>(QObjectPrivate::get(d->state))->complete();
69
70 finished();
71}
72
74{
75 for (const QQuickStateAction &action : std::as_const(bindingsList)) {
76 if (auto binding = action.toBinding; binding) {
77 binding.installOn(action.property, QQmlAnyBinding::RespectInterceptors);
78 } else if (action.event) {
79 if (action.reverseEvent)
80 action.event->reverse();
81 else
82 action.event->execute();
83 }
84
85 }
86
88}
89
93
94void QQuickTransitionManager::transition(const QList<QQuickStateAction> &list,
95 QQuickTransition *transition,
96 QObject *defaultTarget)
97{
99
100 // The copy below is ON PURPOSE, because firing actions might involve scripts that modify the list.
102
103 // Determine which actions are binding changes and disable any current bindings
104 for (const QQuickStateAction &action : std::as_const(applyList)) {
105 if (action.toBinding)
106 d->bindingsList << action;
107 if (action.fromBinding) {
108 auto property = action.property;
109 QQmlAnyBinding::removeBindingFrom(property); // Disable current binding
110 }
111 if (action.event && action.event->changesBindings()) { //### assume isReversable()?
112 d->bindingsList << action;
113 action.event->clearBindings();
114 }
115 }
116
117 // Animated transitions need both the start and the end value for
118 // each property change. In the presence of bindings, the end values
119 // are non-trivial to calculate. As a "best effort" attempt, we first
120 // apply all the property and binding changes, then read all the actual
121 // final values, then roll back the changes and proceed as normal.
122 //
123 // This doesn't catch everything, and it might be a little fragile in
124 // some cases - but whatcha going to do?
125 if (transition && !d->bindingsList.isEmpty()) {
126
127 // Apply all the property and binding changes
128 for (const QQuickStateAction &action : std::as_const(applyList)) {
129 if (auto binding = action.toBinding; binding) {
130 binding.installOn(action.property);
131 } else if (!action.event) {
133 } else if (action.event->isReversable()) {
134 if (action.reverseEvent)
135 action.event->reverse();
136 else
137 action.event->execute();
138 }
139 }
140
141 // Read all the end values for binding changes.
142 for (auto it = applyList.begin(), eit = applyList.end(); it != eit; ++it) {
143 if (it->event) {
144 it->event->saveTargetValues();
145 continue;
146 }
147 const QQmlProperty &prop = it->property;
148 if (it->toBinding || !it->toValue.isValid())
149 it->toValue = prop.read();
150 }
151
152 // Revert back to the original values
153 for (const QQuickStateAction &action : std::as_const(applyList)) {
154 if (action.event) {
155 if (action.event->isReversable()) {
156 action.event->clearBindings();
157 action.event->rewind();
158 action.event->clearBindings(); //### shouldn't be needed
159 }
160 continue;
161 }
162
163 if (action.toBinding) {
164 auto property = action.property;
165 QQmlAnyBinding::removeBindingFrom(property); // Make sure this is disabled during the transition
166 }
167
169 }
170 }
171
172 if (transition) {
173 QList<QQmlProperty> touched;
175 d->transitionInstance = transition->prepare(applyList, touched, this, defaultTarget);
177 if (oldInstance && oldInstance != d->transitionInstance)
178 delete oldInstance;
179
180 // Modify the action list to remove actions handled in the transition
181 auto isHandledInTransition = [this, touched](const QQuickStateAction &action) {
182 if (action.event) {
183 return action.actionDone;
184 } else {
185 if (touched.contains(action.property)) {
186 if (action.toValue != action.fromValue)
188 return true;
189 }
190 }
191 return false;
192 };
193
194 applyList.removeIf(isHandledInTransition);
195 }
196
197 // Any actions remaining have not been handled by the transition and should
198 // be applied immediately. We skip applying bindings, as they are all
199 // applied at the end in applyBindings() to avoid any nastiness mid
200 // transition
201 for (const QQuickStateAction &action : std::as_const(applyList)) {
202 if (action.event && !action.event->changesBindings()) {
203 if (action.event->isReversable() && action.reverseEvent)
204 action.event->reverse();
205 else
206 action.event->execute();
207 } else if (!action.event && !action.toBinding) {
208 action.property.write(action.toValue);
209 }
210 }
211 if (lcStates().isDebugEnabled()) {
212 for (const QQuickStateAction &action : std::as_const(applyList)) {
213 if (action.event)
214 qCDebug(lcStates) << "no transition for event:" << action.event->type();
215 else
216 qCDebug(lcStates) << "no transition for:" << action.property.object()
217 << action.property.name() << "from:" << action.fromValue
218 << "to:" << action.toValue;
219 }
220 }
221
222 if (!transition)
223 complete();
224}
225
227{
230
231 for (const QQuickStateAction &action : std::as_const(d->bindingsList)) {
232 if (action.toBinding && action.deletableToBinding) {
233 auto property = action.property;
235 } else if (action.event) {
236 //### what do we do here?
237 }
238
239 }
240 d->bindingsList.clear();
241 d->completeList.clear();
242}
243
bool isEmpty() const noexcept
Definition qlist.h:401
void clear()
Definition qlist.h:434
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
static void removeBindingFrom(QQmlProperty &prop)
static bool write(QObject *, const QQmlPropertyData &, const QVariant &, const QQmlRefPointer< QQmlContextData > &, QQmlPropertyData::WriteFlags flags={})
The QQmlProperty class abstracts accessing properties on objects created from QML.
QVariant read() const
Returns the property value.
QQuickTransitionInstance * transitionInstance
QList< QQuickSimpleAction > SimpleActionList
QQuickStateOperation::ActionList bindingsList
void transition(const QList< QQuickStateAction > &, QQuickTransition *transition, QObject *defaultTarget=nullptr)
iterator begin()
Definition qset.h:136
QSet< QString >::iterator it
else opt state
[0]
Combined button and popup list for selecting options.
#define RETURN_IF_DELETED(func)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLdouble s
[6]
Definition qopenglext.h:235
const char property[13]
Definition qwizard.cpp:101
QList< int > list
[14]
gzip write("uncompressed data")
QObject::connect nullptr