summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-09 17:59:51 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-09 17:59:51 +0200
commit22e96c4d342de3bfe4fc27f4cd7233edcfe737cc (patch)
tree6bdd02cdd8603cf16383fb339a2cfdbce82491da /tests/auto/corelib/itemmodels
parentbd79c4e28c307ba87aca02155b845774c7ffec1f (diff)
parentfa95eb055401f5264cbc6aca761cb9b5feb4affc (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 8e2d583961..04a7129f01 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -143,6 +143,7 @@ private slots:
void noMapAfterSourceDelete();
void forwardDropApi();
void canDropMimeData();
+ void filterHint();
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
@@ -3802,6 +3803,12 @@ void tst_QSortFilterProxyModel::moveSourceRows()
QCOMPARE(filterBeforeParents.size(), 1);
QCOMPARE(filterAfterParents.size(), 1);
+ QCOMPARE(
+ filterBeforeParentLayoutSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::NoLayoutChangeHint);
+ QCOMPARE(filterAfterParentLayoutSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::NoLayoutChangeHint);
+
QCOMPARE(filterBothBeforeParentLayoutSpy.size(), 0);
QCOMPARE(filterBothAfterParentLayoutSpy.size(), 0);
}
@@ -4123,5 +4130,50 @@ void tst_QSortFilterProxyModel::resortingDoesNotBreakTreeModels()
QCOMPARE(proxy.rowCount(pi1), 1);
}
+void tst_QSortFilterProxyModel::filterHint()
+{
+ // test that a filtering model does not emit layoutChanged with a hint
+ QStringListModel model(QStringList() << "one"
+ << "two"
+ << "three"
+ << "four"
+ << "five"
+ << "six");
+ QSortFilterProxyModel proxy1;
+ proxy1.setSourceModel(&model);
+ proxy1.setSortRole(Qt::DisplayRole);
+ proxy1.setDynamicSortFilter(true);
+ proxy1.sort(0);
+
+ QSortFilterProxyModel proxy2;
+ proxy2.setSourceModel(&proxy1);
+ proxy2.setFilterRole(Qt::DisplayRole);
+ proxy2.setFilterRegExp("^[^ ]*$");
+ proxy2.setDynamicSortFilter(true);
+
+ QSignalSpy proxy1BeforeSpy(&proxy1, &QSortFilterProxyModel::layoutAboutToBeChanged);
+ QSignalSpy proxy1AfterSpy(&proxy1, &QSortFilterProxyModel::layoutChanged);
+ QSignalSpy proxy2BeforeSpy(&proxy2, &QSortFilterProxyModel::layoutAboutToBeChanged);
+ QSignalSpy proxy2AfterSpy(&proxy2, &QSortFilterProxyModel::layoutChanged);
+
+ model.setData(model.index(2), QStringLiteral("modified three"), Qt::DisplayRole);
+
+ // The first proxy was re-sorted as one item as changed.
+ QCOMPARE(proxy1BeforeSpy.size(), 1);
+ QCOMPARE(proxy1BeforeSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::VerticalSortHint);
+ QCOMPARE(proxy1AfterSpy.size(), 1);
+ QCOMPARE(proxy1AfterSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::VerticalSortHint);
+
+ // But the second proxy must not have the VerticalSortHint since an item was filtered
+ QCOMPARE(proxy2BeforeSpy.size(), 1);
+ QCOMPARE(proxy2BeforeSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::NoLayoutChangeHint);
+ QCOMPARE(proxy2AfterSpy.size(), 1);
+ QCOMPARE(proxy2AfterSpy.first().at(1).value<QAbstractItemModel::LayoutChangeHint>(),
+ QAbstractItemModel::NoLayoutChangeHint);
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"