From 3f8c4ae047428d21303cc5e12880838236138616 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 9 Sep 2020 16:28:27 +0200 Subject: QAbstractItemView: add virtual itemDelegateForIndex and obsolete itemDelegate(index), which the new function replaces. This allows itemviews to override the item delegate per index. The existing APIs to set delegates for rows and columns doesn't work for tree views, or other views where the delegate should depend on the parent index as well. Adjust all itemview code that accessed the QAIVPrivate's relevant data structures directly to go through the virtual function. [ChangeLog][QtWidgets][QAbstractItemView] The itemDelegate(QModelIndex) member function has been made obsolete, and has been replaced by a new virtual itemDelegateForIndex(QModelIndex) member function that can be overridden to give subclasses control over which item delegate should be used for an index. Change-Id: Ib03529c38797386d3a1d4cf3c5646e911d95daf5 Reviewed-by: Samuel Gaist Reviewed-by: Lars Knoll Reviewed-by: Christian Ehrlicher --- src/widgets/itemviews/qtreeview.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/widgets/itemviews/qtreeview.cpp') diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 56df15f237..dedc27501f 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1621,6 +1621,7 @@ void QTreeViewPrivate::calcLogicalIndices( */ int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const { + Q_Q(const QTreeView); QWidget *editor = editorForIndex(index).widget.data(); if (editor && persistent.contains(editor)) { hint = qMax(hint, editor->sizeHint().width()); @@ -1628,7 +1629,7 @@ int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, cons int max = editor->maximumSize().width(); hint = qBound(min, hint, max); } - int xhint = delegateForIndex(index)->sizeHint(option, index).width(); + int xhint = q->itemDelegateForIndex(index)->sizeHint(option, index).width(); hint = qMax(hint, xhint + (isTreePosition(index.column()) ? indentationForItem(i) : 0)); return hint; } @@ -1802,7 +1803,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, opt.state = oldState; } - d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex); + itemDelegateForIndex(modelIndex)->paint(painter, opt, modelIndex); } if (currentRowHasFocus) { @@ -3015,7 +3016,7 @@ int QTreeView::indexRowSizeHint(const QModelIndex &index) const int max = editor->maximumSize().height(); height = qBound(min, height, max); } - int hint = d->delegateForIndex(idx)->sizeHint(option, idx).height(); + int hint = itemDelegateForIndex(idx)->sizeHint(option, idx).height(); height = qMax(height, hint); } } @@ -3274,7 +3275,7 @@ QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(const QRect &rect) cons option.rect = q->visualRect(index); if (option.rect.isValid()) { - if (QAbstractItemDelegate *delegate = delegateForIndex(index)) + if (QAbstractItemDelegate *delegate = q->itemDelegateForIndex(index)) delegate->updateEditorGeometry(editor, option, index); const QPoint pos = editor->pos(); -- cgit v1.2.3