diff options
Diffstat (limited to 'src/widgets/itemviews/qtreeview.cpp')
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 0fe607bc31..6ab6576cbe 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1448,7 +1448,8 @@ void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItem *option, c void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const { Q_D(const QTreeView); - const QVector<QTreeViewItem> viewItems = d->viewItems; + // d->viewItems changes when posted layouts are executed in itemDecorationAt, so don't copy + const QVector<QTreeViewItem> &viewItems = d->viewItems; QStyleOptionViewItem option = d->viewOptionsV1(); const QStyle::State state = option.state; @@ -1947,7 +1948,7 @@ void QTreeView::mouseDoubleClickEvent(QMouseEvent *event) if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, this)) emit activated(persistent); - d->pressedIndex = QModelIndex(); + d->releaseFromDoubleClick = true; d->executePostedLayout(); // we need to make sure viewItems is updated if (d->itemsExpandable && d->expandsOnDoubleClick @@ -2664,7 +2665,10 @@ QSize QTreeView::viewportSizeHint() const \since 4.2 Expands all expandable items. - \warning: if the model contains a large number of items, + \note This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} + data. + + \warning If the model contains a large number of items, this function will take some time to execute. \sa collapseAll(), expand(), collapse(), setExpanded() @@ -2686,7 +2690,10 @@ void QTreeView::expandAll() A \a depth of -1 will expand all children, a \a depth of 0 will only expand the given \a index. - \warning: if the model contains a large number of items, + \note This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} + data. + + \warning If the model contains a large number of items, this function will take some time to execute. \sa expandAll() @@ -2751,6 +2758,9 @@ void QTreeView::collapseAll() \since 4.3 Expands all expandable items to the given \a depth. + \note This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} + data. + \sa expandAll(), collapseAll(), expand(), collapse(), setExpanded() */ void QTreeView::expandToDepth(int depth) @@ -3317,9 +3327,21 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit int count = 0; if (model->hasChildren(parent)) { - if (model->canFetchMore(parent)) + if (model->canFetchMore(parent)) { + // fetchMore first, otherwise we might not yet have any data for sizeHintForRow model->fetchMore(parent); - count = model->rowCount(parent); + // guestimate the number of items in the viewport, and fetch as many as might fit + const int itemHeight = defaultItemHeight <= 0 ? q->sizeHintForRow(0) : defaultItemHeight; + const int viewCount = itemHeight ? viewport->height() / itemHeight : 0; + int lastCount = -1; + while ((count = model->rowCount(parent)) < viewCount && + count != lastCount && model->canFetchMore(parent)) { + model->fetchMore(parent); + lastCount = count; + } + } else { + count = model->rowCount(parent); + } } bool expanding = true; @@ -3447,6 +3469,7 @@ int QTreeViewPrivate::indentationForItem(int item) const int QTreeViewPrivate::itemHeight(int item) const { + Q_ASSERT(item < viewItems.count()); if (uniformRowHeights) return defaultItemHeight; if (viewItems.isEmpty()) |