diff options
Diffstat (limited to 'tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp')
-rw-r--r-- | tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 44195d3b25..b26516ee6b 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -270,6 +270,12 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override { + if (onlyValidCalls) { + Q_ASSERT(row >= 0); + Q_ASSERT(column >= 0); + Q_ASSERT(row < rows); + Q_ASSERT(column < cols); + } if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) { return QModelIndex(); } @@ -378,6 +384,7 @@ public: mutable bool fetched = false; bool decorationsEnabled = false; bool statusTipsEnabled = false; + bool onlyValidCalls = false; }; // Testing get/set functions @@ -952,6 +959,7 @@ void tst_QTreeView::indexWidget() QStandardItemModel treeModel; initStandardTreeModel(&treeModel); view.setModel(&treeModel); + view.resize(300, 400); // make sure the width of the view is larger than the widgets below QModelIndex index = view.model()->index(0, 0); @@ -980,6 +988,7 @@ void tst_QTreeView::indexWidget() //now let's try to do that later when the widget is already shown view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); index = view.model()->index(1, 0); QVERIFY(!view.indexWidget(index)); @@ -2418,6 +2427,7 @@ void tst_QTreeView::hiddenItems() void tst_QTreeView::spanningItems() { QtTestModel model(10, 10); + model.onlyValidCalls = true; QTreeView view; view.setModel(&model); view.show(); @@ -2457,6 +2467,8 @@ void tst_QTreeView::spanningItems() } } QCOMPARE(view.sizeHintForColumn(0), w); + + view.repaint(); // to check that this doesn't hit any assert } void tst_QTreeView::selectionOrderTest() @@ -2862,6 +2874,7 @@ public: }; Node *root; + bool crash = false; EvilModel(QObject *parent = nullptr): QAbstractItemModel(parent), root(new Node) {} @@ -2870,6 +2883,11 @@ public: delete root; } + void setCrash() + { + crash = true; + } + void change() { emit layoutAboutToBeChanged(); @@ -2938,6 +2956,10 @@ public: QVariant data(const QModelIndex &idx, int role) const override { + if (crash) { + QTest::qFail("Should not get here...", __FILE__, __LINE__); + return QVariant(); + } if (idx.isValid() && role == Qt::DisplayRole) { Node *parentNode = root; if (idx.isValid()) { @@ -2957,6 +2979,7 @@ void tst_QTreeView::evilModel_data() { QTest::addColumn<bool>("visible"); QTest::newRow("visible") << false; + QTest::newRow("visible") << true; } void tst_QTreeView::evilModel() @@ -3126,6 +3149,9 @@ void tst_QTreeView::evilModel() model.change(); view.setRootIndex(secondLevel); + + model.setCrash(); + view.setModel(nullptr); } void tst_QTreeView::indexRowSizeHint() @@ -4861,13 +4887,27 @@ void tst_QTreeView::taskQTBUG_61476() const QPoint pos = rect.center(); QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos); - if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) == - QEvent::MouseButtonPress) + const bool expandsOnPress = + (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) == QEvent::MouseButtonPress); + if (expandsOnPress) QTRY_VERIFY(!tv.isExpanded(mi)); QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos); QTRY_VERIFY(!tv.isExpanded(mi)); QCOMPARE(lastTopLevel->checkState(), Qt::Checked); + + // Test that it does not toggle the check state of a previously selected item when collapsing an + // item causes it to position the item under the mouse to be the decoration for the selected item + tv.expandAll(); + tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum()); + // It is not enough to programmatically select the item, we need to have it clicked on + QTest::mouseClick(tv.viewport(), Qt::LeftButton, {}, tv.visualRect(lastTopLevel->index()).center()); + QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos); + if (expandsOnPress) + QTRY_VERIFY(!tv.isExpanded(mi)); + QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos); + QTRY_VERIFY(!tv.isExpanded(mi)); + QCOMPARE(lastTopLevel->checkState(), Qt::Checked); } QTEST_MAIN(tst_QTreeView) |