From ad27a2e5792b523b2cac46b62569030531af41eb Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 2 Oct 2023 21:17:00 +0200 Subject: [PATCH] QHeaderView: add test for rows/columns moved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a testcase to make sure the signals for moveing rows are properly connected from the model to the corresponding QHeaderView slots. Task-number: QTBUG-117698 Pick-to: 6.5 Change-Id: I354f8836d3de58a8bf51da7a8c0859a673ec9339 Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit cb4e7f4176e6135d4af0604a6e5c32682b38d33d) Reviewed-by: Qt Cherry-pick Bot --- .../itemviews/qheaderview/tst_qheaderview.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 35526997709..7835a40904e 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -227,6 +227,7 @@ private slots: void statusTips(); void testRemovingColumnsViaLayoutChanged(); void testModelMovingColumns(); + void testModelMovingRows(); protected: void setupTestData(bool use_reset_model = false); @@ -307,6 +308,12 @@ public: endRemoveRows(); } + void moveRow(int from, int to) + { + beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + endMoveRows(); + } + void removeOneColumn(int col) { beginRemoveColumns(QModelIndex(), col, col); @@ -3644,10 +3651,33 @@ void tst_QHeaderView::testModelMovingColumns() hv.setModel(&model); hv.resizeSections(QHeaderView::ResizeToContents); hv.show(); + hv.hideSection(3); + QVERIFY(!hv.isSectionHidden(1)); + QVERIFY(hv.isSectionHidden(3)); QPersistentModelIndex index3 = model.index(0, 3); model.moveColumn(3, 1); QCOMPARE(index3.column(), 1); + QVERIFY(hv.isSectionHidden(1)); + QVERIFY(!hv.isSectionHidden(3)); +} + +void tst_QHeaderView::testModelMovingRows() +{ + QtTestModel model(10, 10); + QHeaderView hv(Qt::Vertical); + hv.setModel(&model); + hv.resizeSections(QHeaderView::ResizeToContents); + hv.show(); + hv.hideSection(3); + QVERIFY(!hv.isSectionHidden(1)); + QVERIFY(hv.isSectionHidden(3)); + + QPersistentModelIndex index3 = model.index(3, 0); + model.moveRow(3, 1); + QCOMPARE(index3.row(), 1); + QVERIFY(hv.isSectionHidden(1)); + QVERIFY(!hv.isSectionHidden(3)); } QTEST_MAIN(tst_QHeaderView)