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>
This commit is contained in:
parent
d84f449bcd
commit
ae3ad0ad21
@ -853,12 +853,18 @@ static QItemSelection mergeIndexes(const QVector<QPersistentModelIndex> &indexes
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < indexes.count()) {
|
while (i < indexes.count()) {
|
||||||
const QPersistentModelIndex &tl = indexes.at(i);
|
const QPersistentModelIndex &tl = indexes.at(i);
|
||||||
|
if (!tl.isValid()) {
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QPersistentModelIndex br = tl;
|
QPersistentModelIndex br = tl;
|
||||||
QModelIndex brParent = br.parent();
|
QModelIndex brParent = br.parent();
|
||||||
int brRow = br.row();
|
int brRow = br.row();
|
||||||
int brColumn = br.column();
|
int brColumn = br.column();
|
||||||
while (++i < indexes.count()) {
|
while (++i < indexes.count()) {
|
||||||
const QPersistentModelIndex &next = indexes.at(i);
|
const QPersistentModelIndex &next = indexes.at(i);
|
||||||
|
if (!next.isValid())
|
||||||
|
continue;
|
||||||
const QModelIndex nextParent = next.parent();
|
const QModelIndex nextParent = next.parent();
|
||||||
const int nextRow = next.row();
|
const int nextRow = next.row();
|
||||||
const int nextColumn = next.column();
|
const int nextColumn = next.column();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user