From kde-commits Thu Aug 22 15:08:00 2013 From: Andras Mantia Date: Thu, 22 Aug 2013 15:08:00 +0000 To: kde-commits Subject: [kdelibs] kdeui/itemviews: 1) Make the delegate work always on the model's index, do not go back to Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=137718409117977 Git commit 7e60cb9c4887888f8676a1a7a10f3d911f369ae3 by Andras Mantia. Committed on 22/08/2013 at 14:54. Pushed by amantia into branch 'master'. 1) Make the delegate work always on the model's index, do not go back to th= e source index, if the model is a proxy (that idea fails anyway with a prox= y chain) 2) If the option.rect is empty, don't create or update widgets 3) If the option.rect is not in the view's rectangle, do not create the wid= gets. This makes sure that only visible widgets are created. M +12 -12 kdeui/itemviews/kwidgetitemdelegatepool.cpp M +1 -1 kdeui/itemviews/kwidgetitemdelegatepool_p.h http://commits.kde.org/kdelibs/7e60cb9c4887888f8676a1a7a10f3d911f369ae3 diff --git a/kdeui/itemviews/kwidgetitemdelegatepool.cpp b/kdeui/itemviews/= kwidgetitemdelegatepool.cpp index 2ca52a0..8121c9c 100644 --- a/kdeui/itemviews/kwidgetitemdelegatepool.cpp +++ b/kdeui/itemviews/kwidgetitemdelegatepool.cpp @@ -86,7 +86,9 @@ KWidgetItemDelegatePool::~KWidgetItemDelegatePool() = QList KWidgetItemDelegatePool::findWidgets(const QPersistentMode= lIndex &idx, const QStyleOptionVie= wItem &option, - UpdateWidgetsEnum upd= ateWidgets) const + UpdateWidgetsEnum upd= ateWidgets, + bool includeNotVisible + ) const { QList result; = @@ -94,13 +96,13 @@ QList KWidgetItemDelegatePool::findWidgets(co= nst QPersistentModelIndex return result; } = - QModelIndex index; - if (const QAbstractProxyModel *proxyModel =3D qobject_cast(idx.model())) { - index =3D proxyModel->mapToSource(idx); - } else { - index =3D idx; + if (!includeNotVisible && option.rect.isEmpty()) { + return result; } = + QModelIndex index =3D idx; + + if (!index.isValid()) { return result; } @@ -108,6 +110,9 @@ QList KWidgetItemDelegatePool::findWidgets(co= nst QPersistentModelIndex if (d->usedWidgets.contains(index)) { result =3D d->usedWidgets[index]; } else { + if (!d->delegate->itemView()->rect().contains(option.rect)) + return result; + // ### KDE5 This sets a property on the delegate because we can't = add an argument to createItemWidgets d->delegate->setProperty("goya:creatingWidgetForIndex", QVariant::= fromValue(index)); result =3D d->delegate->createItemWidgets(); @@ -142,12 +147,7 @@ QList KWidgetItemDelegatePool::invalidIndexe= sWidgets() const QList result; foreach (QWidget *widget, d->widgetInIndex.keys()) { const QAbstractProxyModel *proxyModel =3D qobject_cast(d->delegate->d->model); - QModelIndex index; - if (proxyModel) { - index =3D proxyModel->mapFromSource(d->widgetInIndex[widget]); - } else { - index =3D d->widgetInIndex[widget]; - } + QModelIndex index =3D d->widgetInIndex[widget]; if (!index.isValid()) { result << widget; } diff --git a/kdeui/itemviews/kwidgetitemdelegatepool_p.h b/kdeui/itemviews/= kwidgetitemdelegatepool_p.h index 46bd38b..f632d40 100644 --- a/kdeui/itemviews/kwidgetitemdelegatepool_p.h +++ b/kdeui/itemviews/kwidgetitemdelegatepool_p.h @@ -64,7 +64,7 @@ public: * @internal */ QList findWidgets(const QPersistentModelIndex &index, const = QStyleOptionViewItem &option, - UpdateWidgetsEnum updateWidgets =3D Update= Widgets) const; + UpdateWidgetsEnum updateWidgets =3D Update= Widgets, bool includeNotVisible =3D false) const; = /** * @internal