diff options
author | Nils Jeisecke <jeisecke@saltation.de> | 2013-10-07 11:55:12 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-26 09:19:23 +0100 |
commit | 1061c7e5cfae88a336f1327cc20b2d8a0a3c6015 (patch) | |
tree | 058e8a07c1da7671ac8fcd9c91b91b386d106a2e /src/quick/items/qquicklistview.cpp | |
parent | 7d25db8ff452926e58b7a66608666b35c194fc69 (diff) |
Make GridView/ListView attached "view" property available to all delegate types
This is useful for accessing the view (e.g. "width", "cellWidth", ... properties)
from within section (ListView only), header, footer and highlight delegate components.
A typical usecase are components that are used in multiple views and therefore
cannot use the views's id for access.
The only attached property valid for those non-item delegates is "view". This
has been added to the documentation.
Change-Id: I33d976da778be23ed531a3b193ceee95ed9800d2
Task-number: QTBUG-32836
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src/quick/items/qquicklistview.cpp')
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 2dd61e386f..3ac28f438b 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -247,16 +247,14 @@ void QQuickViewSection::setLabelPositioning(int l) class FxListItemSG : public FxViewItem { public: - FxListItemSG(QQuickItem *i, QQuickListView *v, bool own) : FxViewItem(i, v, own), view(v) { - attached = static_cast<QQuickListViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(item)); + FxListItemSG(QQuickItem *i, QQuickListView *v, bool own) : FxViewItem(i, v, own, static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(i))), view(v) + { } inline QQuickItem *section() const { return attached ? static_cast<QQuickListViewAttached*>(attached)->m_sectionItem : 0; } void setSection(QQuickItem *s) { - if (!attached) - attached = static_cast<QQuickListViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(item)); static_cast<QQuickListViewAttached*>(attached)->m_sectionItem = s; } @@ -972,6 +970,9 @@ QQuickItem * QQuickListViewPrivate::getSectionItem(const QString §ion) QQml_setParent_noEvent(sectionItem, contentItem); sectionItem->setParentItem(contentItem); } + // sections are not controlled by FxListItemSG, so apply attached properties here + QQuickItemViewAttached *attached = static_cast<QQuickItemViewAttached*>(qmlAttachedPropertiesObject<QQuickListView>(sectionItem)); + attached->setView(q); } else { delete context; } @@ -1787,7 +1788,8 @@ QQuickListView::~QQuickListView() \qmlattachedproperty ListView QtQuick::ListView::view This attached property holds the view that manages this delegate instance. - It is attached to each instance of the delegate. + It is attached to each instance of the delegate and also to the header, the footer, + the section and the highlight delegates. */ /*! @@ -2855,6 +2857,9 @@ void QQuickListView::geometryChanged(const QRectF &newGeometry, const QRectF &ol void QQuickListView::initItem(int index, QObject *object) { QQuickItemView::initItem(index, object); + + // setting the view from the FxViewItem wrapper is too late if the delegate + // needs access to the view in Component.onCompleted QQuickItem *item = qmlobject_cast<QQuickItem*>(object); if (item) { QQuickListViewAttached *attached = static_cast<QQuickListViewAttached *>( |