From 0d0fb04d505d105fb4b2fc71d68f729ce670b12e Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Thu, 20 Feb 2014 19:16:01 +0100 Subject: [PATCH] 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 --- src/widgets/itemviews/qtreeview.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index dd430435f32..781dd345bd8 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -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();