From c21766c925726578aeb7abd733ab52ef8086c85a Mon Sep 17 00:00:00 2001 From: Marius Bugge Monsen Date: Fri, 5 Jun 2009 10:51:42 +0200 Subject: Update the tests to use QtGraphicsListView::itemForIndex(). --- tests/qgraphicslistview/tst_qgraphicslistview.cpp | 93 ++++++++++------------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/tests/qgraphicslistview/tst_qgraphicslistview.cpp b/tests/qgraphicslistview/tst_qgraphicslistview.cpp index 292b67c..ac442a5 100644 --- a/tests/qgraphicslistview/tst_qgraphicslistview.cpp +++ b/tests/qgraphicslistview/tst_qgraphicslistview.cpp @@ -383,12 +383,12 @@ void tst_QtGraphicsListView::layout_data() { QTest::addColumn("count"); QTest::addColumn("orientation"); - QTest::addColumn("size"); + QTest::addColumn("viewSize"); QTest::addColumn("firstIndex"); QTest::addColumn("horizontalOffset"); QTest::addColumn("verticalOffset"); - QTest::addColumn >("expectedGeometries"); QTest::addColumn >("expectedIndexes"); + QTest::addColumn >("expectedGeometries"); QTest::newRow("no items, vertical") << 0 @@ -396,9 +396,8 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. - << QList() - << QList(); - + << QList() + << QList(); QTest::newRow("one item, vertical, all visible") << 1 @@ -406,9 +405,8 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. - << (QList() << QRectF(0, 0, 20, 20)) - << (QList() << 0); - + << (QList() << 0) + << (QList() << QRectF(0, 0, 20, 20)); QTest::newRow("five items, vertical, all visible") << 5 @@ -416,14 +414,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. + << (QList() + << 0 << 1 << 2 << 3 << 4) << (QList() << QRectF(0, 0, 20, 20) << QRectF(0, 20, 20, 20) << QRectF(0, 40, 20, 20) << QRectF(0, 60, 20, 20) - << QRectF(0, 80, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4); + << QRectF(0, 80, 20, 20)); QTest::newRow("ten items, vertical, five visible") << 10 @@ -431,14 +429,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. + << (QList() + << 0 << 1 << 2 << 3 << 4) << (QList() << QRectF(0, 0, 20, 20) << QRectF(0, 20, 20, 20) << QRectF(0, 40, 20, 20) << QRectF(0, 60, 20, 20) - << QRectF(0, 80, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4); + << QRectF(0, 80, 20, 20)); QTest::newRow("ten items, vertical, five visible, first item five") << 10 @@ -446,14 +444,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 5 << 0. << 0. + << (QList() + << 5 << 6 << 7 << 8 << 9) << (QList() << QRectF(0, 0, 20, 20) << QRectF(0, 20, 20, 20) << QRectF(0, 40, 20, 20) << QRectF(0, 60, 20, 20) - << QRectF(0, 80, 20, 20)) - << (QList() - << 5 << 6 << 7 << 8 << 9); + << QRectF(0, 80, 20, 20)); QTest::newRow("ten items, vertical, five visible, vertical offset") << 10 @@ -461,15 +459,15 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 10. + << (QList() + << 0 << 1 << 2 << 3 << 4 << 5) << (QList() << QRectF(0, -10, 20, 20) << QRectF(0, 10, 20, 20) << QRectF(0, 30, 20, 20) << QRectF(0, 50, 20, 20) << QRectF(0, 70, 20, 20) - << QRectF(0, 90, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4 << 5); + << QRectF(0, 90, 20, 20)); QTest::newRow("no items, horizontal") << 0 @@ -477,9 +475,8 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. - << QList() - << QList(); - + << QList() + << QList(); QTest::newRow("one item, horizontal, all visible") << 1 @@ -487,9 +484,8 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. - << (QList() << QRectF(0, 0, 20, 20)) - << (QList() << 0); - + << (QList() << 0) + << (QList() << QRectF(0, 0, 20, 20)); QTest::newRow("five items, horizontal, all visible") << 5 @@ -497,14 +493,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. + << (QList() + << 0 << 1 << 2 << 3 << 4) << (QList() << QRectF(0, 0, 20, 20) << QRectF(20, 0, 20, 20) << QRectF(40, 0, 20, 20) << QRectF(60, 0, 20, 20) - << QRectF(80, 0, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4); + << QRectF(80, 0, 20, 20)); QTest::newRow("ten items, horizontal, five visible") << 10 @@ -512,14 +508,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 0. << 0. + << (QList() + << 0 << 1 << 2 << 3 << 4) << (QList() << QRectF(0, 0, 20, 20) << QRectF(20, 0, 20, 20) << QRectF(40, 0, 20, 20) << QRectF(60, 0, 20, 20) - << QRectF(80, 0, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4); + << QRectF(80, 0, 20, 20)); QTest::newRow("ten items, horizontal, five visible, first item five") << 10 @@ -527,14 +523,14 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 5 << 0. << 0. + << (QList() + << 5 << 6 << 7 << 8 << 9) << (QList() << QRectF(0, 0, 20, 20) << QRectF(20, 0, 20, 20) << QRectF(40, 0, 20, 20) << QRectF(60, 0, 20, 20) - << QRectF(80, 0, 20, 20)) - << (QList() - << 5 << 6 << 7 << 8 << 9); + << QRectF(80, 0, 20, 20)); QTest::newRow("ten items, horizontal, five visible, horizontal offset") << 10 @@ -542,34 +538,34 @@ void tst_QtGraphicsListView::layout_data() << QSizeF(100, 100) << 0 << 10. << 0. + << (QList() + << 0 << 1 << 2 << 3 << 4 << 5) << (QList() << QRectF(-10, 0, 20, 20) << QRectF(10, 0, 20, 20) << QRectF(30, 0, 20, 20) << QRectF(50, 0, 20, 20) << QRectF(70, 0, 20, 20) - << QRectF(90, 0, 20, 20)) - << (QList() - << 0 << 1 << 2 << 3 << 4 << 5); + << QRectF(90, 0, 20, 20)); } void tst_QtGraphicsListView::layout() { QFETCH(int, count); QFETCH(int, orientation); - QFETCH(QSizeF, size); + QFETCH(QSizeF, viewSize); QFETCH(int, firstIndex); QFETCH(qreal, horizontalOffset); QFETCH(qreal, verticalOffset); - QFETCH(QList, expectedGeometries); QFETCH(QList, expectedIndexes); + QFETCH(QList, expectedGeometries); QtListDefaultModel model; for (int i = 0; i < count; ++i) model.insertItem(i, new QtListDefaultItem()); view->setOrientation(static_cast(orientation)); - view->setGeometry(QRectF(QPointF(0, 0), size)); + view->setGeometry(QRectF(QPointF(0, 0), viewSize)); view->setItemCreator(new QtGraphicsListViewItemCreator()); view->setModel(&model); view->setFirstIndex(firstIndex); @@ -577,17 +573,10 @@ void tst_QtGraphicsListView::layout() view->setVerticalOffset(verticalOffset); view->doLayout(); - // ### FIXME: find a better way to get the visible items - QList visibleItems; - for (int j = 0; j < count; ++j) - if (QtGraphicsListViewItem *item = view->itemForIndex(j)) - visibleItems.append(item); - - QCOMPARE(visibleItems.count(), expectedGeometries.count()); - QCOMPARE(visibleItems.count(), expectedIndexes.count()); - for (int j = 0; j < expectedGeometries.count(); ++j) { - QCOMPARE(visibleItems.at(j)->geometry(), expectedGeometries.at(j)); - QCOMPARE(visibleItems.at(j)->index(), expectedIndexes.at(j)); + for (int j = 0; j < expectedIndexes.count(); ++j) { + QtGraphicsListViewItem *item = view->itemForIndex(expectedIndexes.at(j)); + QCOMPARE(item->index(), expectedIndexes.at(j)); + QCOMPARE(item->geometry(), expectedGeometries.at(j)); } } -- cgit v1.2.3