From 49c892328223dfa2502b462d8e5e8e181f4f6cd5 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 25 Jul 2016 13:24:59 +0200 Subject: QSortFilterProxyModel: Don't forward the hint from source's layoutChanged signal We can't forward a VerticalSortHint or HorizontalSortHint hint, because we might be filtering extra items. The documentation of QAbstractItemModel::LayoutChangeHint states: Note that VerticalSortHint and HorizontalSortHint carry the meaning that items are being moved within the same parent, not moved to a different parent in the model, and not filtered out or in. And some of the views rely on this assumption (QQmlDelegateModel for example) What happens in the test is the following: - 'model' emit the dataChanged signal when its data is changed. - 'proxi1' QSortFilterProxyModelPrivate::_q_sourceDataChanged does not forward the dataChanged signal imediatly, it will instead first re-sort the model and call layoutAboutToBeChanged / layouChanged with the VerticalSortHint - 'proxy2' would forward the layoutAboutToBeChanged with the hint, but in QSortFilterProxyModelPrivate::_q_sourceLayoutChanged, it will redo the mapping which will cause the changed data to be filtered. So proxy2 can't forward the VerticalSortHint as it removed rows in the process. Change-Id: I20b6983e9d18bf7509fe6144c74f37d24e4a18c2 Reviewed-by: Tobias Koenig Reviewed-by: David Faure --- src/corelib/itemmodels/qsortfilterproxymodel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 0771fd0e30..f264ad015d 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -1322,6 +1322,7 @@ void QSortFilterProxyModelPrivate::_q_sourceReset() void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList &sourceParents, QAbstractItemModel::LayoutChangeHint hint) { Q_Q(QSortFilterProxyModel); + Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns saved_persistent_indexes.clear(); QList parents; @@ -1340,7 +1341,7 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QListlayoutAboutToBeChanged(parents, hint); + emit q->layoutAboutToBeChanged(parents); if (persistent.indexes.isEmpty()) return; @@ -1350,6 +1351,7 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList &sourceParents, QAbstractItemModel::LayoutChangeHint hint) { Q_Q(QSortFilterProxyModel); + Q_UNUSED(hint); // We can't forward Hint because we might filter additional rows or columns // Optimize: We only actually have to clear the mapping related to the contents of // sourceParents, not everything. @@ -1379,7 +1381,7 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QListlayoutChanged(parents, hint); + emit q->layoutChanged(parents); } void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted( -- cgit v1.2.3 From ed38f516bf1a9185ed331c2e5a38648e64a3982a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 2 Aug 2016 20:29:55 +0300 Subject: QStringListModel: begin/endResetModel() are no signals ... so don't use emit on them. Just confuses readers. Change-Id: I24365fc533b5b35f8942d6014dbc68387aa23e22 Reviewed-by: Friedemann Kleint --- src/corelib/itemmodels/qstringlistmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index b0919c5d78..c6a1fac9c8 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -301,9 +301,9 @@ QStringList QStringListModel::stringList() const */ void QStringListModel::setStringList(const QStringList &strings) { - emit beginResetModel(); + beginResetModel(); lst = strings; - emit endResetModel(); + endResetModel(); } /*! -- cgit v1.2.3