diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2021-07-20 15:49:33 +0100 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2021-07-20 21:27:27 +0100 |
commit | 1dcfb09c5bf431bf8b065ac038bd1fc618a68f96 (patch) | |
tree | e43a3bb55f4531cf3d2ca6706f3c41522f15cb8c /src/corelib/itemmodels | |
parent | e1b010ff47ae81067802d9240ea990d6d9187484 (diff) |
emit layoutAboutToBeChanged timely
layoutAboutToBeChanged must be called before
persistentIndexList as the user might create persistent indexes
as a response to the signal
Fixes: QTBUG-93466
Pick-to: 6.2 5.15
Change-Id: I73c24501f536ef9b6092c3374821497f0a8f0de4
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qtransposeproxymodel.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/corelib/itemmodels/qtransposeproxymodel.cpp b/src/corelib/itemmodels/qtransposeproxymodel.cpp index 899f93c2a5..558ec45b73 100644 --- a/src/corelib/itemmodels/qtransposeproxymodel.cpp +++ b/src/corelib/itemmodels/qtransposeproxymodel.cpp @@ -64,6 +64,7 @@ QModelIndex QTransposeProxyModelPrivate::uncheckedMapFromSource(const QModelInde void QTransposeProxyModelPrivate::onLayoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint) { Q_Q(QTransposeProxyModel); + Q_ASSERT(layoutChangeProxyIndexes.size() == layoutChangePersistentIndexes.size()); QModelIndexList toList; toList.reserve(layoutChangePersistentIndexes.size()); for (const QPersistentModelIndex &persistIdx : qAsConst(layoutChangePersistentIndexes)) @@ -83,9 +84,26 @@ void QTransposeProxyModelPrivate::onLayoutChanged(const QList<QPersistentModelIn emit q->layoutChanged(proxyParents, proxyHint); } -void QTransposeProxyModelPrivate::onLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint) +void QTransposeProxyModelPrivate::onLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents, QAbstractItemModel::LayoutChangeHint hint) { Q_Q(QTransposeProxyModel); + QList<QPersistentModelIndex> proxyParents; + proxyParents.reserve(sourceParents.size()); + for (const QPersistentModelIndex &parent : sourceParents) { + if (!parent.isValid()) { + proxyParents << QPersistentModelIndex(); + continue; + } + const QModelIndex mappedParent = q->mapFromSource(parent); + Q_ASSERT(mappedParent.isValid()); + proxyParents << mappedParent; + } + QAbstractItemModel::LayoutChangeHint proxyHint = QAbstractItemModel::NoLayoutChangeHint; + if (hint == QAbstractItemModel::VerticalSortHint) + proxyHint = QAbstractItemModel::HorizontalSortHint; + else if (hint == QAbstractItemModel::HorizontalSortHint) + proxyHint = QAbstractItemModel::VerticalSortHint; + emit q->layoutAboutToBeChanged(proxyParents, proxyHint); const QModelIndexList proxyPersistentIndexes = q->persistentIndexList(); layoutChangeProxyIndexes.clear(); layoutChangePersistentIndexes.clear(); @@ -98,16 +116,6 @@ void QTransposeProxyModelPrivate::onLayoutAboutToBeChanged(const QList<QPersiste Q_ASSERT(srcPersistentIndex.isValid()); layoutChangePersistentIndexes << srcPersistentIndex; } - QList<QPersistentModelIndex> proxyParents; - proxyParents.reserve(parents.size()); - for (auto& srcParent : parents) - proxyParents << q->mapFromSource(srcParent); - QAbstractItemModel::LayoutChangeHint proxyHint = QAbstractItemModel::NoLayoutChangeHint; - if (hint == QAbstractItemModel::VerticalSortHint) - proxyHint = QAbstractItemModel::HorizontalSortHint; - else if (hint == QAbstractItemModel::HorizontalSortHint) - proxyHint = QAbstractItemModel::VerticalSortHint; - emit q->layoutAboutToBeChanged(proxyParents, proxyHint); } void QTransposeProxyModelPrivate::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, |