summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2018-06-25 18:54:16 +0200
committerDavid Faure <david.faure@kdab.com>2018-07-28 12:26:41 +0000
commitce4407c32749e9d22314c09aa205691dbad2a335 (patch)
treef65ff82d8579985d61b065af3a50e06a9ef4b9a1 /tests
parentcd542b0094d485e5127794f32e77ea81d9092b05 (diff)
QSFPM unittest: check dataChanged and layoutChanged signals
I'm not sure why QSFPM purposefully emits dataChanged for a source dataChanged that triggers a layoutChanged (i.e. due to sorting, multiple rows are moving around). (This predates the git import in Qt 4.5.) Surely whoever is listening will not gain much from the "small" dataChanged after the "big" layoutChanged... anyhow, this documents the current behavior, at least. It also proves that the bug I saw long ago (changing a filtered-out value used to emit dataChanged(invalid, invalid), IIRC) is no longer present. Change-Id: I8975c549db88226b2b3393de9f8dca4f4109df15 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp48
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 a7ab1e20d9..947c4e8112 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -1900,6 +1900,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")
@@ -1912,6 +1914,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
;
@@ -1925,6 +1929,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
;
@@ -1938,9 +1944,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
@@ -1951,6 +1974,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data()
<< "x" // newValue
<< IntPairList() // removeIntervals
<< IntPairList() // insertIntervals
+ << -1 // no dataChanged signal
+ << false // layoutChanged
<< (QStringList() << "a" << "c") // proxyItems
;
@@ -1964,6 +1989,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
;
@@ -1977,6 +2004,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data()
<< "x" // newValue
<< (IntPairList() << IntPair(1, 1)) // removeIntervals
<< IntPairList() // insertIntervals
+ << -1 // no dataChanged signal
+ << false // layoutChanged
<< (QStringList() << "a") // proxyItems
;
@@ -1990,6 +2019,8 @@ void tst_QSortFilterProxyModel::changeSourceData_data()
<< "x" // newValue
<< IntPairList() // removeIntervals
<< IntPairList() // insertIntervals
+ << 0 // expectedDataChangedRow
+ << false // layoutChanged
<< (QStringList() << "x" << "b" << "c") // proxyItems
;
}
@@ -2005,6 +2036,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;
@@ -2033,9 +2066,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());
@@ -2065,6 +2102,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: