From ce4407c32749e9d22314c09aa205691dbad2a335 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 25 Jun 2018 18:54:16 +0200 Subject: QSFPM unittest: check dataChanged and layoutChanged signals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Thorbjørn Lund Martsum --- .../tst_qsortfilterproxymodel.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests') 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("newValue"); QTest::addColumn("removeIntervals"); QTest::addColumn("insertIntervals"); + QTest::addColumn("expectedDataChangedRow"); // -1 if no dataChanged signal expected + QTest::addColumn("expectedLayoutChanged"); QTest::addColumn("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(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(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(); + 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: -- cgit v1.2.3