diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 139 |
1 files changed, 106 insertions, 33 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 2881f58660..36bf76564f 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -58,6 +58,8 @@ #include <qscrollbar.h> #include <qboxlayout.h> #include <qlineedit.h> +#include <qscreen.h> +#include <qscopedpointer.h> static inline void setFrameless(QWidget *w) { @@ -67,6 +69,22 @@ static inline void setFrameless(QWidget *w) w->setWindowFlags(flags); } +static inline void centerOnScreen(QWidget *w) +{ + const QPoint offset = QPoint(w->width() / 2, w->height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + +// Move cursor out of widget area to avoid undesired interaction on Mac. +static inline void moveCursorAway(const QWidget *topLevel) +{ +#ifndef QT_NO_CURSOR + QCursor::setPos(topLevel->geometry().topRight() + QPoint(100, 0)); +#else + Q_UNUSED(topLevel) +#endif +} + class TestView : public QAbstractItemView { Q_OBJECT @@ -363,25 +381,27 @@ void tst_QAbstractItemView::emptyModels() { QFETCH(QString, viewType); - TestView *view = 0; + QScopedPointer<QAbstractItemView> view; if (viewType == "QListView") - view = reinterpret_cast<TestView*>(new QListView()); + view.reset(new QListView()); else if (viewType == "QTableView") - view = reinterpret_cast<TestView*>(new QTableView()); + view.reset(new QTableView()); else if (viewType == "QTreeView") - view = reinterpret_cast<TestView*>(new QTreeView()); + view.reset(new QTreeView()); else if (viewType == "QHeaderView") - view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical)); + view.reset(new QHeaderView(Qt::Vertical)); else QVERIFY(0); + centerOnScreen(view.data()); + moveCursorAway(view.data()); view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); QVERIFY(!view->model()); QVERIFY(!view->selectionModel()); //QVERIFY(view->itemDelegate() != 0); - basic_tests(view); - delete view; + basic_tests(reinterpret_cast<TestView*>(view.data())); } void tst_QAbstractItemView::setModel_data() @@ -397,24 +417,28 @@ void tst_QAbstractItemView::setModel_data() void tst_QAbstractItemView::setModel() { QFETCH(QString, viewType); - TestView *view = 0; + + QScopedPointer<QAbstractItemView> view; + if (viewType == "QListView") - view = reinterpret_cast<TestView*>(new QListView()); + view.reset(new QListView()); else if (viewType == "QTableView") - view = reinterpret_cast<TestView*>(new QTableView()); + view.reset(new QTableView()); else if (viewType == "QTreeView") - view = reinterpret_cast<TestView*>(new QTreeView()); + view.reset(new QTreeView()); else if (viewType == "QHeaderView") - view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical)); + view.reset(new QHeaderView(Qt::Vertical)); else QVERIFY(0); + centerOnScreen(view.data()); + moveCursorAway(view.data()); view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); QStandardItemModel model(20,20); view->setModel(0); view->setModel(&model); - basic_tests(view); - delete view; + basic_tests(reinterpret_cast<TestView*>(view.data())); } void tst_QAbstractItemView::basic_tests(TestView *view) @@ -625,7 +649,10 @@ void tst_QAbstractItemView::noModel() view.setModel(&model); // Make the viewport smaller than the contents, so that we can scroll view.resize(100,100); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); // make sure that the scrollbars are not at value 0 view.scrollTo(view.model()->index(10,10)); @@ -645,7 +672,10 @@ void tst_QAbstractItemView::dragSelect() QTableView view; view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.setVisible(true); + QVERIFY(QTest::qWaitForWindowExposed(&view)); const int delay = 2; for (int i = 0; i < 2; ++i) { @@ -666,7 +696,10 @@ void tst_QAbstractItemView::rowDelegate() QTableView view; view.setModel(&model); view.setItemDelegateForRow(3, &delegate); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex index = model.index(3, 0); view.openPersistentEditor(index); @@ -683,7 +716,10 @@ void tst_QAbstractItemView::columnDelegate() QTableView view; view.setModel(&model); view.setItemDelegateForColumn(3, &delegate); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex index = model.index(0, 3); view.openPersistentEditor(index); @@ -736,8 +772,10 @@ void tst_QAbstractItemView::persistentEditorFocus() view.setCurrentIndex(model.index(0, 0)); QCOMPARE(view.currentIndex(), model.index(0, 0)); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); - QTRY_VERIFY(view.isVisible()); + QVERIFY(QTest::qWaitForWindowExposed(&view)); for (int i = 0; i < list.count(); ++i) { QTRY_VERIFY(list.at(i)->isVisible()); @@ -1034,6 +1072,8 @@ void tst_QAbstractItemView::setItemDelegate() } } } + centerOnScreen(&v); + moveCursorAway(&v); v.show(); #ifdef Q_WS_X11 QCursor::setPos(v.geometry().center()); @@ -1111,20 +1151,25 @@ void tst_QAbstractItemView::setCurrentIndex() QFETCH(int, itemFlags); QFETCH(bool, result); - TestView *view = 0; + QScopedPointer<QAbstractItemView> view; + if (viewType == "QListView") - view = reinterpret_cast<TestView*>(new QListView()); + view.reset(new QListView()); else if (viewType == "QTableView") - view = reinterpret_cast<TestView*>(new QTableView()); + view.reset(new QTableView()); else if (viewType == "QTreeView") - view = reinterpret_cast<TestView*>(new QTreeView()); + view.reset(new QTreeView()); else if (viewType == "QHeaderView") - view = reinterpret_cast<TestView*>(new QHeaderView(Qt::Vertical)); + view.reset(new QHeaderView(Qt::Vertical)); else QVERIFY(0); + + centerOnScreen(view.data()); + moveCursorAway(view.data()); view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); - QStandardItemModel *model = new QStandardItemModel(view); + QStandardItemModel *model = new QStandardItemModel(view.data()); QStandardItem *item = new QStandardItem("first item"); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); model->appendRow(item); @@ -1139,8 +1184,6 @@ void tst_QAbstractItemView::setCurrentIndex() QVERIFY(view->currentIndex() == model->index(0,0)); view->setCurrentIndex(model->index(1,0)); QVERIFY(view->currentIndex() == model->index(result ? 1 : 0,0)); - - delete view; } void tst_QAbstractItemView::task221955_selectedEditor() @@ -1159,11 +1202,13 @@ void tst_QAbstractItemView::task221955_selectedEditor() tree.setItemWidget(dummy, 0, button = new QPushButton("More...")); button->setAutoFillBackground(true); // as recommended in doc + centerOnScreen(&tree); + moveCursorAway(&tree); tree.show(); tree.setFocus(); tree.setCurrentIndex(tree.model()->index(1,0)); - QTest::qWait(100); QApplication::setActiveWindow(&tree); + QVERIFY(QTest::qWaitForWindowActive(&tree)); QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); @@ -1207,9 +1252,11 @@ void tst_QAbstractItemView::task250754_fontChange() } tree.setModel(m); + w.resize(160, 240); // Minimum width for windows with frame on Windows 8 + centerOnScreen(&w); + moveCursorAway(&w); w.show(); - w.resize(150,240); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowExposed(&w)); QFont font = tree.font(); font.setPixelSize(10); tree.setFont(font); @@ -1233,8 +1280,10 @@ void tst_QAbstractItemView::task200665_itemEntered() QStandardItemModel model(1000,1); QListView view; view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); - QTest::qWait(200); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QRect rect = view.visualRect(model.index(0,0)); QCursor::setPos( view.viewport()->mapToGlobal(rect.center()) ); QSignalSpy spy(&view, SIGNAL(entered(QModelIndex))); @@ -1256,7 +1305,10 @@ void tst_QAbstractItemView::task257481_emptyEditor() QTreeView treeView; treeView.setRootIsDecorated(false); treeView.setModel(&model); + centerOnScreen(&treeView); + moveCursorAway(&treeView); treeView.show(); + QVERIFY(QTest::qWaitForWindowExposed(&treeView)); treeView.edit(model.index(0,0)); QList<QLineEdit *> lineEditors = treeView.viewport()->findChildren<QLineEdit *>(); @@ -1287,14 +1339,16 @@ void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling() } QListView view; - view.setFixedSize(150, 250); + view.setFixedSize(160, 250); // Minimum width for windows with frame on Windows 8 view.setFlow(QListView::LeftToRight); view.setGridSize(QSize(100, 100)); view.setSelectionMode(QListView::ExtendedSelection); view.setViewMode(QListView::IconMode); view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex index0 = model.index(0, 0); QModelIndex index1 = model.index(1, 0); @@ -1322,14 +1376,16 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection() } QListView view; - view.setFixedSize(150, 450); + view.setFixedSize(160, 450); // Minimum width for windows with frame on Windows 8 view.setFlow(QListView::LeftToRight); view.setGridSize(QSize(100, 100)); view.setSelectionMode(QListView::ExtendedSelection); view.setViewMode(QListView::IconMode); view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex index0 = model.index(0, 0); QModelIndex index1 = model.index(1, 0); @@ -1397,14 +1453,16 @@ void tst_QAbstractItemView::ctrlRubberbandSelection() } QListView view; - view.setFixedSize(150, 450); + view.setFixedSize(160, 450); // Minimum width for windows with frame on Windows 8 view.setFlow(QListView::LeftToRight); view.setGridSize(QSize(100, 100)); view.setSelectionMode(QListView::ExtendedSelection); view.setViewMode(QListView::IconMode); view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex index1 = model.index(1, 0); QModelIndex index2 = model.index(2, 0); @@ -1443,6 +1501,8 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection() font.setPixelSize(10); view.setFont(font); view.resize(200,240); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); QApplication::setActiveWindow(&view); @@ -1482,7 +1542,11 @@ void tst_QAbstractItemView::QTBUG6753_selectOnSelection() for (int j = 0; j < table.columnCount(); ++j) table.setItem(i, j, new QTableWidgetItem("choo-be-doo-wah")); + centerOnScreen(&table); + moveCursorAway(&table); table.show(); + QVERIFY(QTest::qWaitForWindowExposed(&table)); + table.setSelectionMode(QAbstractItemView::ExtendedSelection); table.selectAll(); QVERIFY(QTest::qWaitForWindowExposed(&table)); @@ -1512,6 +1576,8 @@ void tst_QAbstractItemView::testClickedSignal() { QTableWidget view(5, 5); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1580,6 +1646,8 @@ void tst_QAbstractItemView::testChangeEditorState() view.setEditTriggers(QAbstractItemView::CurrentChanged); view.setItemDelegate(new StateChangeDelegate); view.setModel(&model); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1596,7 +1664,10 @@ void tst_QAbstractItemView::deselectInSingleSelection() s.setRowCount(10); s.setColumnCount(10); view.setModel(&s); + centerOnScreen(&view); + moveCursorAway(&view); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); view.setSelectionMode(QAbstractItemView::SingleSelection); view.setEditTriggers(QAbstractItemView::NoEditTriggers); QApplication::setActiveWindow(&view); @@ -1639,6 +1710,8 @@ void tst_QAbstractItemView::testNoActivateOnDisabledItem() model.setItem(0, 0, item); item->setFlags(Qt::NoItemFlags); treeView.setModel(&model); + centerOnScreen(&treeView); + moveCursorAway(&treeView); treeView.show(); QApplication::setActiveWindow(&treeView); |