Make QTreeView::expand/collapse check for ineffectual invocations

Added checks if item is already expanded/collapsed to
QTreeView::expand/collapse since the following computations
can be quite expensive. (This is useful when saving/restoring a
lot of item expansion state e.g. after a model reset.)

Task-number: QTBUG-35939
Change-Id: I82c4489f9fe0b8ac61994652a60312e34c46f628
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Adam Reichold 2014-02-20 19:16:01 +01:00 committed by The Qt Project
parent e5870b61c6
commit 0d0fb04d50

View File

@ -754,6 +754,8 @@ void QTreeView::expand(const QModelIndex &index)
return;
if (index.flags() & Qt::ItemNeverHasChildren)
return;
if (d->isIndexExpanded(index))
return;
if (d->delayedPendingLayout) {
//A complete relayout is going to be performed, just store the expanded index, no need to layout.
if (d->storeExpanded(index))
@ -785,6 +787,8 @@ void QTreeView::collapse(const QModelIndex &index)
Q_D(QTreeView);
if (!d->isIndexValid(index))
return;
if (!d->isIndexExpanded(index))
return;
//if the current item is now invisible, the autoscroll will expand the tree to see it, so disable the autoscroll
d->delayedAutoScroll.stop();