diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-09-20 15:58:05 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-22 00:23:56 +0200 |
commit | 7ecce2cc0e33bc6b1aa052163f9d6c1365b93b27 (patch) | |
tree | 19a241c55900325c117aefb1ef4f88f83505a1cf /tests | |
parent | b4001eacd6472a3515a0eb7d80e845bd733d5bcd (diff) |
Additional ListView section header placement options
Add a section.labelPositioning property which can be a combination
of:
- ViewSection.InlineLabels - section labels are shown inline between
the item delegates separating sections (default).
- ViewSection.CurrentLabelAtStart - the current section label sticks to
the start of the view as it is moved.
- ViewSection.NextLabelAtEnd - the next section label (beyond all visible
sections) sticks to the end of the view as it is moved.
Task-number: QTBUG-12880
Change-Id: I4601828337412bd3a83769c9b8df3f6d4d7474b8
Reviewed-on: http://codereview.qt-project.org/5192
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qsglistview/data/listview-sections_delegate.qml | 4 | ||||
-rw-r--r-- | tests/auto/declarative/qsglistview/tst_qsglistview.cpp | 143 |
2 files changed, 146 insertions, 1 deletions
diff --git a/tests/auto/declarative/qsglistview/data/listview-sections_delegate.qml b/tests/auto/declarative/qsglistview/data/listview-sections_delegate.qml index 82f332c951..496d8d7784 100644 --- a/tests/auto/declarative/qsglistview/data/listview-sections_delegate.qml +++ b/tests/auto/declarative/qsglistview/data/listview-sections_delegate.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Rectangle { property string sectionProperty: "number" + property int sectionPositioning: ViewSection.InlineLabels width: 240 height: 320 color: "#ffffff" @@ -63,7 +64,8 @@ Rectangle { color: "#99bb99" height: 20 width: list.width - Text { text: section } + Text { text: section + ", " + parent.y + ", " + parent.objectName } } + section.labelPositioning: sectionPositioning } } diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp index cbd1b0189e..ce1587db88 100644 --- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp +++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp @@ -105,6 +105,7 @@ private slots: void enforceRange_withoutHighlight(); void spacing(); void sections(); + void sectionsPositioning(); void sectionsDelegate(); void cacheBuffer(); void positionViewAtIndex(); @@ -144,6 +145,7 @@ private: template <class T> void moved(); template <class T> void clear(); QSGView *createView(); + QSGItem *findVisibleChild(QSGItem *parent, const QString &objectName); template<typename T> T *findItem(QSGItem *parent, const QString &id, int index=-1); template<typename T> @@ -1701,6 +1703,135 @@ void tst_QSGListView::sectionsDelegate() delete canvas; } +void tst_QSGListView::sectionsPositioning() +{ + QSGView *canvas = createView(); + canvas->show(); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), QString::number(i/5)); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview-sections_delegate.qml")); + qApp->processEvents(); + canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QSGViewSection::InlineLabels | QSGViewSection::CurrentLabelAtStart | QSGViewSection::NextLabelAtEnd))); + + QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QSGItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + for (int i = 0; i < 3; ++i) { + QSGItem *item = findItem<QSGItem>(contentItem, "sect_" + QString::number(i)); + QVERIFY(item); + QTRY_COMPARE(item->y(), qreal(i*20*6)); + } + + QSGItem *topItem = findVisibleChild(contentItem, "sect_0"); // section header + QVERIFY(topItem); + QCOMPARE(topItem->y(), 0.); + + QSGItem *bottomItem = findVisibleChild(contentItem, "sect_3"); // section footer + QVERIFY(bottomItem); + QCOMPARE(bottomItem->y(), 300.); + + // move down a little and check that section header is at top + listview->setContentY(10); + QCOMPARE(topItem->y(), 0.); + + // push the top header up + listview->setContentY(110); + topItem = findVisibleChild(contentItem, "sect_0"); // section header + QVERIFY(topItem); + QCOMPARE(topItem->y(), 100.); + + QSGItem *item = findVisibleChild(contentItem, "sect_1"); + QVERIFY(item); + QCOMPARE(item->y(), 120.); + + bottomItem = findVisibleChild(contentItem, "sect_4"); // section footer + QVERIFY(bottomItem); + QCOMPARE(bottomItem->y(), 410.); + + // Move past section 0 + listview->setContentY(120); + topItem = findVisibleChild(contentItem, "sect_0"); // section header + QVERIFY(!topItem); + + // Push section footer down + listview->setContentY(70); + bottomItem = findVisibleChild(contentItem, "sect_4"); // section footer + QVERIFY(bottomItem); + QCOMPARE(bottomItem->y(), 380.); + + // Change current section + listview->setContentY(10); + model.modifyItem(0, "One", "aaa"); + model.modifyItem(1, "Two", "aaa"); + model.modifyItem(2, "Three", "aaa"); + model.modifyItem(3, "Four", "aaa"); + model.modifyItem(4, "Five", "aaa"); + QTest::qWait(300); + + QTRY_COMPARE(listview->currentSection(), QString("aaa")); + + for (int i = 0; i < 3; ++i) { + QSGItem *item = findItem<QSGItem>(contentItem, + "sect_" + (i == 0 ? QString("aaa") : QString::number(i))); + QVERIFY(item); + QTRY_COMPARE(item->y(), qreal(i*20*6)); + } + + topItem = findVisibleChild(contentItem, "sect_aaa"); // section header + QVERIFY(topItem); + QCOMPARE(topItem->y(), 10.); + + // remove section boundary + listview->setContentY(120); + model.removeItem(5); + QTRY_COMPARE(listview->count(), model.count()); + for (int i = 0; i < 3; ++i) { + QSGItem *item = findItem<QSGItem>(contentItem, + "sect_" + (i == 0 ? QString("aaa") : QString::number(i))); + QVERIFY(item); + QTRY_COMPARE(item->y(), qreal(i*20*6)); + } + + QTRY_VERIFY(topItem = findVisibleChild(contentItem, "sect_aaa")); // section header + QCOMPARE(topItem->y(), 120.); + QVERIFY(topItem = findVisibleChild(contentItem, "sect_1")); + QCOMPARE(topItem->y(), 140.); + + // Change the next section + listview->setContentY(0); + bottomItem = findVisibleChild(contentItem, "sect_3"); // section footer + QVERIFY(bottomItem); + QCOMPARE(bottomItem->y(), 320.); + + model.modifyItem(14, "New", "new"); + + QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_new")); // section footer + QCOMPARE(bottomItem->y(), 320.); + + // Turn sticky footer off + listview->setContentY(50); + canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QSGViewSection::InlineLabels | QSGViewSection::CurrentLabelAtStart))); + item = findVisibleChild(contentItem, "sect_new"); // inline label restored + QCOMPARE(item->y(), 360.); + + // Turn sticky header off + listview->setContentY(50); + canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QSGViewSection::InlineLabels))); + item = findVisibleChild(contentItem, "sect_aaa"); // inline label restored + QCOMPARE(item->y(), 20.); + + delete canvas; +} + void tst_QSGListView::currentIndex() { TestModel model; @@ -3491,6 +3622,18 @@ QSGView *tst_QSGListView::createView() return canvas; } +QSGItem *tst_QSGListView::findVisibleChild(QSGItem *parent, const QString &objectName) +{ + QSGItem *item = 0; + QList<QSGItem*> items = parent->findChildren<QSGItem*>(objectName); + for (int i = 0; i < items.count(); ++i) { + if (items.at(i)->isVisible()) { + item = items.at(i); + break; + } + } + return item; +} /* Find an item with the specified objectName. If index is supplied then the item must also evaluate the {index} expression equal to index |