diff options
author | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-06-05 11:22:06 +0200 |
---|---|---|
committer | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-06-05 11:22:06 +0200 |
commit | c8c483e96b7bb0ebe248bd8ed2f9ba306b80635c (patch) | |
tree | 826ef08a23e5f562aa50ec52f6c77e12ac1e20a3 /tests | |
parent | c670109b5f0eeb5b8e9807255d4eb9e3a20d4580 (diff) |
Add tst_QtGraphicsTreeView::layout() test. No data for now. Also update the QtGraphicsListView and QtGraphicsTableView layout tests to check the item before using it.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qgraphicslistview/tst_qgraphicslistview.cpp | 2 | ||||
-rw-r--r-- | tests/qgraphicstableview/tst_qgraphicstableview.cpp | 1 | ||||
-rw-r--r-- | tests/qgraphicstreeview/tst_qgraphicstreeview.cpp | 104 |
3 files changed, 106 insertions, 1 deletions
diff --git a/tests/qgraphicslistview/tst_qgraphicslistview.cpp b/tests/qgraphicslistview/tst_qgraphicslistview.cpp index ac442a5..878f958 100644 --- a/tests/qgraphicslistview/tst_qgraphicslistview.cpp +++ b/tests/qgraphicslistview/tst_qgraphicslistview.cpp @@ -44,7 +44,6 @@ public: QSizeF sizeHint(int, const QStyleOptionViewItemV4 *, Qt::SizeHint, const QSizeF&) const { return QSize(20, 20); } }; - class tst_QtGraphicsListView : public QObject { Q_OBJECT @@ -575,6 +574,7 @@ void tst_QtGraphicsListView::layout() for (int j = 0; j < expectedIndexes.count(); ++j) { QtGraphicsListViewItem *item = view->itemForIndex(expectedIndexes.at(j)); + QVERIFY(item); QCOMPARE(item->index(), expectedIndexes.at(j)); QCOMPARE(item->geometry(), expectedGeometries.at(j)); } diff --git a/tests/qgraphicstableview/tst_qgraphicstableview.cpp b/tests/qgraphicstableview/tst_qgraphicstableview.cpp index 172bbed..ae4cd8a 100644 --- a/tests/qgraphicstableview/tst_qgraphicstableview.cpp +++ b/tests/qgraphicstableview/tst_qgraphicstableview.cpp @@ -191,6 +191,7 @@ void tst_QtGraphicsTableView::layout() for (int j = 0; j < expectedCells.count(); ++j) { QtCell cell = expectedCells.at(j); QtGraphicsTableViewItem *item = view->itemForCell(cell.row, cell.column); + QVERIFY(item); QCOMPARE(item->row(), cell.row); QCOMPARE(item->column(), cell.column); QCOMPARE(item->geometry(), expectedGeometries.at(j)); diff --git a/tests/qgraphicstreeview/tst_qgraphicstreeview.cpp b/tests/qgraphicstreeview/tst_qgraphicstreeview.cpp index 8e1864e..13e9080 100644 --- a/tests/qgraphicstreeview/tst_qgraphicstreeview.cpp +++ b/tests/qgraphicstreeview/tst_qgraphicstreeview.cpp @@ -23,6 +23,22 @@ #include <QtTest/QtTest> #include <qgraphicstreeview.h> +#include <qtreedefaultmodel.h> + +class GraphicsTreeView : public QtGraphicsTreeView +{ +public: + GraphicsTreeView() { } + void setController(QtTreeController *c) { QtGraphicsTreeView::setController(c); } + void setModel(QtTreeModelBase *m) { QtGraphicsTreeView::setModel(m); } +}; + +class GraphicsTreeViewItem : public QtGraphicsTreeViewItem +{ +public: + GraphicsTreeViewItem(const QtTreeModelIterator &it, QtGraphicsTreeView *view) : QtGraphicsTreeViewItem(it, view) { } + QSizeF sizeHint(int, const QStyleOptionViewItemV4 *, Qt::SizeHint, const QSizeF&) const { return QSize(20, 20); } +}; class tst_QtGraphicsTreeView : public QObject { @@ -37,13 +53,23 @@ public slots: void cleanupTestCase(); void init(); void cleanup(); + void maximumFirstIndex_data(); + void maximumFirstIndex(); + void itemAt_data(); + void itemAt(); + void layout_data(); + void layout(); private slots: void getSetCheck(); protected: + GraphicsTreeView *view; }; +Q_DECLARE_METATYPE(QList<int>) +Q_DECLARE_METATYPE(QList<QRectF>) + tst_QtGraphicsTreeView::tst_QtGraphicsTreeView() { } @@ -62,15 +88,93 @@ void tst_QtGraphicsTreeView::cleanupTestCase() void tst_QtGraphicsTreeView::init() { + view = new GraphicsTreeView(); } void tst_QtGraphicsTreeView::cleanup() { + delete view; } void tst_QtGraphicsTreeView::getSetCheck() { } +void tst_QtGraphicsTreeView::maximumFirstIndex_data() +{ +} + +void tst_QtGraphicsTreeView::maximumFirstIndex() +{ +} + +void tst_QtGraphicsTreeView::itemAt_data() +{ +} + +void tst_QtGraphicsTreeView::itemAt() +{ +} + +void tst_QtGraphicsTreeView::layout_data() +{ + QTest::addColumn<int>("branchCount"); + QTest::addColumn<int>("branchDepth"); + QTest::addColumn<QSizeF>("viewSize"); + QTest::addColumn<int>("firstIndex"); + QTest::addColumn<qreal>("horizontalOffset"); + QTest::addColumn<qreal>("verticalOffset"); + QTest::addColumn<QList<QRectF> >("expectedGeometries"); + + QTest::newRow("no items") + << 0 << 0 + << QSizeF(100, 100) + << 0 + << 0. << 0. + << QList<QRectF>(); +} + +void tst_QtGraphicsTreeView::layout() +{ + QFETCH(int, branchCount); + QFETCH(int, branchDepth); + QFETCH(QSizeF, viewSize); + QFETCH(int, firstIndex); + QFETCH(qreal, horizontalOffset); + QFETCH(qreal, verticalOffset); + QFETCH(QList<QRectF>, expectedGeometries); + + QtTreeDefaultModel model; + QStack<QtTreeDefaultItem*> parents; + parents.push(model.rootItem()); + for (int i = 0; i < branchCount; ++i) { + // add a new branch of items + for (int j = 0; j < branchDepth; ++j) + parents.push(new QtTreeDefaultItem("foo", parents.top())); + // go back to the root + for (int k = 0; k < branchDepth; ++k) + parents.pop(); + } + + view->setGeometry(QRectF(QPointF(0, 0), viewSize)); + view->setItemCreator(new QtGraphicsTreeViewItemCreator<GraphicsTreeViewItem>()); + view->setModel(&model); + view->setFirstIndex(firstIndex); + view->setHorizontalOffset(horizontalOffset); + view->setVerticalOffset(verticalOffset); + view->doLayout(); + + // ### FIXME: check whith expanded branches + + // get top item iterator and check geometries + QtTreeModelIterator it = view->itemAt(QPointF(10, 10)); + for (int j = 0; j < expectedGeometries.count(); ++j) { + QtGraphicsTreeViewItem *item = view->itemForIterator(it); + QVERIFY(item); + QCOMPARE(item->geometry(), expectedGeometries.at(j)); + view->nextItem(it); + } +} + QTEST_MAIN(tst_QtGraphicsTreeView) #include <tst_qgraphicstreeview.moc> |