aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickstateoperations.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-10-14 17:00:41 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-10-18 12:39:29 +0200
commit785addcd17c7988be90a2ca17599c12b07e4e170 (patch)
tree939b83778a8508f27e880a0b48b34bfee1ca9d61 /src/quick/items/qquickstateoperations.cpp
parent728cc261a0cd644760d217b9ea22dce9f00676c9 (diff)
ParentChange: handle bindable properties
QQuickParentChange::actions was unable to handle new style properties. Fix this by using a QQmlAnyBinding create function instead of QQmlBinding. This required adding the necessary support for creation from a QQmlScriptString to QQmlProperyBinding and QQmlAnyBinding. Extra care had to be taken in reverseRewindHelper, which assumed that setting x/y/width/height would keep binding intact. We therefore use setValueBypassingBindings instead of the plain setter. Fixes: QTBUG-97480 Pick-to: 6.2 6.2.1 Change-Id: I0cc6d61c655d9d37846adf4b09fe103f507bb329 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/quick/items/qquickstateoperations.cpp')
-rw-r--r--src/quick/items/qquickstateoperations.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp
index ec91bb0294..54517e1ed6 100644
--- a/src/quick/items/qquickstateoperations.cpp
+++ b/src/quick/items/qquickstateoperations.cpp
@@ -355,8 +355,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << xa;
} else {
QQmlProperty property(d->target, QLatin1String("x"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->xString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->xString.value, d->target, qmlContext(this));
QQuickStateAction xa;
xa.property = property;
xa.toBinding = newBinding;
@@ -374,8 +373,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << ya;
} else {
QQmlProperty property(d->target, QLatin1String("y"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->yString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->yString.value, d->target, qmlContext(this));
QQuickStateAction ya;
ya.property = property;
ya.toBinding = newBinding;
@@ -393,8 +391,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << sa;
} else {
QQmlProperty property(d->target, QLatin1String("scale"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->scaleString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->scaleString.value, d->target, qmlContext(this));
QQuickStateAction sa;
sa.property = property;
sa.toBinding = newBinding;
@@ -412,8 +409,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << ra;
} else {
QQmlProperty property(d->target, QLatin1String("rotation"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->rotationString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->rotationString.value, d->target, qmlContext(this));
QQuickStateAction ra;
ra.property = property;
ra.toBinding = newBinding;
@@ -431,8 +427,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << wa;
} else {
QQmlProperty property(d->target, QLatin1String("width"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->widthString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->widthString, d->target, qmlContext(this));
QQuickStateAction wa;
wa.property = property;
wa.toBinding = newBinding;
@@ -450,8 +445,7 @@ QQuickStateOperation::ActionList QQuickParentChange::actions()
actions << ha;
} else {
QQmlProperty property(d->target, QLatin1String("height"));
- QQmlBinding *newBinding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, d->heightString.value, d->target, qmlContext(this));
- newBinding->setTarget(property);
+ auto newBinding = QQmlAnyBinding::createFromScriptString(property, d->heightString, d->target, qmlContext(this));
QQuickStateAction ha;
ha.property = property;
ha.toBinding = newBinding;
@@ -488,11 +482,13 @@ void QQuickParentChangePrivate::reverseRewindHelper(const std::unique_ptr<QQuick
{
if (!target || !snapshot)
return;
- target->setX(snapshot->x);
- target->setY(snapshot->y);
+ auto targetPriv = QQuickItemPrivate::get(target);
+ // leave existing bindings alive; new bindings are applied in applyBindings
+ targetPriv->x.setValueBypassingBindings(snapshot->x);
+ targetPriv->y.setValueBypassingBindings(snapshot->y);
+ targetPriv->width.setValueBypassingBindings(snapshot->width);
+ targetPriv->height.setValueBypassingBindings(snapshot->height);
target->setScale(snapshot->scale);
- target->setWidth(snapshot->width);
- target->setHeight(snapshot->height);
target->setRotation(snapshot->rotation);
target->setParentItem(snapshot->parent);
if (snapshot->stackBefore)