diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-06 06:15:17 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-06 06:15:17 (GMT) |
commit | dc7acac9552ce556d0388a11f6c5584ea8e10ae3 (patch) | |
tree | b62f780acdf1408885792da282025fcdbf68aeda | |
parent | 3a051866fb139afa08fcf1a0c17a171bce567480 (diff) | |
download | Qt-dc7acac9552ce556d0388a11f6c5584ea8e10ae3.zip Qt-dc7acac9552ce556d0388a11f6c5584ea8e10ae3.tar.gz Qt-dc7acac9552ce556d0388a11f6c5584ea8e10ae3.tar.bz2 |
Better section testing... and bug fixing.
3 files changed, 35 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 1f5d51d..59137a7 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -1748,6 +1748,7 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) d->updateUnrequestedIndexes(); if (!d->visibleItems.count() || d->model->count() <= 1) { d->layout(); + d->updateSections(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; @@ -1827,6 +1828,7 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) added.at(j)->attached->emitAdd(); d->updateUnrequestedPositions(); d->updateViewport(); + d->updateSections(); emit countChanged(); } @@ -2009,6 +2011,7 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) d->visibleItems.first()->setPosition(firstItemPos); d->layout(); + d->updateSections(); } void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml index 56700be..2edc0bd 100644 --- a/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml @@ -54,6 +54,6 @@ Rectangle { height: 320 model: testModel delegate: myDelegate - sectionExpression: "Math.floor(index/5)" + sectionExpression: "Math.floor(number/5)" } } diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 9f904b8..0015c48 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -702,7 +702,7 @@ void tst_QmlGraphicsListView::sections() TestModel model; for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); + model.addItem("Item" + QString::number(i), QString::number(i)); QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -724,6 +724,36 @@ void tst_QmlGraphicsListView::sections() QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); } + // Remove section boundary + model.removeItem(5); + + // New section header created + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", 5); + QVERIFY(item); + QCOMPARE(item->height(), 40.0); + + model.insertItem(3, "New Item", "3"); + + // Section header moved + item = findItem<QmlGraphicsItem>(viewport, "wrapper", 5); + QVERIFY(item); + QCOMPARE(item->height(), 20.0); + + item = findItem<QmlGraphicsItem>(viewport, "wrapper", 6); + QVERIFY(item); + QCOMPARE(item->height(), 40.0); + + // insert item which will become a section header + model.insertItem(6, "Replace header", "5"); + + item = findItem<QmlGraphicsItem>(viewport, "wrapper", 6); + QVERIFY(item); + QCOMPARE(item->height(), 40.0); + + item = findItem<QmlGraphicsItem>(viewport, "wrapper", 7); + QVERIFY(item); + QCOMPARE(item->height(), 20.0); + QVERIFY(listview->currentSection() == "0"); listview->setViewportY(140); |