diff options
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index a9138a6505..b3431bcc7a 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -1904,6 +1904,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() QTest::addColumn<QString>("newValue"); QTest::addColumn<IntPairList>("removeIntervals"); QTest::addColumn<IntPairList>("insertIntervals"); + QTest::addColumn<int>("expectedDataChangedRow"); // -1 if no dataChanged signal expected + QTest::addColumn<bool>("expectedLayoutChanged"); QTest::addColumn<QStringList>("proxyItems"); QTest::newRow("move_to_end_ascending") @@ -1916,6 +1918,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "z" // newValue << IntPairList() // removeIntervals << IntPairList() // insertIntervals + << 2 // dataChanged(row 2) is emitted, see comment "Make sure we also emit dataChanged for the rows" in the source code (unclear why, though) + << true // layoutChanged << (QStringList() << "b" << "c" << "z") // proxyItems ; @@ -1929,6 +1933,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "a" // newValue << IntPairList() // removeIntervals << IntPairList() // insertIntervals + << 2 // dataChanged(row 2) is emitted, see comment "Make sure we also emit dataChanged for the rows" in the source code (unclear why, though) + << true // layoutChanged << (QStringList() << "z" << "b" << "a") // proxyItems ; @@ -1942,9 +1948,26 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "a" // newValue << IntPairList() // removeIntervals << IntPairList() // insertIntervals + << -1 // no dataChanged signal + << false // layoutChanged << (QStringList() << "b" << "a") // proxyItems ; + QTest::newRow("no_effect_on_filtering") + << (QStringList() << "a" << "b") // sourceItems + << static_cast<int>(Qt::AscendingOrder) // sortOrder + << "" // filter + << (QStringList() << "a" << "b") // expectedInitialProxyItems + << true // dynamic + << 1 // row + << "z" // newValue + << IntPairList() // removeIntervals + << IntPairList() // insertIntervals + << 1 // expectedDataChangedRow + << false // layoutChanged + << (QStringList() << "a" << "z") // proxyItems + ; + QTest::newRow("filtered_out_value_stays_out") << (QStringList() << "a" << "b" << "c" << "d") // sourceItems << static_cast<int>(Qt::AscendingOrder) // sortOrder @@ -1955,6 +1978,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "x" // newValue << IntPairList() // removeIntervals << IntPairList() // insertIntervals + << -1 // no dataChanged signal + << false // layoutChanged << (QStringList() << "a" << "c") // proxyItems ; @@ -1968,6 +1993,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "x" // newValue << IntPairList() // removeIntervals << (IntPairList() << IntPair(2, 2)) // insertIntervals + << -1 // no dataChanged signal + << false // layoutChanged << (QStringList() << "a" << "c" << "x") // proxyItems ; @@ -1981,6 +2008,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "x" // newValue << (IntPairList() << IntPair(1, 1)) // removeIntervals << IntPairList() // insertIntervals + << -1 // no dataChanged signal + << false // layoutChanged << (QStringList() << "a") // proxyItems ; @@ -1994,6 +2023,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data() << "x" // newValue << IntPairList() // removeIntervals << IntPairList() // insertIntervals + << 0 // expectedDataChangedRow + << false // layoutChanged << (QStringList() << "x" << "b" << "c") // proxyItems ; } @@ -2009,6 +2040,8 @@ void tst_QSortFilterProxyModel::changeSourceData() QFETCH(QString, newValue); QFETCH(IntPairList, removeIntervals); QFETCH(IntPairList, insertIntervals); + QFETCH(int, expectedDataChangedRow); + QFETCH(bool, expectedLayoutChanged); QFETCH(QStringList, proxyItems); QStandardItemModel model; @@ -2037,9 +2070,13 @@ void tst_QSortFilterProxyModel::changeSourceData() QSignalSpy removeSpy(&proxy, &QSortFilterProxyModel::rowsRemoved); QSignalSpy insertSpy(&proxy, &QSortFilterProxyModel::rowsInserted); + QSignalSpy dataChangedSpy(&proxy, &QSortFilterProxyModel::dataChanged); + QSignalSpy layoutChangedSpy(&proxy, &QSortFilterProxyModel::layoutChanged); QVERIFY(removeSpy.isValid()); QVERIFY(insertSpy.isValid()); + QVERIFY(dataChangedSpy.isValid()); + QVERIFY(layoutChangedSpy.isValid()); { QModelIndex index = model.index(row, 0, QModelIndex()); @@ -2069,6 +2106,17 @@ void tst_QSortFilterProxyModel::changeSourceData() QModelIndex index = proxy.index(i, 0, QModelIndex()); QCOMPARE(proxy.data(index, Qt::DisplayRole).toString(), proxyItems.at(i)); } + + if (expectedDataChangedRow == -1) { + QCOMPARE(dataChangedSpy.count(), 0); + } else { + QCOMPARE(dataChangedSpy.count(), 1); + const QModelIndex idx = dataChangedSpy.at(0).at(0).value<QModelIndex>(); + QCOMPARE(idx.row(), expectedDataChangedRow); + QCOMPARE(idx.column(), 0); + } + + QCOMPARE(layoutChangedSpy.count(), expectedLayoutChanged ? 1 : 0); } // Checks that the model is a table, and that each and every row is like this: |