summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-09-07 22:15:47 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-09-09 12:04:15 +0000
commit85917c4b72a498e86d6dd057a5b6df26c0565fc4 (patch)
tree7f5481ce32b7b6d6c3b8eec803925b45222d2844 /tests
parentef40cad3a974242cc8f9167288a8804239586669 (diff)
Autotests/QItemView: re-enable tst_QItemView::indexAt()
tst_QItemView::indexAt() was disabled since Qt 5.0 (and maybe earlier) maybe due to it's long runtime (15s on my machine). Speed it up by checking only some special positions inside the visual rect (borders, center) as it will likely not fail on other positions but succeed for the ones which get tested. Task-number: QTBUG-22470 Change-Id: I5c7135757049176f9daca4afc1b7f40c75b9ecd9 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
index afd6d84486..bbdaac5c6f 100644
--- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
@@ -546,23 +546,26 @@ void tst_QItemView::walkScreen(QAbstractItemView *view)
}
}
-void walkIndex(QModelIndex index, QAbstractItemView *view)
+void walkIndex(const QModelIndex &index, const QAbstractItemView *view)
{
- QRect visualRect = view->visualRect(index);
- //if (index.column() == 0)
- //qDebug() << index << visualRect;
- int width = visualRect.width();
- int height = visualRect.height();
+ const QRect visualRect = view->visualRect(index);
+ const int width = visualRect.width();
+ const int height = visualRect.height();
- for (int w = 0; w < width; ++w)
+ if (width == 0 || height == 0)
+ return;
+
+ const auto widths = (width < 2) ? QVector<int>({ 0, 1 }) : QVector<int>({ 0, 1, width / 2, width - 2, width - 1 });
+ const auto heights = (height < 2) ? QVector<int>({ 0, 1 }) : QVector<int>({ 0, 1, height / 2, height - 2, height - 1 });
+ for (int w : widths)
{
- for (int h = 0; h < height; ++h)
+ for (int h : heights)
{
- QPoint point(visualRect.x()+w, visualRect.y()+h);
- if (view->indexAt(point) != index) {
+ const QPoint point(visualRect.x() + w, visualRect.y() + h);
+ const auto idxAt = view->indexAt(point);
+ if (idxAt != index)
qDebug() << "index" << index << "visualRect" << visualRect << point << view->indexAt(point);
- }
- QCOMPARE(view->indexAt(point), index);
+ QCOMPARE(idxAt, index);
}
}
@@ -579,7 +582,7 @@ void walkIndex(QModelIndex index, QAbstractItemView *view)
a bug it will point it out, but the above tests should have already found the basic bugs
because it is easier to figure out the problem in those tests then this one.
*/
-void checkChildren(QAbstractItemView *currentView, const QModelIndex &parent = QModelIndex(), int currentDepth=0)
+void checkChildren(const QAbstractItemView *currentView, const QModelIndex &parent = QModelIndex(), int currentDepth = 0)
{
QAbstractItemModel *currentModel = currentView->model();
@@ -623,7 +626,6 @@ void tst_QItemView::indexAt()
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
view->show();
view->setModel(treeModel);
-#if 0
checkChildren(view);
QModelIndex index = view->model()->index(0, 0);
@@ -636,7 +638,6 @@ void tst_QItemView::indexAt()
QPoint p(1, view->height()/2);
QModelIndex idx = view->indexAt(p);
QCOMPARE(idx, QModelIndex());
-#endif
}
void tst_QItemView::scrollTo_data()