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/qlistview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/widgets/itemviews/qlistview.cpp') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 141937da75..721b9aa0d3 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1083,7 +1083,7 @@ void QListView::paintEvent(QPaintEvent *e) previousRow = row; } - d->delegateForIndex(*it)->paint(&painter, option, *it); + itemDelegateForIndex(*it)->paint(&painter, option, *it); } #if QT_CONFIG(draganddrop) @@ -1883,14 +1883,15 @@ QModelIndex QListViewPrivate::closestIndex(const QRect &target, QSize QListViewPrivate::itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const { + Q_Q(const QListView); if (!uniformItemSizes) { - const QAbstractItemDelegate *delegate = delegateForIndex(index); + const QAbstractItemDelegate *delegate = q->itemDelegateForIndex(index); return delegate ? delegate->sizeHint(option, index) : QSize(); } if (!cachedItemSize.isValid()) { // the last item is probaly the largest, so we use its size int row = model->rowCount(root) - 1; QModelIndex sample = model->index(row, column, root); - const QAbstractItemDelegate *delegate = delegateForIndex(sample); + const QAbstractItemDelegate *delegate = q->itemDelegateForIndex(sample); cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize(); } return cachedItemSize; -- cgit v1.2.3