summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-29 19:17:29 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-29 19:17:29 +0200
commit0230ecf7beee037f5fd8ff53a023a022ab363848 (patch)
tree6398e8852915aa5ed035cc4923716b1029c0c688 /tests
parent50aa984a068f050c115b985c549419be6874f6b9 (diff)
Add test for QtGraphicsTableView::doLayout(). Still missing test data.
Diffstat (limited to 'tests')
-rw-r--r--tests/qgraphicstableview/tst_qgraphicstableview.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/tests/qgraphicstableview/tst_qgraphicstableview.cpp b/tests/qgraphicstableview/tst_qgraphicstableview.cpp
index 437cb46..317323d 100644
--- a/tests/qgraphicstableview/tst_qgraphicstableview.cpp
+++ b/tests/qgraphicstableview/tst_qgraphicstableview.cpp
@@ -23,6 +23,23 @@
#include <QtTest/QtTest>
#include <qgraphicstableview.h>
+#include <qtabledefaultmodel.h>
+#include <qtablecontroller.h>
+
+class GraphicsTableView : public QtGraphicsTableView
+{
+public:
+ GraphicsTableView() { }
+ void setController(QtTableController *c) { QtGraphicsTableView::setController(c); }
+ void setModel(QtTableModelInterface *m) { QtGraphicsTableView::setModel(m); }
+};
+
+class GraphicsTableViewItem : public QtGraphicsTableViewItem
+{
+public:
+ GraphicsTableViewItem(int row, int column, QtGraphicsTableView *view) : QtGraphicsTableViewItem(row, column, view) { }
+ QSizeF sizeHint(int, const QStyleOptionViewItemV4 *, Qt::SizeHint, const QSizeF&) const { return QSize(20, 20); }
+};
class tst_QtGraphicsTableView : public QObject
{
@@ -40,10 +57,31 @@ public slots:
private slots:
void getSetCheck();
+ void maximumFirstRow_data();
+ void maximumFirstRow();
+ void maximumFirstColumn_data();
+ void maximumFirstColumn();
+ void cellAt_data();
+ void cellAt();
+ void layout_data();
+ void layout();
protected:
+ GraphicsTableView *view;
+};
+
+struct QtCell
+{
+ QtCell(int row = 0, int column = 0) : row(row), column(column) {}
+ int row;
+ int column;
};
+Q_DECLARE_METATYPE(QtCell)
+Q_DECLARE_METATYPE(QList<QtCell>)
+Q_DECLARE_METATYPE(QList<int>)
+Q_DECLARE_METATYPE(QList<QRectF>)
+
tst_QtGraphicsTableView::tst_QtGraphicsTableView()
{
}
@@ -62,15 +100,95 @@ void tst_QtGraphicsTableView::cleanupTestCase()
void tst_QtGraphicsTableView::init()
{
+ view = new GraphicsTableView();
}
void tst_QtGraphicsTableView::cleanup()
{
+ delete view;
}
void tst_QtGraphicsTableView::getSetCheck()
{
}
+void tst_QtGraphicsTableView::maximumFirstRow_data()
+{
+}
+
+void tst_QtGraphicsTableView::maximumFirstRow()
+{
+}
+
+void tst_QtGraphicsTableView::maximumFirstColumn_data()
+{
+}
+
+void tst_QtGraphicsTableView::maximumFirstColumn()
+{
+}
+
+void tst_QtGraphicsTableView::cellAt_data()
+{
+}
+
+void tst_QtGraphicsTableView::cellAt()
+{
+}
+
+void tst_QtGraphicsTableView::layout_data()
+{
+ QTest::addColumn<int>("rowCount");
+ QTest::addColumn<int>("columnCount");
+ QTest::addColumn<QSizeF>("size");
+ QTest::addColumn<QtCell>("firstCell");
+ QTest::addColumn<qreal>("horizontalOffset");
+ QTest::addColumn<qreal>("verticalOffset");
+ QTest::addColumn<QList<QRectF> >("expectedGeometries");
+ QTest::addColumn<QList<QtCell> >("expectedCells");
+
+ QTest::newRow("no items, vertical")
+ << 0
+ << int(Qt::Vertical)
+ << QSizeF(100, 100)
+ << QtCell()
+ << 0. << 0.
+ << QList<QRectF>()
+ << QList<QtCell>();
+}
+
+void tst_QtGraphicsTableView::layout()
+{
+ QFETCH(int, rowCount);
+ QFETCH(int, columnCount);
+ QFETCH(QSizeF, size);
+ QFETCH(QtCell, firstCell);
+ QFETCH(qreal, horizontalOffset);
+ QFETCH(qreal, verticalOffset);
+ QFETCH(QList<QRectF>, expectedGeometries);
+ QFETCH(QList<QtCell>, expectedCells);
+
+ QtTableDefaultModel model(rowCount, columnCount);
+
+ view->setGeometry(QRectF(QPointF(0, 0), size));
+ view->setItemCreator(new QtGraphicsTableViewItemCreator<GraphicsTableViewItem>());
+ view->setModel(&model);
+ view->setFirstRow(firstCell.row);
+ view->setFirstColumn(firstCell.column);
+ view->setHorizontalOffset(horizontalOffset);
+ view->setVerticalOffset(verticalOffset);
+ view->doLayout();
+
+ QList<QGraphicsItem*> items = view->childItems();
+ QCOMPARE(items.count(), expectedGeometries.count());
+ QCOMPARE(items.count(), expectedCells.count());
+ for (int j = 0; j < expectedGeometries.count(); ++j) {
+ QtGraphicsTableViewItem *item = static_cast<QtGraphicsTableViewItem*>(items.at(j));
+ QCOMPARE(item->geometry(), expectedGeometries.at(j));
+ QCOMPARE(item->row(), expectedCells.at(j).row);
+ QCOMPARE(item->column(), expectedCells.at(j).column);
+ }
+}
+
QTEST_MAIN(tst_QtGraphicsTableView)
#include <tst_qgraphicstableview.moc>