summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-05 10:51:42 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-05 10:51:42 +0200
commitc21766c925726578aeb7abd733ab52ef8086c85a (patch)
tree32d8a7b1cc329556da0efb1add36d4a0a118dec6
parent63ca79ec8816c94bf54bbc7b4ad25a36e0251f1b (diff)
Update the tests to use QtGraphicsListView::itemForIndex().
-rw-r--r--tests/qgraphicslistview/tst_qgraphicslistview.cpp93
1 files 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<int>("count");
QTest::addColumn<int>("orientation");
- QTest::addColumn<QSizeF>("size");
+ QTest::addColumn<QSizeF>("viewSize");
QTest::addColumn<int>("firstIndex");
QTest::addColumn<qreal>("horizontalOffset");
QTest::addColumn<qreal>("verticalOffset");
- QTest::addColumn<QList<QRectF> >("expectedGeometries");
QTest::addColumn<QList<int> >("expectedIndexes");
+ QTest::addColumn<QList<QRectF> >("expectedGeometries");
QTest::newRow("no items, vertical")
<< 0
@@ -396,9 +396,8 @@ void tst_QtGraphicsListView::layout_data()
<< QSizeF(100, 100)
<< 0
<< 0. << 0.
- << QList<QRectF>()
- << QList<int>();
-
+ << QList<int>()
+ << QList<QRectF>();
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>() << QRectF(0, 0, 20, 20))
- << (QList<int>() << 0);
-
+ << (QList<int>() << 0)
+ << (QList<QRectF>() << 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<int>()
+ << 0 << 1 << 2 << 3 << 4)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 0 << 1 << 2 << 3 << 4)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 5 << 6 << 7 << 8 << 9)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 0 << 1 << 2 << 3 << 4 << 5)
<< (QList<QRectF>()
<< 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<int>()
- << 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<QRectF>()
- << QList<int>();
-
+ << QList<int>()
+ << QList<QRectF>();
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>() << QRectF(0, 0, 20, 20))
- << (QList<int>() << 0);
-
+ << (QList<int>() << 0)
+ << (QList<QRectF>() << 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<int>()
+ << 0 << 1 << 2 << 3 << 4)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 0 << 1 << 2 << 3 << 4)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 5 << 6 << 7 << 8 << 9)
<< (QList<QRectF>()
<< 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<int>()
- << 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<int>()
+ << 0 << 1 << 2 << 3 << 4 << 5)
<< (QList<QRectF>()
<< 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<int>()
- << 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<QRectF>, expectedGeometries);
QFETCH(QList<int>, expectedIndexes);
+ QFETCH(QList<QRectF>, expectedGeometries);
QtListDefaultModel model;
for (int i = 0; i < count; ++i)
model.insertItem(i, new QtListDefaultItem());
view->setOrientation(static_cast<Qt::Orientation>(orientation));
- view->setGeometry(QRectF(QPointF(0, 0), size));
+ view->setGeometry(QRectF(QPointF(0, 0), viewSize));
view->setItemCreator(new QtGraphicsListViewItemCreator<GraphicsListViewItem>());
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<QtGraphicsListViewItem*> 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));
}
}