summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels/qstandarditemmodel.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-04-24 17:06:49 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-06-27 10:01:07 +0000
commit74be42ca598c4f13486191c0b8c58bee3d1f1090 (patch)
tree4895fe5a2f995c3dbd112469b527ff789e0f76b4 /src/gui/itemmodels/qstandarditemmodel.cpp
parente3a1b18bc3e213c318107b84b07543d945b48514 (diff)
ItemModels: Cache last-known child index
Instead of caching the last index of a search for a child item, cache the index of the child in the child item. When the item model is not changed, the index is valid. Otherwise, the index can only change when items get inserted or removed before the child. So in that case, start searching in the vicinity of the previously known index. As an example: a selectAll() on the view will always hit the cached index, so no search is performed for any item in the model/view. Task-number: QTBUG-61368 Change-Id: I85d085299987237fae23451d9e8bbb6060464ef2 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/gui/itemmodels/qstandarditemmodel.cpp')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index f55e90c153..235bc5bd7d 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -142,6 +142,8 @@ void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item,
oldItem->d_func()->setModel(0);
delete oldItem;
children.replace(index, item);
+ if (item)
+ item->d_func()->lastKnownIndex = index;
if (model && emitChanged)
emit model->layoutChanged();
@@ -475,6 +477,8 @@ bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &item
item->d_func()->parent = q;
int index = childIndex(i + row, 0);
children.replace(index, item);
+ if (item)
+ item->d_func()->lastKnownIndex = index;
}
if (model)
model->d_func()->rowsInserted(q, row, count);
@@ -512,6 +516,8 @@ bool QStandardItemPrivate::insertRows(int row, int count, const QList<QStandardI
}
}
children.replace(index, item);
+ if (item)
+ item->d_func()->lastKnownIndex = index;
++index;
}
}
@@ -558,6 +564,8 @@ bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QSta
int c = column + (i % count);
int index = childIndex(r, c);
children.replace(index, item);
+ if (item)
+ item->d_func()->lastKnownIndex = index;
}
}
if (model)