diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-09-24 15:09:34 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-12-04 01:35:02 +0100 |
commit | 1841a9e41d02c9b95a7eb3c47e09f6773da56a85 (patch) | |
tree | 965a96a2b4299abf2ada3057895a5ef4abb0af2f /src/quick/items/qquickitemview_p_p.h | |
parent | 8c72e634b3b0eacbfdee883bfc34994d3c19ed77 (diff) |
QQuickListView: implement support for reusing items
This patch will implement delegate item recycling in
ListView. The API will be the same as used in TableView, except
that it will be off by default since the behavior of a delegate
that is reused is not compatible with legacy applications
which were not written with this in mind.
Most importantly:
- Component.onCompleted will only be called on a delegate the
first time it's created, and never when it's reused.
- Any user-declared properties in the delegate (that is, not
model roles, index, etc) will not be cleared or updated when an
item is reused. The application must do this manually upon
receiving the pooled or reused signal in the item.
[ChangeLog][ListView] ListView now has support for reusing delegate
items. This can be switched on by setting the reuseItems property of
ListView to true.
Task-number: QTBUG-80507
Change-Id: I68cc8300b050e4a1f89feebb1d31a2fd9189c793
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickitemview_p_p.h')
-rw-r--r-- | src/quick/items/qquickitemview_p_p.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index b31f53b2c0..2942f9ddaf 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -174,7 +174,7 @@ public: void mirrorChange() override; FxViewItem *createItem(int modelIndex,QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested); - virtual bool releaseItem(FxViewItem *item); + virtual bool releaseItem(FxViewItem *item, QQmlInstanceModel::ReusableFlag reusableFlag); QQuickItem *createHighlightItem() const; QQuickItem *createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault = false) const; @@ -238,15 +238,17 @@ public: q->polish(); } - void releaseVisibleItems() { + void releaseVisibleItems(QQmlInstanceModel::ReusableFlag reusableFlag) { // make a copy and clear the visibleItems first to avoid destroyed // items being accessed during the loop (QTBUG-61294) const QList<FxViewItem *> oldVisible = visibleItems; visibleItems.clear(); for (FxViewItem *item : oldVisible) - releaseItem(item); + releaseItem(item, reusableFlag); } + virtual QQuickItemViewAttached *getAttachedObject(const QObject *) const { return nullptr; } + QPointer<QQmlInstanceModel> model; QVariant modelVariant; int itemCount; @@ -288,6 +290,11 @@ public: QQmlComponent *footerComponent; FxViewItem *footer; + // Reusing delegate items cannot be on by default for backwards compatibility. + // Reusing an item will e.g mean that Component.onCompleted will only be called for an + // item when it's created and not when it's reused, which will break legacy applications. + QQmlInstanceModel::ReusableFlag reusableFlag = QQmlInstanceModel::NotReusable; + struct MovedItem { FxViewItem *item; QQmlChangeSet::MoveKey moveKey; |