From c1007112c867d979ffd969d74c6aab10d4bc9474 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 24 Nov 2011 21:21:28 +0100 Subject: Be specific about what part of the model is being re-layouted. Change-Id: I6b6fe98929543447f945a335c33960823c0d1a4a Reviewed-by: Olivier Goffart --- .../tst_qsortfilterproxymodel.cpp | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests/auto/widgets/itemviews') diff --git a/tests/auto/widgets/itemviews/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/widgets/itemviews/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 8e628411fc..46194ce3f7 100644 --- a/tests/auto/widgets/itemviews/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/widgets/itemviews/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -150,6 +150,8 @@ private slots: void mapSelectionFromSource(); void filteredColumns(); + void testParentLayoutChanged(); + protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); void checkHierarchy(const QStringList &data, const QAbstractItemModel *model); @@ -3210,5 +3212,72 @@ void tst_QSortFilterProxyModel::taskQTBUG_17812_resetInvalidate() QCOMPARE(ok, works); } +Q_DECLARE_METATYPE(QList) + +void tst_QSortFilterProxyModel::testParentLayoutChanged() +{ + QStandardItemModel model; + QStandardItem *parentItem = model.invisibleRootItem(); + for (int i = 0; i < 4; ++i) { + { + QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); + parentItem->appendRow(item); + } + { + QStandardItem *item = new QStandardItem(QString("item 1%0").arg(i)); + parentItem->appendRow(item); + parentItem = item; + } + } + + QSortFilterProxyModel proxy; + proxy.sort(0, Qt::AscendingOrder); + proxy.setDynamicSortFilter(true); + + proxy.setSourceModel(&model); + + qRegisterMetaType >(); + + QSignalSpy dataChangedSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + + // Verify that the no-arg signal is still emitted. + QSignalSpy layoutAboutToBeChangedSpy(&proxy, SIGNAL(layoutAboutToBeChanged())); + QSignalSpy layoutChangedSpy(&proxy, SIGNAL(layoutChanged())); + + QSignalSpy parentsAboutToBeChangedSpy(&proxy, SIGNAL(layoutAboutToBeChanged(QList))); + QSignalSpy parentsChangedSpy(&proxy, SIGNAL(layoutChanged(QList))); + + QStandardItem *item = model.invisibleRootItem()->child(1)->child(1); + + // Ensure mapped: + proxy.mapFromSource(model.indexFromItem(item)); + + item->setData("Changed"); + + QCOMPARE(dataChangedSpy.size(), 1); + QCOMPARE(layoutAboutToBeChangedSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 1); + QCOMPARE(parentsAboutToBeChangedSpy.size(), 1); + QCOMPARE(parentsChangedSpy.size(), 1); + + QVariantList beforeSignal = parentsAboutToBeChangedSpy.first(); + QVariantList afterSignal = parentsChangedSpy.first(); + + QCOMPARE(beforeSignal.size(), 1); + QCOMPARE(afterSignal.size(), 1); + + QList beforeParents = beforeSignal.first().value >(); + QList afterParents = afterSignal.first().value >(); + + QCOMPARE(beforeParents.size(), 1); + QCOMPARE(afterParents.size(), 1); + + QVERIFY(beforeParents.first().isValid()); + QVERIFY(beforeParents.first() == afterParents.first()); + + QVERIFY(beforeParents.first() == proxy.mapFromSource(model.indexFromItem(model.invisibleRootItem()->child(1)))); + +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" -- cgit v1.2.3