From bba51197a1f99a5c77c2747de2ecd399fdb638a0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 17 Jun 2010 11:36:30 +1000 Subject: Properly update childrenRect for position changes and shrinking. Task-number: QTBUG-11465 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 9 ++-- .../qdeclarativeitem/data/childrenRectBug2.qml | 53 ++++++++++++++++++++++ .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 27 ++++++++++- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 42b370b..336010f 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -345,10 +345,11 @@ void QDeclarativeContents::complete() void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) { - if (newGeometry.width() != oldGeometry.width()) - calcWidth(changed); - if (newGeometry.height() != oldGeometry.height()) - calcHeight(changed); + //### we can only pass changed if the left edge has moved left, or the right edge has moved right + if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x()) + calcWidth(/*changed*/); + if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y()) + calcHeight(/*changed*/); } void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item) diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml new file mode 100644 index 0000000..225d8d4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml @@ -0,0 +1,53 @@ +import Qt 4.7 + +Rectangle { + width:360; + height: 200 + + Item { + objectName: "theItem" + anchors.centerIn: parent + width: childrenRect.width + height: childrenRect.height + Rectangle { + id: header1 + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + width: 100; height: 50 + color: "green" + } + Rectangle { + id: text1 + anchors.top: header1.bottom + anchors.topMargin: 10 + anchors.horizontalCenter: parent.horizontalCenter + width: 100; height: 50 + color: "blue" + } + } + + states: [ + State { + name: "row" + AnchorChanges { + target: header1 + anchors.horizontalCenter: undefined + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.top: undefined + } + AnchorChanges { + target: text1 + anchors.horizontalCenter: undefined + anchors.verticalCenter: parent.verticalCenter + anchors.top: undefined + anchors.left: header1.right + } + PropertyChanges { + target: text1 + anchors.leftMargin: 10 + anchors.topMargin: 0 + } + } + ] +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 0a66245..4a57def 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -44,7 +44,8 @@ #include #include #include -#include +#include +#include #include "../../../shared/util.h" #ifdef Q_OS_SYMBIAN @@ -73,6 +74,7 @@ private slots: void transforms_data(); void childrenRect(); void childrenRectBug(); + void childrenRectBug2(); void childrenProperty(); void resourcesProperty(); @@ -753,6 +755,29 @@ void tst_QDeclarativeItem::childrenRectBug() delete canvas; } +// QTBUG-11465 +void tst_QDeclarativeItem::childrenRectBug2() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug2.qml")); + canvas->show(); + + QDeclarativeRectangle *rect = qobject_cast(canvas->rootObject()); + QVERIFY(rect); + QDeclarativeItem *item = rect->findChild("theItem"); + QCOMPARE(item->width(), qreal(100)); + QCOMPARE(item->height(), qreal(110)); + QCOMPARE(item->x(), qreal(130)); + + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + rectPrivate->setState("row"); + QCOMPARE(item->width(), qreal(210)); + QCOMPARE(item->height(), qreal(50)); + QCOMPARE(item->x(), qreal(75)); + + delete canvas; +} + template T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { -- cgit v0.12