diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-09 15:34:01 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-11 16:51:49 +0200 |
commit | 0d403890a40983b0bfa5c3640e20f6943492a6f6 (patch) | |
tree | c80a2e82269b3440fb326faa15e26e1ca84ebd32 /tests/auto/quick/qquickstates | |
parent | 66db74e53e3fa4aedeb519b8c8626066e1d6a1ce (diff) |
ParentChange: Restore old position correctly
ParentChange does floating point math in doChange to calculate the
correct position. Unfortunately, while doing the conversion, we
accumulate rounding errors in the presence of rotations.
Those can lead to visual glitches, as observed in QTBUG-68176.
This patch avoids the issue by storing the old values and resetting to
them in restore.
Fixes: QTBUG-68176
Change-Id: I6ebe1ccbc601838aa664cdc723e0cd58c95e785a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickstates')
-rw-r--r-- | tests/auto/quick/qquickstates/data/parentChangeCorrectReversal.qml | 72 | ||||
-rw-r--r-- | tests/auto/quick/qquickstates/tst_qquickstates.cpp | 17 |
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickstates/data/parentChangeCorrectReversal.qml b/tests/auto/quick/qquickstates/data/parentChangeCorrectReversal.qml new file mode 100644 index 0000000000..3d38fa4046 --- /dev/null +++ b/tests/auto/quick/qquickstates/data/parentChangeCorrectReversal.qml @@ -0,0 +1,72 @@ +import QtQuick 2.10 +import QtQuick.Layouts 1.3 + +Item { + id: root + + visible: true + + width: 400 + height: 200 + property bool switchToRight: false + property alias stayingRectX: stayingRect.x + + RowLayout { + id: topLayout + + anchors.fill: parent + + Item { + Layout.fillWidth: true + Layout.fillHeight: true + + Rectangle { + id: leftRect + + width: parent.width*(2/3) + height: width + anchors.centerIn: parent + + color: "red" + + Rectangle { + id: stayingRect + + x: 70; y: 70 + width: 50; height: 50 + + color: "yellow" + } + } + } + + Item { + Layout.fillWidth: true + Layout.fillHeight: true + + Rectangle { + id: rightRect + + width: parent.height*(2/3) + height: width + anchors.centerIn: parent + + color: "green" + rotation: 45 + } + } + } + + states: State { + name: "switchToRight" + + ParentChange { + target: stayingRect + parent: rightRect + width: 70 + } + + } + + state: root.switchToRight ? "switchToRight" : "" +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 1eb797f54f..d5fea3cb28 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -139,6 +139,7 @@ private slots: void revertListMemoryLeak(); void duplicateStateName(); void trivialWhen(); + void parentChangeCorrectReversal(); }; void tst_qquickstates::initTestCase() @@ -1675,6 +1676,22 @@ void tst_qquickstates::trivialWhen() QVERIFY(c.create()); } +void tst_qquickstates::parentChangeCorrectReversal() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("parentChangeCorrectReversal.qml")); + QScopedPointer<QObject> root {c.create()}; + QVERIFY(root); + QQmlProperty stayingRectX(root.get(), "stayingRectX"); + qreal oldX = stayingRectX.read().toDouble(); + QQmlProperty switchToRight(root.get(), "switchToRight"); + switchToRight.write(true); + qreal newX = stayingRectX.read().toDouble(); + QVERIFY(newX != oldX); + switchToRight.write(false); + QCOMPARE(oldX, stayingRectX.read().toDouble()); +} + QTEST_MAIN(tst_qquickstates) |