diff options
Diffstat (limited to 'src/qml/types/qqmldelegatemodel.cpp')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 23bdeb55b2..aab385ceb5 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1521,6 +1521,18 @@ void QQmlDelegateModel::_q_dataChanged(const QModelIndex &begin, const QModelInd _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, roles); } +bool QQmlDelegateModel::isDescendantOf(const QPersistentModelIndex& desc, const QList< QPersistentModelIndex >& parents) const +{ + for (int i = 0, c = parents.count(); i < c; ++i) { + for (QPersistentModelIndex parent = desc; parent.isValid(); parent = parent.parent()) { + if (parent == parents[i]) + return true; + } + } + + return false; +} + void QQmlDelegateModel::_q_layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint) { Q_D(QQmlDelegateModel); @@ -1529,8 +1541,9 @@ void QQmlDelegateModel::_q_layoutAboutToBeChanged(const QList<QPersistentModelIn if (hint == QAbstractItemModel::VerticalSortHint) { d->m_storedPersistentIndexes.clear(); - if (!parents.contains(d->m_adaptorModel.rootIndex)) + if (!parents.isEmpty() && d->m_adaptorModel.rootIndex.isValid() && !isDescendantOf(d->m_adaptorModel.rootIndex, parents)) { return; + } for (int i = 0; i < d->m_count; ++i) { const QModelIndex index = d->m_adaptorModel.aim()->index(i, 0, d->m_adaptorModel.rootIndex); @@ -1550,8 +1563,9 @@ void QQmlDelegateModel::_q_layoutChanged(const QList<QPersistentModelIndex> &par return; if (hint == QAbstractItemModel::VerticalSortHint) { - if (!parents.contains(d->m_adaptorModel.rootIndex)) + if (!parents.isEmpty() && d->m_adaptorModel.rootIndex.isValid() && !isDescendantOf(d->m_adaptorModel.rootIndex, parents)) { return; + } for (int i = 0, c = d->m_storedPersistentIndexes.count(); i < c; ++i) { const QPersistentModelIndex &index = d->m_storedPersistentIndexes.at(i); |