diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-07-20 05:14:11 (GMT) |
---|---|---|
committer | Toby Tomkins <toby.tomkins@nokia.com> | 2010-07-26 04:10:01 (GMT) |
commit | fb065bb1ca4c49194e8a936ec0babba04f8471a1 (patch) | |
tree | db81336dd844ec5b30277d1c29f2c25dabe393cf | |
parent | d28dcae97d2244906d1e2c21f38dc1d33396004a (diff) | |
download | Qt-fb065bb1ca4c49194e8a936ec0babba04f8471a1.zip Qt-fb065bb1ca4c49194e8a936ec0babba04f8471a1.tar.gz Qt-fb065bb1ca4c49194e8a936ec0babba04f8471a1.tar.bz2 |
Rewinding AnchorChanges should not make target item's implicit width and height explicit
Task-number: QTBUG-12273
Reviewed-by: Michael Brasser
(cherry picked from commit 164b2b54922d87a44a60efe6dbbe2fa3b7716820)
3 files changed, 78 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 51e6f99..27d4b2d 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -1501,8 +1501,12 @@ void QDeclarativeAnchorChanges::rewind() d->target->setX(d->rewindX); d->target->setY(d->rewindY); - d->target->setWidth(d->rewindWidth); - d->target->setHeight(d->rewindHeight); + if (targetPrivate->widthValid) { + d->target->setWidth(d->rewindWidth); + } + if (targetPrivate->heightValid) { + d->target->setHeight(d->rewindHeight); + } } void QDeclarativeAnchorChanges::saveCurrentValues() diff --git a/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml b/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml new file mode 100644 index 0000000..e6b6020 --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/anchorRewindBug.qml @@ -0,0 +1,37 @@ +import Qt 4.7 +Rectangle { + id: container + color: "red" + height: 200 + width: 200 + Column { + id: column + objectName: "column" + anchors.left: container.right + anchors.bottom: container.bottom + + Rectangle { + id: rectangle + color: "blue" + height: 100 + width: 200 + } + Rectangle { + color: "blue" + height: 100 + width: 200 + } + } + states: State { + name: "reanchored" + AnchorChanges { + target: column + anchors.left: undefined + anchors.right: container.right + } + PropertyChanges { + target: rectangle + opacity: 0 + } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 639b2f3..7bc4fd4 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -121,6 +121,7 @@ private slots: void anchorChanges4(); void anchorChanges5(); void anchorChangesCrash(); + void anchorRewindBug(); void script(); void restoreEntryValues(); void explicitChanges(); @@ -807,6 +808,40 @@ void tst_qdeclarativestates::anchorChangesCrash() delete rect; } +// QTBUG-12273 +void tst_qdeclarativestates::anchorRewindBug() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent rectComponent(&engine, SRCDIR "/data/anchorRewindBug.qml"); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QDeclarativeItem * column = rect->findChild<QDeclarativeItem*>("column"); + + QVERIFY(column != 0); + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 200.0); + QDeclarativeItemPrivate::get(rect)->setState("reanchored"); + + // column height and width should stay implicit + // and column's implicit resizing should still work + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 100.0); + + QDeclarativeItemPrivate::get(rect)->setState(""); + + // column height and width should stay implicit + // and column's implicit resizing should still work + QVERIFY(!QDeclarativeItemPrivate::get(column)->heightValid); + QVERIFY(!QDeclarativeItemPrivate::get(column)->widthValid); + QCOMPARE(column->height(), 200.0); + + delete rect; +} + void tst_qdeclarativestates::script() { QDeclarativeEngine engine; |