From 8c50262bfd9239bafdac0fbe03316af2b1e01d98 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 29 Mar 2010 15:56:41 +1000 Subject: Relayout items when Flow size changes. Also add Flow tests. Task-number: QTBUG-9421 --- doc/src/declarative/elements.qdoc | 1 + .../graphicsitems/qdeclarativepositioners.cpp | 3 ++ .../qdeclarativepositioners/data/flowtest.qml | 39 ++++++++++++++ .../tst_qdeclarativepositioners.cpp | 60 ++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativepositioners/data/flowtest.qml diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index e62d546..8091f95 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -179,6 +179,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Column \o \l Row \o \l Grid +\o \l Flow \endlist \o diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 5e91224..b23b8c9 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -820,6 +820,9 @@ public: QDeclarativeFlow::QDeclarativeFlow(QDeclarativeItem *parent) : QDeclarativeBasePositioner(*(new QDeclarativeFlowPrivate), Both, parent) { + Q_D(QDeclarativeFlow); + // Flow layout requires relayout if its own size changes too. + d->addItemChangeListener(d, QDeclarativeItemPrivate::Geometry); } /*! diff --git a/tests/auto/declarative/qdeclarativepositioners/data/flowtest.qml b/tests/auto/declarative/qdeclarativepositioners/data/flowtest.qml new file mode 100644 index 0000000..bd13bac --- /dev/null +++ b/tests/auto/declarative/qdeclarativepositioners/data/flowtest.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Item { + width: 90 + height: 480 + Flow { + anchors.fill: parent + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 50 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 0e1fee2..9026566 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -65,6 +65,8 @@ private slots: void test_grid_animated(); void test_propertychanges(); void test_repeater(); + void test_flow(); + void test_flow_resize(); private: QDeclarativeView *createView(const QString &filename); }; @@ -441,6 +443,64 @@ void tst_QDeclarativePositioners::test_repeater() QCOMPARE(three->y(), 0.0); } +void tst_QDeclarativePositioners::test_flow() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml"); + + QDeclarativeRectangle *one = canvas->rootObject()->findChild("one"); + QVERIFY(one != 0); + QDeclarativeRectangle *two = canvas->rootObject()->findChild("two"); + QVERIFY(two != 0); + QDeclarativeRectangle *three = canvas->rootObject()->findChild("three"); + QVERIFY(three != 0); + QDeclarativeRectangle *four = canvas->rootObject()->findChild("four"); + QVERIFY(four != 0); + QDeclarativeRectangle *five = canvas->rootObject()->findChild("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 70.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 70.0); +} + +void tst_QDeclarativePositioners::test_flow_resize() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/flowtest.qml"); + + QDeclarativeItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root); + root->setWidth(125); + + QDeclarativeRectangle *one = canvas->rootObject()->findChild("one"); + QVERIFY(one != 0); + QDeclarativeRectangle *two = canvas->rootObject()->findChild("two"); + QVERIFY(two != 0); + QDeclarativeRectangle *three = canvas->rootObject()->findChild("three"); + QVERIFY(three != 0); + QDeclarativeRectangle *four = canvas->rootObject()->findChild("four"); + QVERIFY(four != 0); + QDeclarativeRectangle *five = canvas->rootObject()->findChild("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); +} + QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename) { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12