QTreeView: speedup expanding items via keyPressEvent/asterisk
Expanding items with asterisk is done with expand(QModelIndex) which in the end calls layout() which is very slow and useless until all items are expanded. Therefore delay the relayouting until all items are expanded. [ChangeLog][QtWidgets][QTreeView] Speedup expanding items when pressing asterisk Task-number: QTBUG-39486 Change-Id: Ieb798fc22e9fa0dcac4bb92de7e3ed3ebb9d1c38 Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
5712c62d1c
commit
0e2dae902b
|
|
@ -1991,19 +1991,21 @@ void QTreeView::keyPressEvent(QKeyEvent *event)
|
|||
if (d->isIndexValid(current) && d->model && d->itemsExpandable) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Asterisk: {
|
||||
// do layouting only once after expanding is done
|
||||
d->doDelayedItemsLayout();
|
||||
QStack<QModelIndex> parents;
|
||||
parents.push(current);
|
||||
while (!parents.isEmpty()) {
|
||||
QModelIndex parent = parents.pop();
|
||||
for (int row = 0; row < d->model->rowCount(parent); ++row) {
|
||||
QModelIndex child = d->model->index(row, 0, parent);
|
||||
if (!d->isIndexValid(child))
|
||||
break;
|
||||
parents.push(child);
|
||||
expand(child);
|
||||
}
|
||||
while (!parents.isEmpty()) {
|
||||
QModelIndex parent = parents.pop();
|
||||
for (int row = 0; row < d->model->rowCount(parent); ++row) {
|
||||
QModelIndex child = d->model->index(row, 0, parent);
|
||||
if (!d->isIndexValid(child))
|
||||
break;
|
||||
parents.push(child);
|
||||
expand(child);
|
||||
}
|
||||
expand(current);
|
||||
}
|
||||
expand(current);
|
||||
break; }
|
||||
case Qt::Key_Plus:
|
||||
expand(current);
|
||||
|
|
|
|||
Loading…
Reference in New Issue