aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2011-08-16 11:48:14 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-18 00:24:09 +0200
commit74f3a67fe80fecf7ba2fd76e1758b6c0f68ce918 (patch)
tree1f50ac2696414113387da29de3213c9ed494ec68 /tests
parentdc5644758a2cdbe67111e3471488b89b1ddddd8c (diff)
Add attached properties to the positioners.
Added an attached property type to the base positioner class. This allows items within a positioner (Row, Column, Grid, Flow) to determine their index inside the positioner, as well as whether they are the first or last items. Non-visible items are ignored, as in the positioner layout objects themselves. It may be useful to expand this in the future to contain more information specific to the positioner, for example row/column for Grid. Task-number: QTBUG-19211 Change-Id: I10a8c9ca5528dd12811125cae8a9b4d2e3747972 Reviewed-on: http://codereview.qt.nokia.com/2983 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qsgpositioners/data/attachedproperties-column.qml50
-rw-r--r--tests/auto/declarative/qsgpositioners/data/attachedproperties-dynamic.qml44
-rw-r--r--tests/auto/declarative/qsgpositioners/data/attachedproperties-flow.qml50
-rw-r--r--tests/auto/declarative/qsgpositioners/data/attachedproperties-grid.qml50
-rw-r--r--tests/auto/declarative/qsgpositioners/data/attachedproperties-row.qml50
-rw-r--r--tests/auto/declarative/qsgpositioners/data/rectangleComponent.qml11
-rw-r--r--tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp114
7 files changed, 369 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsgpositioners/data/attachedproperties-column.qml b/tests/auto/declarative/qsgpositioners/data/attachedproperties-column.qml
new file mode 100644
index 0000000000..4c667aa205
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/attachedproperties-column.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 100
+ height: 200
+
+ Column {
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'red'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "greenRect"
+ width: 100
+ height: 100
+ color: 'green'
+ property int posIndex: Positioner.index
+ property bool isFirstItem: Positioner.isFirstItem
+ property bool isLastItem: Positioner.isLastItem
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'blue'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "yellowRect"
+ width: 100
+ height: 100
+ color: 'yellow'
+
+ property int posIndex: -1
+ property bool isFirstItem: false
+ property bool isLastItem: false
+
+ function onDemandPositioner() {
+ posIndex = Positioner.index;
+ isFirstItem = Positioner.isFirstItem
+ isLastItem = Positioner.isLastItem
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/attachedproperties-dynamic.qml b/tests/auto/declarative/qsgpositioners/data/attachedproperties-dynamic.qml
new file mode 100644
index 0000000000..894749dc16
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/attachedproperties-dynamic.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.0
+
+Rectangle
+{
+ width: 300
+ height: 100
+
+ Row {
+ id: pos
+ objectName: "pos"
+ anchors.fill: parent
+
+ Rectangle {
+ objectName: "rect0"
+ width: 100
+ height: 100
+ color: 'red'
+ property int index: Positioner.index
+ property bool firstItem: Positioner.isFirstItem
+ property bool lastItem: Positioner.isLastItem
+ }
+
+ Rectangle {
+ objectName: "rect1"
+ width: 100
+ height: 100
+ color: 'green'
+ property int index: Positioner.index
+ property bool firstItem: Positioner.isFirstItem
+ property bool lastItem: Positioner.isLastItem
+ }
+
+ property QtObject subRect;
+
+ function createSubRect() {
+ var component = Qt.createComponent("rectangleComponent.qml");
+ subRect = component.createObject(pos, {});
+ }
+
+ function destroySubRect() {
+ subRect.destroy();
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/attachedproperties-flow.qml b/tests/auto/declarative/qsgpositioners/data/attachedproperties-flow.qml
new file mode 100644
index 0000000000..e7f9a63e2a
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/attachedproperties-flow.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 200
+ height: 100
+
+ Flow {
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'red'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "greenRect"
+ width: 100
+ height: 100
+ color: 'green'
+ property int posIndex: Positioner.index
+ property bool isFirstItem: Positioner.isFirstItem
+ property bool isLastItem: Positioner.isLastItem
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'blue'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "yellowRect"
+ width: 100
+ height: 100
+ color: 'yellow'
+
+ property int posIndex: -1
+ property bool isFirstItem: false
+ property bool isLastItem: false
+
+ function onDemandPositioner() {
+ posIndex = Positioner.index;
+ isFirstItem = Positioner.isFirstItem
+ isLastItem = Positioner.isLastItem
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/attachedproperties-grid.qml b/tests/auto/declarative/qsgpositioners/data/attachedproperties-grid.qml
new file mode 100644
index 0000000000..2094309b9f
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/attachedproperties-grid.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 200
+ height: 100
+
+ Grid {
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'red'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "greenRect"
+ width: 100
+ height: 100
+ color: 'green'
+ property int posIndex: Positioner.index
+ property bool isFirstItem: Positioner.isFirstItem
+ property bool isLastItem: Positioner.isLastItem
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'blue'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "yellowRect"
+ width: 100
+ height: 100
+ color: 'yellow'
+
+ property int posIndex: -1
+ property bool isFirstItem: false
+ property bool isLastItem: false
+
+ function onDemandPositioner() {
+ posIndex = Positioner.index;
+ isFirstItem = Positioner.isFirstItem
+ isLastItem = Positioner.isLastItem
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/attachedproperties-row.qml b/tests/auto/declarative/qsgpositioners/data/attachedproperties-row.qml
new file mode 100644
index 0000000000..212a26b431
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/attachedproperties-row.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 200
+ height: 100
+
+ Row {
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'red'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "greenRect"
+ width: 100
+ height: 100
+ color: 'green'
+ property int posIndex: Positioner.index
+ property bool isFirstItem: Positioner.isFirstItem
+ property bool isLastItem: Positioner.isLastItem
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: 'blue'
+ visible: false
+ }
+
+ Rectangle {
+ objectName: "yellowRect"
+ width: 100
+ height: 100
+ color: 'yellow'
+
+ property int posIndex: -1
+ property bool isFirstItem: false
+ property bool isLastItem: false
+
+ function onDemandPositioner() {
+ posIndex = Positioner.index;
+ isFirstItem = Positioner.isFirstItem
+ isLastItem = Positioner.isLastItem
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/rectangleComponent.qml b/tests/auto/declarative/qsgpositioners/data/rectangleComponent.qml
new file mode 100644
index 0000000000..de1bb99593
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/rectangleComponent.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0;
+
+Rectangle {
+ objectName: "rect2"
+ color: "blue"
+ width: 100
+ height: 100
+ property int index: Positioner.index
+ property bool firstItem: Positioner.isFirstItem
+ property bool lastItem: Positioner.isLastItem
+}
diff --git a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
index 497f511335..137e6acd77 100644
--- a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
+++ b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
@@ -91,6 +91,10 @@ private slots:
void test_conflictinganchors();
void test_mirroring();
void test_allInvisible();
+ void test_attachedproperties();
+ void test_attachedproperties_data();
+ void test_attachedproperties_dynamic();
+
private:
QSGView *createView(const QString &filename);
};
@@ -1345,6 +1349,116 @@ void tst_qsgpositioners::test_allInvisible()
QVERIFY(column->height() == 0);
}
+void tst_qsgpositioners::test_attachedproperties()
+{
+ QFETCH(QString, filename);
+
+ QSGView *canvas = createView(filename);
+ QVERIFY(canvas->rootObject() != 0);
+
+ QSGRectangle *greenRect = canvas->rootObject()->findChild<QSGRectangle *>("greenRect");
+ QVERIFY(greenRect != 0);
+
+ int posIndex = greenRect->property("posIndex").toInt();
+ QVERIFY(posIndex == 0);
+ bool isFirst = greenRect->property("isFirstItem").toBool();
+ QVERIFY(isFirst == true);
+ bool isLast = greenRect->property("isLastItem").toBool();
+ QVERIFY(isLast == false);
+
+ QSGRectangle *yellowRect = canvas->rootObject()->findChild<QSGRectangle *>("yellowRect");
+ QVERIFY(yellowRect != 0);
+
+ posIndex = yellowRect->property("posIndex").toInt();
+ QVERIFY(posIndex == -1);
+ isFirst = yellowRect->property("isFirstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = yellowRect->property("isLastItem").toBool();
+ QVERIFY(isLast == false);
+
+ yellowRect->metaObject()->invokeMethod(yellowRect, "onDemandPositioner");
+
+ posIndex = yellowRect->property("posIndex").toInt();
+ QVERIFY(posIndex == 1);
+ isFirst = yellowRect->property("isFirstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = yellowRect->property("isLastItem").toBool();
+ QVERIFY(isLast == true);
+
+ delete canvas;
+}
+
+void tst_qsgpositioners::test_attachedproperties_data()
+{
+ QTest::addColumn<QString>("filename");
+
+ QTest::newRow("column") << SRCDIR "/data/attachedproperties-column.qml";
+ QTest::newRow("row") << SRCDIR "/data/attachedproperties-row.qml";
+ QTest::newRow("grid") << SRCDIR "/data/attachedproperties-grid.qml";
+ QTest::newRow("flow") << SRCDIR "/data/attachedproperties-flow.qml";
+}
+
+void tst_qsgpositioners::test_attachedproperties_dynamic()
+{
+ QSGView *canvas = createView(SRCDIR "/data/attachedproperties-dynamic.qml");
+ QVERIFY(canvas->rootObject() != 0);
+
+ QSGRow *row = canvas->rootObject()->findChild<QSGRow *>("pos");
+ QVERIFY(row != 0);
+
+ QSGRectangle *rect0 = canvas->rootObject()->findChild<QSGRectangle *>("rect0");
+ QVERIFY(rect0 != 0);
+
+ int posIndex = rect0->property("index").toInt();
+ QVERIFY(posIndex == 0);
+ bool isFirst = rect0->property("firstItem").toBool();
+ QVERIFY(isFirst == true);
+ bool isLast = rect0->property("lastItem").toBool();
+ QVERIFY(isLast == false);
+
+ QSGRectangle *rect1 = canvas->rootObject()->findChild<QSGRectangle *>("rect1");
+ QVERIFY(rect1 != 0);
+
+ posIndex = rect1->property("index").toInt();
+ QVERIFY(posIndex == 1);
+ isFirst = rect1->property("firstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = rect1->property("lastItem").toBool();
+ QVERIFY(isLast == true);
+
+ row->metaObject()->invokeMethod(row, "createSubRect");
+
+ posIndex = rect1->property("index").toInt();
+ QVERIFY(posIndex == 1);
+ isFirst = rect1->property("firstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = rect1->property("lastItem").toBool();
+ QVERIFY(isLast == false);
+
+ QSGRectangle *rect2 = canvas->rootObject()->findChild<QSGRectangle *>("rect2");
+ QVERIFY(rect2 != 0);
+
+ posIndex = rect2->property("index").toInt();
+ QVERIFY(posIndex == 2);
+ isFirst = rect2->property("firstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = rect2->property("lastItem").toBool();
+ QVERIFY(isLast == true);
+
+ row->metaObject()->invokeMethod(row, "destroySubRect");
+
+ qApp->processEvents(QEventLoop::DeferredDeletion);
+
+ posIndex = rect1->property("index").toInt();
+ QVERIFY(posIndex == 1);
+ isFirst = rect1->property("firstItem").toBool();
+ QVERIFY(isFirst == false);
+ isLast = rect1->property("lastItem").toBool();
+ QVERIFY(isLast == true);
+
+ delete canvas;
+}
+
QSGView *tst_qsgpositioners::createView(const QString &filename)
{
QSGView *canvas = new QSGView(0);