From 44e88d2380344b138d6d916758fa80782a3d96b5 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 5 Feb 2010 15:25:27 +1000 Subject: Fix ListView tests. --- .../graphicsitems/qmlgraphicslistview.cpp | 10 +++--- .../tst_qmlgraphicslistview.cpp | 38 +++++++++++++++------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 8fb7c84..dafbef8 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -531,7 +531,7 @@ public: QmlComponent *headerComponent; FxListItem *header; enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 }; - BufferMode bufferMode; + int bufferMode; mutable qreal minExtent; mutable qreal maxExtent; @@ -675,7 +675,7 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to, bool doBuffer) FxListItem *item = 0; int pos = itemEnd + 1; while (modelIndex < model->count() && pos <= fillTo) { - //qDebug() << "refill: append item" << modelIndex; + //qDebug() << "refill: append item" << modelIndex << "pos" << pos; if (!(item = createItem(modelIndex))) break; item->setPosition(pos); @@ -969,7 +969,7 @@ void QmlGraphicsListViewPrivate::updateSections() void QmlGraphicsListViewPrivate::updateCurrentSection() { - if (sectionCriteria || visibleItems.isEmpty()) { + if (!sectionCriteria || visibleItems.isEmpty()) { currentSection = QString(); return; } @@ -1903,8 +1903,10 @@ void QmlGraphicsListView::setCacheBuffer(int b) Q_D(QmlGraphicsListView); if (d->buffer != b) { d->buffer = b; - if (isComponentComplete()) + if (isComponentComplete()) { + d->bufferMode = QmlGraphicsListViewPrivate::BufferBefore | QmlGraphicsListViewPrivate::BufferAfter; refill(); + } } } diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 87d4649..6f97030 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -93,6 +93,7 @@ private: T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); template QList findItems(QmlGraphicsItem *parent, const QString &objectName); + void dumpTree(QmlGraphicsItem *parent, int depth = 0); }; class TestObject : public QObject @@ -364,6 +365,9 @@ void tst_QmlGraphicsListView::items() T model2; ctxt->setContextProperty("testModel", &model2); + // Allow deleteLaters to process + QTest::qWait(500); + int itemCount = findItems(viewport, "wrapper").count(); QVERIFY(itemCount == 0); @@ -874,7 +878,7 @@ void tst_QmlGraphicsListView::spacing() QmlGraphicsItem *item = findItem(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); - QVERIFY(item->y() == i*20); + QCOMPARE(item->y(), i*20.0); } delete canvas; @@ -886,7 +890,7 @@ void tst_QmlGraphicsListView::sections() TestModel model; for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), QString::number(i)); + model.addItem("Item" + QString::number(i), QString::number(i/5)); QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -916,7 +920,7 @@ void tst_QmlGraphicsListView::sections() QVERIFY(item); QCOMPARE(item->height(), 40.0); - model.insertItem(3, "New Item", "3"); + model.insertItem(3, "New Item", "0"); // Section header moved item = findItem(viewport, "wrapper", 5); @@ -928,7 +932,7 @@ void tst_QmlGraphicsListView::sections() QCOMPARE(item->height(), 40.0); // insert item which will become a section header - model.insertItem(6, "Replace header", "5"); + model.insertItem(6, "Replace header", "1"); item = findItem(viewport, "wrapper", 6); QVERIFY(item); @@ -938,13 +942,13 @@ void tst_QmlGraphicsListView::sections() QVERIFY(item); QCOMPARE(item->height(), 20.0); - QVERIFY(listview->currentSection() == "0"); + QCOMPARE(listview->currentSection(), QString("0")); listview->setViewportY(140); - QVERIFY(listview->currentSection() == "1"); + QCOMPARE(listview->currentSection(), QString("1")); listview->setViewportY(20); - QVERIFY(listview->currentSection() == "0"); + QCOMPARE(listview->currentSection(), QString("0")); item = findItem(viewport, "wrapper", 1); QVERIFY(item); @@ -1314,8 +1318,8 @@ T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &obj { const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) continue; //qDebug() << "try" << item; @@ -1343,8 +1347,8 @@ QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QStr QList items; const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) continue; //qDebug() << "try" << item; @@ -1356,6 +1360,18 @@ QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QStr return items; } +void tst_QmlGraphicsListView::dumpTree(QmlGraphicsItem *parent, int depth) +{ + static QString padding(" "); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); + if(!item) + continue; + qDebug() << padding.left(depth*2) << item; + dumpTree(item, depth+1); + } +} + QTEST_MAIN(tst_QmlGraphicsListView) -- cgit v0.12