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/gui | |
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/gui')
-rw-r--r-- | tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp index 7fc2c473de..7758a5d5cc 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -138,6 +138,7 @@ private slots: void taskQTBUG_45114_setItemData(); void setItemPersistentIndex(); void signalsOnTakeItem(); + void createPersistentOnLayoutAboutToBeChanged(); private: QStandardItemModel *m_model = nullptr; QPersistentModelIndex persistent; @@ -1785,5 +1786,40 @@ void tst_QStandardItemModel::signalsOnTakeItem() // QTBUG-89145 QCOMPARE(m.index(1, 0).data(), QVariant()); } +void tst_QStandardItemModel::createPersistentOnLayoutAboutToBeChanged() // QTBUG-93466 +{ + QStandardItemModel model; + QAbstractItemModelTester mTester(&model, nullptr); + model.insertColumn(0); + QCOMPARE(model.columnCount(), 1); + model.insertRows(0, 3); + for (int row = 0; row < 3; ++row) + model.setData(model.index(row, 0), row); + QList<QPersistentModelIndex> idxList; + QSignalSpy layoutAboutToBeChangedSpy(&model, &QAbstractItemModel::layoutAboutToBeChanged); + QSignalSpy layoutChangedSpy(&model, &QAbstractItemModel::layoutChanged); + connect(&model, &QAbstractItemModel::layoutAboutToBeChanged, this, [&idxList, &model](){ + idxList.clear(); + for (int row = 0; row < 3; ++row) + idxList << QPersistentModelIndex(model.index(row, 0)); + }); + connect(&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); + }); + model.setData(model.index(1, 0), -1); + model.sort(0); + QCOMPARE(layoutAboutToBeChangedSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 1); +} + QTEST_MAIN(tst_QStandardItemModel) #include "tst_qstandarditemmodel.moc" |