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
31
36
37void QQuickTransitionManager::setState(QQuickState *s)
38{
39 d->state = s;
40}
41
43{
44 delete d->transitionInstance;
45 d->transitionInstance = nullptr;
46 delete d; d = nullptr;
47}
48
53
54void QQuickTransitionManager::complete()
55{
56 d->applyBindings();
57
58 // Explicitly take a copy in case the write action triggers a script that modifies the list.
60 for (const QQuickSimpleAction &action : std::as_const(completeListCopy))
61 action.property().write(action.value());
62
64
65 if (d->state)
66 static_cast<QQuickStatePrivate*>(QObjectPrivate::get(d->state))->complete();
67
68 finished();
69}
70
72{
73 for (const QQuickStateAction &action : std::as_const(bindingsList)) {
74 if (auto binding = action.toBinding; binding) {
75 binding.installOn(action.property, QQmlAnyBinding::RespectInterceptors);
76 } else if (action.event) {
77 if (action.reverseEvent)
78 action.event->reverse();
79 else
80 action.event->execute();
81 }
82
83 }
84
86}
87
91
92void QQuickTransitionManager::transition(const QList<QQuickStateAction> &list,
93 QQuickTransition *transition,
94 QObject *defaultTarget)
95{
97
98 // The copy below is ON PURPOSE, because firing actions might involve scripts that modify the list.
100
101 // Determine which actions are binding changes and disable any current bindings
102 for (const QQuickStateAction &action : std::as_const(applyList)) {
103 if (action.toBinding)
104 d->bindingsList << action;
105 if (action.fromBinding) {
106 auto property = action.property;
107 QQmlAnyBinding::removeBindingFrom(property); // Disable current binding
108 }
109 if (action.event && action.event->changesBindings()) { //### assume isReversable()?
110 d->bindingsList << action;
111 action.event->clearBindings();
112 }
113 }
114
115 // Animated transitions need both the start and the end value for
116 // each property change. In the presence of bindings, the end values
117 // are non-trivial to calculate. As a "best effort" attempt, we first
118 // apply all the property and binding changes, then read all the actual
119 // final values, then roll back the changes and proceed as normal.
120 //
121 // This doesn't catch everything, and it might be a little fragile in
122 // some cases - but whatcha going to do?
123 if (transition && !d->bindingsList.isEmpty()) {
124
125 // Apply all the property and binding changes
126 for (const QQuickStateAction &action : std::as_const(applyList)) {
127 if (auto binding = action.toBinding; binding) {
128 binding.installOn(action.property);
129 } else if (!action.event) {
131 } else if (action.event->isReversable()) {
132 if (action.reverseEvent)
133 action.event->reverse();
134 else
135 action.event->execute();
136 }
137 }
138
139 // Read all the end values for binding changes.
140 for (auto it = applyList.begin(), eit = applyList.end(); it != eit; ++it) {
141 if (it->event) {
142 it->event->saveTargetValues();
143 continue;
144 }
145 const QQmlProperty &prop = it->property;
146 if (it->toBinding || !it->toValue.isValid())
147 it->toValue = prop.read();
148 }
149
150 // Revert back to the original values
151 for (const QQuickStateAction &action : std::as_const(applyList)) {
152 if (action.event) {
153 if (action.event->isReversable()) {
154 action.event->clearBindings();
155 action.event->rewind();
156 action.event->clearBindings(); //### shouldn't be needed
157 }
158 continue;
159 }
160
161 if (action.toBinding) {
162 auto property = action.property;
163 QQmlAnyBinding::removeBindingFrom(property); // Make sure this is disabled during the transition
164 }
165
167 }
168 }
169
170 if (transition) {
171 QList<QQmlProperty> touched;
173 d->transitionInstance = transition->prepare(applyList, touched, this, defaultTarget);
175 if (oldInstance && oldInstance != d->transitionInstance)
176 delete oldInstance;
177
178 // Modify the action list to remove actions handled in the transition
179 auto isHandledInTransition = [this, touched](const QQuickStateAction &action) {
180 if (action.event) {
181 return action.actionDone;
182 } else {
183 if (touched.contains(action.property)) {
184 if (action.toValue != action.fromValue)
186 return true;
187 }
188 }
189 return false;
190 };
191
192 applyList.removeIf(isHandledInTransition);
193 }
194
195 // Any actions remaining have not been handled by the transition and should
196 // be applied immediately. We skip applying bindings, as they are all
197 // applied at the end in applyBindings() to avoid any nastiness mid
198 // transition
199 for (const QQuickStateAction &action : std::as_const(applyList)) {
200 if (action.event && !action.event->changesBindings()) {
201 if (action.event->isReversable() && action.reverseEvent)
202 action.event->reverse();
203 else
204 action.event->execute();
205 } else if (!action.event && !action.toBinding) {
206 action.property.write(action.toValue);
207 }
208 }
209 if (lcStates().isDebugEnabled()) {
210 for (const QQuickStateAction &action : std::as_const(applyList)) {
211 if (action.event)
212 qCDebug(lcStates) << "no transition for event:" << action.event->type();
213 else
214 qCDebug(lcStates) << "no transition for:" << action.property.object()
215 << action.property.name() << "from:" << action.fromValue
216 << "to:" << action.toValue;
217 }
218 }
219
220 if (!transition)
221 complete();
222}
223
225{
228
229 for (const QQuickStateAction &action : std::as_const(d->bindingsList)) {
230 if (action.toBinding && action.deletableToBinding) {
231 auto property = action.property;
233 } else if (action.event) {
234 //### what do we do here?
235 }
236
237 }
238 d->bindingsList.clear();
239 d->completeList.clear();
240}
241
bool isEmpty() const noexcept
Definition qlist.h:402
void clear()
Definition qlist.h:435
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:137
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define RETURN_IF_DELETED(func)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCDebug(category,...)
GLdouble s
[6]
Definition qopenglext.h:235
const char property[13]
Definition qwizard.cpp:100
QList< int > list
[14]
gzip write("uncompressed data")
QObject::connect nullptr