diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2021-07-20 15:49:33 +0100 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2021-07-20 21:27:27 +0100 |
commit | 1dcfb09c5bf431bf8b065ac038bd1fc618a68f96 (patch) | |
tree | e43a3bb55f4531cf3d2ca6706f3c41522f15cb8c /tests/auto/widgets/itemviews/qlistwidget | |
parent | e1b010ff47ae81067802d9240ea990d6d9187484 (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
Pick-to: 6.2 5.15
Change-Id: I73c24501f536ef9b6092c3374821497f0a8f0de4
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto/widgets/itemviews/qlistwidget')
-rw-r--r-- | tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index 48b0cb8d6b..b121766265 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -118,6 +118,8 @@ private slots: void QTBUG14363_completerWithAnyKeyPressedEditTriggers(); void mimeData(); void QTBUG50891_ensureSelectionModelSignalConnectionsAreSet(); + void createPersistentOnLayoutAboutToBeChanged(); + void createPersistentOnLayoutAboutToBeChangedAutoSort(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void clearItemData(); #endif @@ -1844,6 +1846,72 @@ void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet() } +void tst_QListWidget::createPersistentOnLayoutAboutToBeChanged() // QTBUG-93466 +{ + QListWidget 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_QListWidget::createPersistentOnLayoutAboutToBeChangedAutoSort() // QTBUG-93466 +{ + QListWidget 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.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); +} + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void tst_QListWidget::clearItemData() { |