QHeaderView: add test for rows/columns moved

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.6 6.5
Change-Id: I354f8836d3de58a8bf51da7a8c0859a673ec9339
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-10-02 21:17:00 +02:00
parent a890df0283
commit cb4e7f4176

View File

@ -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)