aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qsgpositioners
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qsgpositioners')
-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/grid-row-column-spacing.qml43
-rw-r--r--tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml40
-rw-r--r--tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml3
-rw-r--r--tests/auto/declarative/qsgpositioners/data/rectangleComponent.qml11
-rw-r--r--tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp189
10 files changed, 530 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/grid-row-column-spacing.qml b/tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml
new file mode 100644
index 0000000000..49bbd337e7
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml
@@ -0,0 +1,43 @@
+import QtQuick 2.0
+
+Item {
+ width: 640
+ height: 480
+ Grid {
+ objectName: "grid"
+ columns: 3
+ spacing: 4
+ rowSpacing: 7
+ columnSpacing: 11
+ 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/qsgpositioners/data/horizontal-animated-disabled.qml b/tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml
new file mode 100644
index 0000000000..8723ffc78f
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/horizontal-animated-disabled.qml
@@ -0,0 +1,40 @@
+import QtQuick 2.0
+
+Item {
+ width: 640
+ height: 480
+
+ Row {
+ objectName: "row"
+ add: Transition {
+ enabled: false
+ NumberAnimation { properties: "x" }
+ }
+ move: Transition {
+ enabled: false
+ NumberAnimation { properties: "x" }
+ }
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ x: -100;
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "blue"
+ x: -100;
+ visible: false
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ x: -100;
+ color: "green"
+ width: 50
+ height: 50
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml b/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml
index b9b8591e83..a88c26b66c 100644
--- a/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml
+++ b/tests/auto/declarative/qsgpositioners/data/horizontal-animated.qml
@@ -4,16 +4,19 @@ Item {
width: 640
height: 480
property bool testRightToLeft: false
+ property bool testEnabled: false
Row {
objectName: "row"
layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight
add: Transition {
+ enabled: testEnabled ? false : true
NumberAnimation {
properties: "x";
}
}
move: Transition {
+ enabled: testEnabled ? false : true
NumberAnimation {
properties: "x";
}
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 a9bdf4249b..137e6acd77 100644
--- a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
+++ b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
@@ -68,6 +68,7 @@ private slots:
void test_horizontal_spacing_rightToLeft();
void test_horizontal_animated();
void test_horizontal_animated_rightToLeft();
+ void test_horizontal_animated_disabled();
void test_vertical();
void test_vertical_spacing();
void test_vertical_animated();
@@ -75,6 +76,7 @@ private slots:
void test_grid_topToBottom();
void test_grid_rightToLeft();
void test_grid_spacing();
+ void test_grid_row_column_spacing();
void test_grid_animated();
void test_grid_animated_rightToLeft();
void test_grid_zero_columns();
@@ -89,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);
};
@@ -328,6 +334,46 @@ void tst_qsgpositioners::test_horizontal_animated_rightToLeft()
delete canvas;
}
+void tst_qsgpositioners::test_horizontal_animated_disabled()
+{
+ QSGView *canvas = createView(SRCDIR "/data/horizontal-animated-disabled.qml");
+
+ QSGRectangle *one = canvas->rootObject()->findChild<QSGRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QSGRectangle *two = canvas->rootObject()->findChild<QSGRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QSGRectangle *three = canvas->rootObject()->findChild<QSGRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QSGItem *row = canvas->rootObject()->findChild<QSGItem*>("row");
+ QVERIFY(row);
+
+ qApp->processEvents();
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->isVisible(), false);
+ QCOMPARE(two->x(), -100.0);//Not 'in' yet
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(three->y(), 0.0);
+
+ //Add 'two'
+ two->setVisible(true);
+ QCOMPARE(two->isVisible(), true);
+ qApp->processEvents();
+ QCOMPARE(row->width(), 150.0);
+ QCOMPARE(row->height(), 50.0);
+
+ qApp->processEvents();
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(three->x(), 100.0);
+
+ delete canvas;
+}
+
void tst_qsgpositioners::test_vertical()
{
QSGView *canvas = createView(SRCDIR "/data/vertical.qml");
@@ -581,6 +627,39 @@ void tst_qsgpositioners::test_grid_spacing()
delete canvas;
}
+void tst_qsgpositioners::test_grid_row_column_spacing()
+{
+ QSGView *canvas = createView(SRCDIR "/data/grid-row-column-spacing.qml");
+
+ QSGRectangle *one = canvas->rootObject()->findChild<QSGRectangle*>("one");
+ QVERIFY(one != 0);
+ QSGRectangle *two = canvas->rootObject()->findChild<QSGRectangle*>("two");
+ QVERIFY(two != 0);
+ QSGRectangle *three = canvas->rootObject()->findChild<QSGRectangle*>("three");
+ QVERIFY(three != 0);
+ QSGRectangle *four = canvas->rootObject()->findChild<QSGRectangle*>("four");
+ QVERIFY(four != 0);
+ QSGRectangle *five = canvas->rootObject()->findChild<QSGRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 61.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 92.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 57.0);
+ QCOMPARE(five->x(), 61.0);
+ QCOMPARE(five->y(), 57.0);
+
+ QSGItem *grid = canvas->rootObject()->findChild<QSGItem*>("grid");
+ QCOMPARE(grid->width(), 142.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ delete canvas;
+}
+
void tst_qsgpositioners::test_grid_animated()
{
QSGView *canvas = createView(SRCDIR "/data/grid-animated.qml");
@@ -1270,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);