diff options
author | Richard Moe Gustavsen <[email protected]> | 2019-09-24 15:09:34 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <[email protected]> | 2019-12-04 01:35:02 +0100 |
commit | 1841a9e41d02c9b95a7eb3c47e09f6773da56a85 (patch) | |
tree | 965a96a2b4299abf2ada3057895a5ef4abb0af2f /src/quick/items/qquickitemview_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 <[email protected]>
Diffstat (limited to 'src/quick/items/qquickitemview_p.h')
-rw-r--r-- | src/quick/items/qquickitemview_p.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index 6bc00411f0..521580d292 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -110,6 +110,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickItemView : public QQuickFlickable Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd) Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged) + Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged REVISION 15) + QML_NAMED_ELEMENT(ItemView) QML_UNCREATABLE("ItemView is an abstract base class.") QML_ADDED_IN_MINOR_VERSION(1) @@ -226,6 +228,9 @@ public: int highlightMoveDuration() const; virtual void setHighlightMoveDuration(int); + bool reuseItems() const; + void setReuseItems(bool reuse); + enum PositionMode { Beginning, Center, End, Visible, Contain, SnapPosition }; Q_ENUM(PositionMode) @@ -281,6 +286,8 @@ Q_SIGNALS: void preferredHighlightEndChanged(); void highlightMoveDurationChanged(); + Q_REVISION(15) void reuseItemsChanged(); + protected: void updatePolish() override; void componentComplete() override; @@ -296,6 +303,8 @@ protected Q_SLOTS: virtual void initItem(int index, QObject *item); void modelUpdated(const QQmlChangeSet &changeSet, bool reset); void destroyingItem(QObject *item); + void onItemPooled(int modelIndex, QObject *object); + void onItemReused(int modelIndex, QObject *object); void animStopped(); void trackedPositionChanged(); @@ -399,6 +408,9 @@ Q_SIGNALS: void prevSectionChanged(); void nextSectionChanged(); + void pooled(); + void reused(); + public: QPointer<QQuickItemView> m_view; bool m_isCurrent : 1; |