tst_QListView: cleanup

Cleanup QListView autotest:
 - fix indentation
 - use QCoreApplication::sendEvent instead of QApplication::sendEvent

Change-Id: If6bb686502f6b4f2bc2dd0db52b331b2c35cf36d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-09-08 20:06:46 +02:00 committed by Edward Welbourne
parent 2431765d57
commit efb9f2e1e4

View File

@ -1058,9 +1058,9 @@ void tst_QListView::selection()
QFETCH(bool, wrapping); QFETCH(bool, wrapping);
QFETCH(int, spacing); QFETCH(int, spacing);
QFETCH(QSize, gridSize); QFETCH(QSize, gridSize);
QFETCH(IntList, hiddenRows); QFETCH(const IntList, hiddenRows);
QFETCH(QRect, selectionRect); QFETCH(QRect, selectionRect);
QFETCH(IntList, expectedItems); QFETCH(const IntList, expectedItems);
QWidget topLevel; QWidget topLevel;
PublicListView v(&topLevel); PublicListView v(&topLevel);
@ -1079,8 +1079,8 @@ void tst_QListView::selection()
v.setSpacing(spacing); v.setSpacing(spacing);
if (gridSize.isValid()) if (gridSize.isValid())
v.setGridSize(gridSize); v.setGridSize(gridSize);
for (int j = 0; j < hiddenRows.count(); ++j) for (int row : hiddenRows)
v.setRowHidden(hiddenRows.at(j), true); v.setRowHidden(row, true);
v.resize(525, 525); v.resize(525, 525);
@ -1089,11 +1089,10 @@ void tst_QListView::selection()
v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect); v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect);
QModelIndexList selected = v.selectionModel()->selectedIndexes(); const QModelIndexList selected = v.selectionModel()->selectedIndexes();
QCOMPARE(selected.count(), expectedItems.count()); QCOMPARE(selected.count(), expectedItems.count());
for (int i = 0; i < selected.count(); ++i) for (const auto &idx : selected)
QVERIFY(expectedItems.contains(selected.at(i).row())); QVERIFY(expectedItems.contains(idx.row()));
} }
void tst_QListView::scrollTo() void tst_QListView::scrollTo()
@ -1152,15 +1151,14 @@ void tst_QListView::scrollTo()
QPoint p = lv.visualRect(index).center(); QPoint p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p); QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed //let's wait because the scrolling is delayed
QTest::qWait(QApplication::doubleClickInterval() + 150);
QTRY_COMPARE(lv.visualRect(index).y(), 0); QTRY_COMPARE(lv.visualRect(index).y(), 0);
//we scroll down. As the item is to tall for the view, it will disappear //we scroll down. As the item is to tall for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier); QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).y(), -itemsize.height()); QTRY_COMPARE(lv.visualRect(index).y(), -itemsize.height());
QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier); QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).y(), 0); QTRY_COMPARE(lv.visualRect(index).y(), 0);
//Let's enable wrapping //Let's enable wrapping
@ -1170,16 +1168,14 @@ void tst_QListView::scrollTo()
//we click the item //we click the item
p = lv.visualRect(index).center(); p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p); QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed
QTest::qWait(QApplication::doubleClickInterval() + 150);
QTRY_COMPARE(lv.visualRect(index).x(), 0); QTRY_COMPARE(lv.visualRect(index).x(), 0);
//we scroll right. As the item is too wide for the view, it will disappear //we scroll right. As the item is too wide for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier); QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).x(), -itemsize.width()); QTRY_COMPARE(lv.visualRect(index).x(), -itemsize.width());
QTest::keyClick(lv.viewport(), Qt::Key_Left, Qt::NoModifier); QTest::keyClick(lv.viewport(), Qt::Key_Left, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).x(), 0); QTRY_COMPARE(lv.visualRect(index).x(), 0);
lv.setWrapping(false); lv.setWrapping(false);
QCoreApplication::processEvents(); //let the layout happen QCoreApplication::processEvents(); //let the layout happen
@ -1498,7 +1494,7 @@ void tst_QListView::task203585_selectAll()
//we make sure that "select all" doesn't select the hidden items //we make sure that "select all" doesn't select the hidden items
QListView view; QListView view;
view.setSelectionMode(QAbstractItemView::ExtendedSelection); view.setSelectionMode(QAbstractItemView::ExtendedSelection);
view.setModel(new QStringListModel(QStringList() << "foo", &view)); view.setModel(new QStringListModel({"foo"}, &view));
view.setRowHidden(0, true); view.setRowHidden(0, true);
view.selectAll(); view.selectAll();
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty()); QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
@ -2403,13 +2399,13 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
int hValue = lv.horizontalScrollBar()->value(); int hValue = lv.horizontalScrollBar()->value();
QApplication::sendEvent(lv.viewport(), &wheelDownEvent); QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.horizontalScrollBar()->value() > hValue); QVERIFY(lv.horizontalScrollBar()->value() > hValue);
QApplication::sendEvent(lv.viewport(), &wheelUpEvent); QCoreApplication::sendEvent(lv.viewport(), &wheelUpEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue); QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
QApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent); QCoreApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue); QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
// ensure that vertical wheel events are not converted when vertical // ensure that vertical wheel events are not converted when vertical
@ -2419,7 +2415,7 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
QCoreApplication::processEvents(); QCoreApplication::processEvents();
int vValue = lv.verticalScrollBar()->value(); int vValue = lv.verticalScrollBar()->value();
QApplication::sendEvent(lv.viewport(), &wheelDownEvent); QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.verticalScrollBar()->value() > vValue); QVERIFY(lv.verticalScrollBar()->value() > vValue);
#else #else
QSKIP("Built with --no-feature-wheelevent"); QSKIP("Built with --no-feature-wheelevent");
@ -2553,9 +2549,9 @@ void tst_QListView::internalDragDropMove()
{ {
const QPoint pos = list.rect().center(); const QPoint pos = list.rect().center();
QMouseEvent mouseMove(QEvent::MouseMove, pos, list.mapToGlobal(pos), Qt::NoButton, {}, {}); QMouseEvent mouseMove(QEvent::MouseMove, pos, list.mapToGlobal(pos), Qt::NoButton, {}, {});
QApplication::sendEvent(&list, &mouseMove); QCoreApplication::sendEvent(&list, &mouseMove);
QMouseEvent mouseRelease(QEvent::MouseButtonRelease, pos, list.mapToGlobal(pos), Qt::LeftButton, {}, {}); QMouseEvent mouseRelease(QEvent::MouseButtonRelease, pos, list.mapToGlobal(pos), Qt::LeftButton, {}, {});
QApplication::sendEvent(&list, &mouseRelease); QCoreApplication::sendEvent(&list, &mouseRelease);
}); });
const int expectedCount = data.rowCount(); const int expectedCount = data.rowCount();
list.startDrag(Qt::MoveAction|Qt::CopyAction); list.startDrag(Qt::MoveAction|Qt::CopyAction);