diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-10-17 09:20:10 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-19 00:44:54 +0200 |
commit | ae3ad0ad211e6b9d745193fc049ad6ee07d731f0 (patch) | |
tree | d433aac5c968cce9407cbe733d085a75e0aa8d5a /src/corelib/itemmodels | |
parent | d84f449bcde56fd2df12f82dd2ba2e1f0a4ae7c7 (diff) |
Handle the case where persistent indexes have gone invalid.
Don't add invalid ranges to the result. They will be removed
whenever d->ranges is processed for public consumption
anyway. For example, QItemSelectionModel::selection() calls
merge() with another selection. The merge() method removes
invalid ranges already. But the invalid ranges don't need
to be there in the first place, so this patch removes them.
A longer-term goal is to maintain d->ranges as an always-sorted list.
This method can be called with a vector containing invalid
QPersistentModelIndexes when those persistent indexes are made invalid
in between layoutAboutToBeChanged and layoutChanged. It's a normal
thing to happen and a case that should be handled deliberately.
Change-Id: I741ed9208d8a75644975c9e8d61f0d6d78e20576
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 74bc0e6a9d..4b9391d285 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -853,12 +853,18 @@ static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes int i = 0; while (i < indexes.count()) { const QPersistentModelIndex &tl = indexes.at(i); + if (!tl.isValid()) { + ++i; + continue; + } QPersistentModelIndex br = tl; QModelIndex brParent = br.parent(); int brRow = br.row(); int brColumn = br.column(); while (++i < indexes.count()) { const QPersistentModelIndex &next = indexes.at(i); + if (!next.isValid()) + continue; const QModelIndex nextParent = next.parent(); const int nextRow = next.row(); const int nextColumn = next.column(); |