diff options
Diffstat (limited to 'tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp')
-rw-r--r-- | tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 7329cd054a..681be2491d 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QIdentityProxyModel> #include <QLabel> @@ -52,6 +52,13 @@ public: : QAbstractTableModel(parent), row_count(rows), column_count(columns) {} + void insertRows(int rows) + { + beginInsertRows(QModelIndex(), row_count, row_count + rows - 1); + row_count += rows; + endInsertRows(); + } + int rowCount(const QModelIndex& = QModelIndex()) const override { return row_count; @@ -384,6 +391,7 @@ private slots: void resizeToContents(); void resizeToContentsSpans(); + void resizeToContentsEarly(); void tabFocus(); void bigModel(); @@ -416,6 +424,7 @@ private slots: void selectColumnsAndCells(); void selectWithHeader_data(); void selectWithHeader(); + void resetDefaultSectionSize(); #if QT_CONFIG(wheelevent) void mouseWheel_data(); @@ -429,6 +438,7 @@ private slots: void viewOptions(); void taskQTBUG_7232_AllowUserToControlSingleStep(); + void rowsInVerticalHeader(); #if QT_CONFIG(textmarkdownwriter) void markdownWriter(); @@ -600,7 +610,6 @@ void tst_QTableView::keyboardNavigation() view.setCurrentIndex(index); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); int row = rowCount - 1; @@ -3768,6 +3777,35 @@ void tst_QTableView::resizeToContentsSpans() QCOMPARE(view2.columnWidth(0), view3.columnWidth(0) - view2.columnWidth(1)); } +void tst_QTableView::resizeToContentsEarly() +{ + QStringListModel model; + QTableView view; + + // connect to the model before setting it on the view + connect(&model, &QStringListModel::modelReset, &model, [&view]{ + view.resizeColumnsToContents(); + }); + connect(&model, &QStringListModel::modelReset, &model, [&view]{ + view.resizeRowsToContents(); + }); + + // the view only connects now to the model's signals, so responds to the + // reset signal *after* the lambdas above + view.setModel(&model); + + QStringList data(200, QString("Hello World")); + model.setStringList(data); + + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum()); + + data = data.sliced(data.size() / 2); + model.setStringList(data); +} + QT_BEGIN_NAMESPACE extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp QT_END_NAMESPACE @@ -3790,7 +3828,6 @@ void tst_QTableView::tabFocus() QLineEdit *edit = new QLineEdit(&window); window.show(); - QApplicationPrivate::setActiveWindow(&window); window.setFocus(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -4901,6 +4938,22 @@ void tst_QTableView::selectWithHeader() QVERIFY(!isSelected()); } +void tst_QTableView::resetDefaultSectionSize() +{ + // Create a table and change its default section size and then reset it. + // This should be a no op so clicking on row 1 should select row 1 and not row + // 0 as previously. QTBUG-116013 + QTableWidget view(10, 10); + view.resize(300, 300); + view.verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); + view.verticalHeader()->setDefaultSectionSize(120); + view.verticalHeader()->resetDefaultSectionSize(); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QEXPECT_FAIL("", "Reverted fix for QTBUG-116013 due to QTBUG-122109", Continue); + QCOMPARE(view.verticalHeader()->logicalIndexAt(9, 45), 1); +} + // This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel #if QT_CONFIG(textmarkdownwriter) @@ -4929,5 +4982,18 @@ void tst_QTableView::markdownWriter() } #endif +void tst_QTableView::rowsInVerticalHeader() +{ + QtTestTableModel model(0, 2); + QTableView view; + view.setModel(&model); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + auto *verticalHeader = view.verticalHeader(); + QCOMPARE(verticalHeader->count(), 0); + model.insertRows(2); + QCOMPARE(verticalHeader->count(), 2); +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" |