diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2021-07-20 15:49:33 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-21 00:36:32 +0000 |
commit | 1693779f05731668d0177d9941a00ed67eba4f20 (patch) | |
tree | 0891ef74fd8076234b5dd278fe1dce17c3e7126f /tests/auto/widgets/itemviews/qtreewidget | |
parent | a48fee3aa46d29f9e06da2df75aca9bf8acadf5e (diff) |
emit layoutAboutToBeChanged timely
layoutAboutToBeChanged must be called before
persistentIndexList as the user might create persistent indexes
as a response to the signal
Fixes: QTBUG-93466
Change-Id: I73c24501f536ef9b6092c3374821497f0a8f0de4
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit 1dcfb09c5bf431bf8b065ac038bd1fc618a68f96)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/widgets/itemviews/qtreewidget')
-rw-r--r-- | tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 4cfea81572..367bba4ee0 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -152,6 +152,8 @@ private slots: void testVisualItemRect(); void reparentHiddenItem(); void persistentChildIndex(); + void createPersistentOnLayoutAboutToBeChanged(); + void createPersistentOnLayoutAboutToBeChangedAutoSort(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void clearItemData(); #endif @@ -3641,5 +3643,72 @@ void tst_QTreeWidget::clearItemData() } #endif +void tst_QTreeWidget::createPersistentOnLayoutAboutToBeChanged() // QTBUG-93466 +{ + QTreeWidget widget; + QCOMPARE(widget.model()->columnCount(), 1); + widget.model()->insertRows(0, 3); + for (int row = 0; row < 3; ++row) + widget.model()->setData(widget.model()->index(row, 0), row); + QList<QPersistentModelIndex> idxList; + QSignalSpy layoutAboutToBeChangedSpy(widget.model(), &QAbstractItemModel::layoutAboutToBeChanged); + QSignalSpy layoutChangedSpy(widget.model(), &QAbstractItemModel::layoutChanged); + connect(widget.model(), &QAbstractItemModel::layoutAboutToBeChanged, this, [&idxList, &widget](){ + idxList.clear(); + for (int row = 0; row < 3; ++row) + idxList << QPersistentModelIndex(widget.model()->index(row, 0)); + }); + connect(widget.model(), &QAbstractItemModel::layoutChanged, this, [&idxList](){ + QCOMPARE(idxList.size(), 3); + QCOMPARE(idxList.at(0).row(), 1); + QCOMPARE(idxList.at(0).column(), 0); + QCOMPARE(idxList.at(0).data().toInt(), 0); + QCOMPARE(idxList.at(1).row(), 0); + QCOMPARE(idxList.at(1).column(), 0); + QCOMPARE(idxList.at(1).data().toInt(), -1); + QCOMPARE(idxList.at(2).row(), 2); + QCOMPARE(idxList.at(2).column(), 0); + QCOMPARE(idxList.at(2).data().toInt(), 2); + }); + widget.model()->setData(widget.model()->index(1, 0), -1); + widget.model()->sort(0); + QCOMPARE(layoutAboutToBeChangedSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 1); +} + +void tst_QTreeWidget::createPersistentOnLayoutAboutToBeChangedAutoSort() // QTBUG-93466 +{ + QTreeWidget widget; + QCOMPARE(widget.model()->columnCount(), 1); + widget.model()->insertRows(0, 3); + for (int row = 0; row < 3; ++row) + widget.model()->setData(widget.model()->index(row, 0), row); + widget.sortByColumn(0, Qt::AscendingOrder); + widget.setSortingEnabled(true); + QList<QPersistentModelIndex> idxList; + QSignalSpy layoutAboutToBeChangedSpy(widget.model(), &QAbstractItemModel::layoutAboutToBeChanged); + QSignalSpy layoutChangedSpy(widget.model(), &QAbstractItemModel::layoutChanged); + connect(widget.model(), &QAbstractItemModel::layoutAboutToBeChanged, this, [&idxList, &widget](){ + idxList.clear(); + for (int row = 0; row < 3; ++row) + idxList << QPersistentModelIndex(widget.model()->index(row, 0)); + }); + connect(widget.model(), &QAbstractItemModel::layoutChanged, this, [&idxList](){ + QCOMPARE(idxList.size(), 3); + QCOMPARE(idxList.at(0).row(), 1); + QCOMPARE(idxList.at(0).column(), 0); + QCOMPARE(idxList.at(0).data().toInt(), 0); + QCOMPARE(idxList.at(1).row(), 0); + QCOMPARE(idxList.at(1).column(), 0); + QCOMPARE(idxList.at(1).data().toInt(), -1); + QCOMPARE(idxList.at(2).row(), 2); + QCOMPARE(idxList.at(2).column(), 0); + QCOMPARE(idxList.at(2).data().toInt(), 2); + }); + widget.model()->setData(widget.model()->index(1, 0), -1); + QCOMPARE(layoutAboutToBeChangedSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 1); +} + QTEST_MAIN(tst_QTreeWidget) #include "tst_qtreewidget.moc" |