aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickstateoperations.cpp15
-rw-r--r--tests/auto/quick/qquickstates/data/anchorRewindSize.qml30
-rw-r--r--tests/auto/quick/qquickstates/tst_qquickstates.cpp36
3 files changed, 79 insertions, 2 deletions
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp
index a6e5eed56c..1c8bee7253 100644
--- a/src/quick/items/qquickstateoperations.cpp
+++ b/src/quick/items/qquickstateoperations.cpp
@@ -1063,6 +1063,9 @@ void QQuickAnchorChanges::reverse()
stateHAnchors != QQuickAnchors::LeftAnchor &&
stateHAnchors != QQuickAnchors::RightAnchor &&
stateHAnchors != QQuickAnchors::HCenterAnchor);
+ // in case of an additive AnchorChange, we _did_ end up modifying the width
+ stateSetWidth |= ((stateHAnchors & QQuickAnchors::LeftAnchor) && (origHAnchors & QQuickAnchors::RightAnchor)) ||
+ ((stateHAnchors & QQuickAnchors::RightAnchor) && (origHAnchors & QQuickAnchors::LeftAnchor));
bool origSetWidth = (origHAnchors &&
origHAnchors != QQuickAnchors::LeftAnchor &&
origHAnchors != QQuickAnchors::RightAnchor &&
@@ -1078,12 +1081,15 @@ void QQuickAnchorChanges::reverse()
stateVAnchors != QQuickAnchors::BottomAnchor &&
stateVAnchors != QQuickAnchors::VCenterAnchor &&
stateVAnchors != QQuickAnchors::BaselineAnchor);
+ // in case of an additive AnchorChange, we _did_ end up modifying the height
+ stateSetHeight |= ((stateVAnchors & QQuickAnchors::TopAnchor) && (origVAnchors & QQuickAnchors::BottomAnchor)) ||
+ ((stateVAnchors & QQuickAnchors::BottomAnchor) && (origVAnchors & QQuickAnchors::TopAnchor));
bool origSetHeight = (origVAnchors &&
origVAnchors != QQuickAnchors::TopAnchor &&
origVAnchors != QQuickAnchors::BottomAnchor &&
origVAnchors != QQuickAnchors::VCenterAnchor &&
origVAnchors != QQuickAnchors::BaselineAnchor);
- if (d->origHeight.isValid() && stateSetHeight && !origSetHeight && !!qt_is_nan(d->origHeight)) {
+ if (d->origHeight.isValid() && stateSetHeight && !origSetHeight && !qt_is_nan(d->origHeight)) {
targetPrivate->heightValidFlag = true;
if (targetPrivate->height != d->origHeight)
targetPrivate->height.setValueBypassingBindings(d->origHeight);
@@ -1097,7 +1103,12 @@ void QQuickAnchorChanges::reverse()
const QRectF newGeometry(d->target->position(), d->target->size());
if (newGeometry != oldGeometry) {
- targetPrivate->dirty(QQuickItemPrivate::Position);
+ QQuickItemPrivate::DirtyType dirtyFlags {};
+ if (newGeometry.topLeft() != oldGeometry.topLeft())
+ dirtyFlags = QQuickItemPrivate::DirtyType(dirtyFlags | QQuickItemPrivate::Position);
+ if (newGeometry.size() != oldGeometry.size())
+ dirtyFlags = QQuickItemPrivate::DirtyType(dirtyFlags | QQuickItemPrivate::Size);
+ targetPrivate->dirty(dirtyFlags);
d->target->geometryChange(newGeometry, oldGeometry);
}
}
diff --git a/tests/auto/quick/qquickstates/data/anchorRewindSize.qml b/tests/auto/quick/qquickstates/data/anchorRewindSize.qml
new file mode 100644
index 0000000000..8fbae05c6d
--- /dev/null
+++ b/tests/auto/quick/qquickstates/data/anchorRewindSize.qml
@@ -0,0 +1,30 @@
+import QtQuick
+
+Item {
+ id: root
+ width: 400
+ height: 400
+ property bool changeState: false
+ Item {
+ id: outer
+ anchors.fill: parent
+ Item {
+ id: inner
+ width: 100
+ height: 100
+ anchors.left: outer.left
+ anchors.top: outer.top
+ }
+ states: [
+ State {
+ when: root.changeState
+ AnchorChanges {
+ target: inner
+ anchors.right: outer.right
+ anchors.bottom: outer.bottom
+ }
+ }
+ ]
+ }
+}
+
diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
index 44187d2b65..5e80c0ad0e 100644
--- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp
+++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
@@ -184,6 +184,7 @@ private slots:
void parentChangeInvolvingBindings();
void deferredProperties();
void rewindAnchorChange();
+ void rewindAnchorChangeSize();
void bindingProperlyRemovedWithTransition();
};
@@ -1975,6 +1976,41 @@ void tst_qquickstates::rewindAnchorChange()
QTRY_COMPARE(innerRect->height(), 200);
}
+void tst_qquickstates::rewindAnchorChangeSize()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("anchorRewindSize.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ std::unique_ptr<QObject> root(c.create());
+ QVERIFY(root);
+
+ QQmlContext *context = qmlContext(root.get());
+ QVERIFY(context);
+
+ QObject *inner = context->objectForName(QStringLiteral("inner"));
+ QVERIFY(inner);
+
+ QQuickItem *innerRect = qobject_cast<QQuickItem *>(inner);
+ QVERIFY(innerRect);
+
+ QCOMPARE(innerRect->x(), 0);
+ QCOMPARE(innerRect->y(), 0);
+ QCOMPARE(innerRect->width(), 100);
+ QCOMPARE(innerRect->height(), 100);
+
+ root->setProperty("changeState", true);
+ QCOMPARE(innerRect->x(), 0);
+ QCOMPARE(innerRect->y(), 0);
+ QCOMPARE(innerRect->width(), 400);
+ QCOMPARE(innerRect->height(), 400);
+
+ root->setProperty("changeState", false);
+ QCOMPARE(innerRect->x(), 0);
+ QCOMPARE(innerRect->y(), 0);
+ QCOMPARE(innerRect->width(), 100);
+ QCOMPARE(innerRect->height(), 100);
+}
+
void tst_qquickstates::bindingProperlyRemovedWithTransition()
{
QQmlEngine engine;