From c4c5129632591738c290058abab281ad1b1493c1 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 10 Mar 2014 15:58:10 +0100 Subject: Item views: improve initial Z-value handling Respect the initial Z-values of item, highlight, header, footer and section delegate instances. Mention also the default values in docs. Change-Id: I2ce4bb537898a0f5fdfa776b79d5747b1c080a7b Reviewed-by: Michael Brasser Reviewed-by: Alan Alpert Reviewed-by: Martin Jones --- .../quick/qquickgridview/data/boundZValues.qml | 46 ++++++++++++++++++ .../quick/qquickgridview/data/constantZValues.qml | 46 ++++++++++++++++++ .../quick/qquickgridview/data/defaultZValues.qml | 37 +++++++++++++++ .../quick/qquickgridview/data/initialZValues.qml | 35 -------------- .../quick/qquickgridview/tst_qquickgridview.cpp | 22 +++++++-- .../quick/qquicklistview/data/boundZValues.qml | 55 ++++++++++++++++++++++ .../quick/qquicklistview/data/constantZValues.qml | 55 ++++++++++++++++++++++ .../quick/qquicklistview/data/defaultZValues.qml | 49 +++++++++++++++++++ .../quick/qquicklistview/data/initialZValues.qml | 35 -------------- .../quick/qquicklistview/tst_qquicklistview.cpp | 26 ++++++++-- 10 files changed, 330 insertions(+), 76 deletions(-) create mode 100644 tests/auto/quick/qquickgridview/data/boundZValues.qml create mode 100644 tests/auto/quick/qquickgridview/data/constantZValues.qml create mode 100644 tests/auto/quick/qquickgridview/data/defaultZValues.qml delete mode 100644 tests/auto/quick/qquickgridview/data/initialZValues.qml create mode 100644 tests/auto/quick/qquicklistview/data/boundZValues.qml create mode 100644 tests/auto/quick/qquicklistview/data/constantZValues.qml create mode 100644 tests/auto/quick/qquicklistview/data/defaultZValues.qml delete mode 100644 tests/auto/quick/qquicklistview/data/initialZValues.qml (limited to 'tests/auto') diff --git a/tests/auto/quick/qquickgridview/data/boundZValues.qml b/tests/auto/quick/qquickgridview/data/boundZValues.qml new file mode 100644 index 0000000000..7a1ca48a81 --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/boundZValues.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + GridView { + id: grid + + property real itemZ: 342 + property real headerZ: 341 + property real footerZ: 340 + property real highlightZ: 339 + + anchors.fill: parent + objectName: "grid" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + z: grid.itemZ + } + + header: Rectangle { + width: 240 + height: 30 + z: grid.headerZ + } + + footer: Rectangle { + width: 240 + height: 30 + z: grid.footerZ + } + + highlight: Rectangle { + width: 240 + height: 30 + z: grid.highlightZ + } + } +} + diff --git a/tests/auto/quick/qquickgridview/data/constantZValues.qml b/tests/auto/quick/qquickgridview/data/constantZValues.qml new file mode 100644 index 0000000000..7cf564a12e --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/constantZValues.qml @@ -0,0 +1,46 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + GridView { + id: grid + + property real itemZ: 241 + property real headerZ: 242 + property real footerZ: 243 + property real highlightZ: 244 + + anchors.fill: parent + objectName: "grid" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + z: 241 + } + + header: Rectangle { + width: 240 + height: 30 + z: 242 + } + + footer: Rectangle { + width: 240 + height: 30 + z: 243 + } + + highlight: Rectangle { + width: 240 + height: 30 + z: 244 + } + } +} + diff --git a/tests/auto/quick/qquickgridview/data/defaultZValues.qml b/tests/auto/quick/qquickgridview/data/defaultZValues.qml new file mode 100644 index 0000000000..53f11bb2da --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/defaultZValues.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + GridView { + id: grid + + property real itemZ: 1 + property real headerZ: 1 + property real footerZ: 1 + property real highlightZ: 0 + + anchors.fill: parent + objectName: "grid" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + } + + header: Rectangle { + width: 240 + height: 30 + } + + footer: Rectangle { + width: 240 + height: 30 + } + } +} + diff --git a/tests/auto/quick/qquickgridview/data/initialZValues.qml b/tests/auto/quick/qquickgridview/data/initialZValues.qml deleted file mode 100644 index 9768b2c695..0000000000 --- a/tests/auto/quick/qquickgridview/data/initialZValues.qml +++ /dev/null @@ -1,35 +0,0 @@ -import QtQuick 2.0 - -Rectangle { - width: 240 - height: 320 - - GridView { - id: grid - - property real initialZ: 342 - - anchors.fill: parent - objectName: "grid" - model: ListModel {} - - delegate: Text { - objectName: "wrapper" - font.pointSize: 20 - text: index - } - - header: Rectangle { - width: 240 - height: 30 - z: grid.initialZ - } - - footer: Rectangle { - width: 240 - height: 30 - z: grid.initialZ - } - } -} - diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index f4eec18690..890174e2a8 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -121,6 +121,7 @@ private slots: void footer(); void footer_data(); void initialZValues(); + void initialZValues_data(); void header(); void header_data(); void extents(); @@ -3200,8 +3201,9 @@ void tst_QQuickGridView::footer_data() void tst_QQuickGridView::initialZValues() { + QFETCH(QString, fileName); QQuickView *window = createView(); - window->setSource(testFileUrl("initialZValues.qml")); + window->setSource(testFileUrl(fileName)); qApp->processEvents(); QQuickGridView *gridview = findItem(window->rootObject(), "grid"); @@ -3209,15 +3211,29 @@ void tst_QQuickGridView::initialZValues() QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != 0); + QVERIFY(gridview->currentItem()); + QTRY_COMPARE(gridview->currentItem()->z(), gridview->property("itemZ").toReal()); + QVERIFY(gridview->headerItem()); - QTRY_COMPARE(gridview->headerItem()->z(), gridview->property("initialZ").toReal()); + QTRY_COMPARE(gridview->headerItem()->z(), gridview->property("headerZ").toReal()); QVERIFY(gridview->footerItem()); - QTRY_COMPARE(gridview->footerItem()->z(), gridview->property("initialZ").toReal()); + QTRY_COMPARE(gridview->footerItem()->z(), gridview->property("footerZ").toReal()); + + QVERIFY(gridview->highlightItem()); + QTRY_COMPARE(gridview->highlightItem()->z(), gridview->property("highlightZ").toReal()); delete window; } +void tst_QQuickGridView::initialZValues_data() +{ + QTest::addColumn("fileName"); + QTest::newRow("defaults") << "defaultZValues.qml"; + QTest::newRow("constants") << "constantZValues.qml"; + QTest::newRow("bindings") << "boundZValues.qml"; +} + void tst_QQuickGridView::header() { QFETCH(QQuickGridView::Flow, flow); diff --git a/tests/auto/quick/qquicklistview/data/boundZValues.qml b/tests/auto/quick/qquicklistview/data/boundZValues.qml new file mode 100644 index 0000000000..10810e540d --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/boundZValues.qml @@ -0,0 +1,55 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + ListView { + id: list + + property real itemZ: 342 + property real headerZ: 341 + property real footerZ: 340 + property real highlightZ: 339 + property real sectionZ: 338 + + anchors.fill: parent + objectName: "list" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + z: list.itemZ + } + + header: Rectangle { + width: 240 + height: 30 + z: list.headerZ + } + + footer: Rectangle { + width: 240 + height: 30 + z: list.footerZ + } + + highlight: Rectangle { + width: 240 + height: 30 + z: list.highlightZ + } + + section.property: "text" + section.delegate: Text { + objectName: "section" + font.pointSize: 20 + text: section + z: list.sectionZ + } + } +} + diff --git a/tests/auto/quick/qquicklistview/data/constantZValues.qml b/tests/auto/quick/qquicklistview/data/constantZValues.qml new file mode 100644 index 0000000000..48917fed4f --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/constantZValues.qml @@ -0,0 +1,55 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + ListView { + id: list + + property real itemZ: 241 + property real headerZ: 242 + property real footerZ: 243 + property real highlightZ: 244 + property real sectionZ: 245 + + anchors.fill: parent + objectName: "list" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + z: 241 + } + + header: Rectangle { + width: 240 + height: 30 + z: 242 + } + + footer: Rectangle { + width: 240 + height: 30 + z: 243 + } + + highlight: Rectangle { + width: 240 + height: 30 + z: 244 + } + + section.property: "text" + section.delegate: Text { + objectName: "section" + font.pointSize: 20 + text: section + z: 245 + } + } +} + diff --git a/tests/auto/quick/qquicklistview/data/defaultZValues.qml b/tests/auto/quick/qquicklistview/data/defaultZValues.qml new file mode 100644 index 0000000000..7326340ae4 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/defaultZValues.qml @@ -0,0 +1,49 @@ +import QtQuick 2.0 + +Rectangle { + width: 240 + height: 320 + + ListView { + id: list + + property real itemZ: 1 + property real headerZ: 1 + property real footerZ: 1 + property real highlightZ: 0 + property real sectionZ: 2 + + anchors.fill: parent + objectName: "list" + model: ListModel { ListElement { text: "text" } } + currentIndex: 0 + + delegate: Text { + objectName: "wrapper" + font.pointSize: 20 + text: index + } + + header: Rectangle { + width: 240 + height: 30 + } + + footer: Rectangle { + width: 240 + height: 30 + } + + highlight: Rectangle { + width: 240 + height: 30 + } + + section.property: "text" + section.delegate: Text { + objectName: "section" + font.pointSize: 20 + text: section + } + } +} diff --git a/tests/auto/quick/qquicklistview/data/initialZValues.qml b/tests/auto/quick/qquicklistview/data/initialZValues.qml deleted file mode 100644 index 3a8e78debb..0000000000 --- a/tests/auto/quick/qquicklistview/data/initialZValues.qml +++ /dev/null @@ -1,35 +0,0 @@ -import QtQuick 2.0 - -Rectangle { - width: 240 - height: 320 - - ListView { - id: list - - property real initialZ: 342 - - anchors.fill: parent - objectName: "list" - model: ListModel {} - - delegate: Text { - objectName: "wrapper" - font.pointSize: 20 - text: index - } - - header: Rectangle { - width: 240 - height: 30 - z: list.initialZ - } - - footer: Rectangle { - width: 240 - height: 30 - z: list.initialZ - } - } -} - diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index efd0fa8103..60c2fadb23 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -147,6 +147,7 @@ private slots: void modelChanges(); void manualHighlight(); void initialZValues(); + void initialZValues_data(); void header(); void header_data(); void header_delayItemCreation(); @@ -3465,8 +3466,9 @@ void tst_QQuickListView::QTBUG_11105() void tst_QQuickListView::initialZValues() { + QFETCH(QString, fileName); QQuickView *window = createView(); - window->setSource(testFileUrl("initialZValues.qml")); + window->setSource(testFileUrl(fileName)); qApp->processEvents(); QQuickListView *listview = findItem(window->rootObject(), "list"); @@ -3474,15 +3476,33 @@ void tst_QQuickListView::initialZValues() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != 0); + QVERIFY(listview->currentItem()); + QTRY_COMPARE(listview->currentItem()->z(), listview->property("itemZ").toReal()); + QVERIFY(listview->headerItem()); - QTRY_COMPARE(listview->headerItem()->z(), listview->property("initialZ").toReal()); + QTRY_COMPARE(listview->headerItem()->z(), listview->property("headerZ").toReal()); QVERIFY(listview->footerItem()); - QTRY_COMPARE(listview->footerItem()->z(), listview->property("initialZ").toReal()); + QTRY_COMPARE(listview->footerItem()->z(), listview->property("footerZ").toReal()); + + QVERIFY(listview->highlightItem()); + QTRY_COMPARE(listview->highlightItem()->z(), listview->property("highlightZ").toReal()); + + QQuickText *sectionItem = 0; + QTRY_VERIFY(sectionItem = findItem(contentItem, "section")); + QTRY_COMPARE(sectionItem->z(), listview->property("sectionZ").toReal()); delete window; } +void tst_QQuickListView::initialZValues_data() +{ + QTest::addColumn("fileName"); + QTest::newRow("defaults") << "defaultZValues.qml"; + QTest::newRow("constants") << "constantZValues.qml"; + QTest::newRow("bindings") << "boundZValues.qml"; +} + void tst_QQuickListView::header() { QFETCH(QQuickListView::Orientation, orientation); -- cgit v1.2.3