From 13d7517c0edd4c99686f2a8f7611c51d0a56a279 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 8 Nov 2019 00:48:05 +0100 Subject: Doc: Fix documentation warnings There were a lot of documentation warnings introduced by the separation of QtQml.Models and QtQml.WorkerScript modules from the QtQml documentation project into their own sub-projects. Fix the above, and also ensure that the experimental Qt.labs.qmlmodels QML types are listed in the documentation, and add them also on the QML module page for QtQml.Models. A few warnings remain, they may be indicative of issues not in the scope of this commit. Fixes: QTBUG-79812 Change-Id: Idc25c976e4c96feab4aae893519d6c9245f57a64 Reviewed-by: Paul Wicking --- src/quick/items/qquicklistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/quick/items/qquicklistview.cpp') diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 8b70ffd0d7..18a9afbad8 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -2078,7 +2078,7 @@ QQuickListView::~QQuickListView() highlight item is \c 0. \sa highlightItem, highlightFollowsCurrentItem, - {Qt Quick Examples - Views#Highlight}{ListView highlight example}, + {Qt Quick Examples - Views#Using Highlight}{ListView Highlight Example}, {Stacking Order in ListView} */ -- cgit v1.2.3 From c89f7a221b7c31a0a4e1b0eed2e91d7633f4eab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Mon, 14 Oct 2019 14:39:48 +0200 Subject: Fix a layout bug caused by a delegate item that was moved by the user The position of the first item in the list of visualItems was used to know how to layout the rest of the visual items. However, this did not work if the first item was actually moved (e.g. due to a DnD operation). We therefore store the position of the first visual item after each time we arrange it, and use that as a basis on where to start layouting from. Task-number: QTBUG-78076 Change-Id: I837f5b7d61a13d98d23287685c6fd66817360906 Reviewed-by: Richard Moe Gustavsen --- src/quick/items/qquicklistview.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/quick/items/qquicklistview.cpp') diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 8b70ffd0d7..ebae4d14ea 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -805,6 +805,7 @@ void QQuickListViewPrivate::layoutVisibleItems(int fromModelIndex) FxViewItem *firstItem = *visibleItems.constBegin(); bool fixedCurrent = currentItem && firstItem->item == currentItem->item; + firstVisibleItemPosition = firstItem->position(); qreal sum = firstItem->size(); qreal pos = firstItem->position() + firstItem->size() + spacing; firstItem->setVisible(firstItem->endPosition() >= from && firstItem->position() <= to); -- cgit v1.2.3 From 1841a9e41d02c9b95a7eb3c47e09f6773da56a85 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 24 Sep 2019 15:09:34 +0200 Subject: 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 --- src/quick/items/qquicklistview.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/quick/items/qquicklistview.cpp') diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 778f28bdd5..9206628716 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -92,7 +92,7 @@ public: FxViewItem *newViewItem(int index, QQuickItem *item) override; void initializeViewItem(FxViewItem *item) override; - bool releaseItem(FxViewItem *item) override; + bool releaseItem(FxViewItem *item, QQmlInstanceModel::ReusableFlag reusableFlag) override; void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) override; void repositionPackageItemAt(QQuickItem *item, int index) override; void resetFirstItemPosition(qreal pos = 0.0) override; @@ -139,6 +139,8 @@ public: bool flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) override; + QQuickItemViewAttached *getAttachedObject(const QObject *object) const override; + QQuickListView::Orientation orient; qreal visiblePos; qreal averageSize; @@ -634,15 +636,15 @@ void QQuickListViewPrivate::initializeViewItem(FxViewItem *item) } } -bool QQuickListViewPrivate::releaseItem(FxViewItem *item) +bool QQuickListViewPrivate::releaseItem(FxViewItem *item, QQmlInstanceModel::ReusableFlag reusableFlag) { if (!item || !model) - return QQuickItemViewPrivate::releaseItem(item); + return QQuickItemViewPrivate::releaseItem(item, reusableFlag); QPointer it = item->item; QQuickListViewAttached *att = static_cast(item->attached); - bool released = QQuickItemViewPrivate::releaseItem(item); + bool released = QQuickItemViewPrivate::releaseItem(item, reusableFlag); if (released && it && att && att->m_sectionItem) { // We hold no more references to this item int i = 0; @@ -682,7 +684,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal int newModelIdx = qBound(0, modelIndex + count, model->count()); count = newModelIdx - modelIndex; if (count) { - releaseVisibleItems(); + releaseVisibleItems(reusableFlag); modelIndex = newModelIdx; visibleIndex = modelIndex; visiblePos = itemEnd + count * (averageSize + spacing); @@ -737,7 +739,7 @@ void QQuickListViewPrivate::removeItem(FxViewItem *item) releasePendingTransition.append(item); } else { qCDebug(lcItemViewDelegateLifecycle) << "\treleasing stationary item" << item->index << (QObject *)(item->item); - releaseItem(item); + releaseItem(item, reusableFlag); } } @@ -1772,6 +1774,12 @@ void QQuickListViewPrivate::setSectionHelper(QQmlContext *context, QQuickItem *s sectionItem->setProperty("section", section); } +QQuickItemViewAttached *QQuickListViewPrivate::getAttachedObject(const QObject *object) const +{ + QObject *attachedObject = qmlAttachedPropertiesObject(object); + return static_cast(attachedObject); +} + //---------------------------------------------------------------------------- /*! @@ -3186,6 +3194,13 @@ void QQuickListView::keyPressEvent(QKeyEvent *event) void QQuickListView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickListView); + + if (d->model) { + // When the view changes size, we force the pool to + // shrink by releasing all pooled items. + d->model->drainReusableItemsPool(0); + } + if (d->isRightToLeft()) { // maintain position relative to the right edge qreal dx = newGeometry.width() - oldGeometry.width(); -- cgit v1.2.3 From 6ad3445f1e159d9beea936b66d267dcaacdc5d6c Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 3 Dec 2019 15:49:12 +0100 Subject: Don't allow dragging a ListView through a floating header or footer If the header or footer positioning is Overlay or PullBack, the list delegates appear to scroll underneath it. The header or footer can contain interactive content. If a mouse or touch press happens to "fall through" that, it should not be possible to drag the ListView contents from there. [ChangeLog][QtQuick][ListView] ListView no longer allows the user to press on an Overlay or PullBack header or footer and start scrolling, but only on the content delegates. Fixes: QTBUG-74046 Change-Id: I4d06c789286be2691d098aeebb10a57b2a335744 Reviewed-by: Mitch Curtis --- src/quick/items/qquicklistview.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/quick/items/qquicklistview.cpp') diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 9206628716..4dbb2b792c 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -3608,6 +3608,23 @@ QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj) return new QQuickListViewAttached(obj); } +bool QQuickListView::contains(const QPointF &point) const +{ + bool ret = QQuickItemView::contains(point); + // QTBUG-74046: if a mouse press "falls through" a floating header or footer, don't allow dragging the list from there + if (ret) { + if (auto header = headerItem()) { + if (headerPositioning() != QQuickListView::InlineHeader && header->contains(mapToItem(header, point))) + ret = false; + } + if (auto footer = footerItem()) { + if (footerPositioning() != QQuickListView::InlineFooter && footer->contains(mapToItem(footer, point))) + ret = false; + } + } + return ret; +} + QT_END_NAMESPACE #include "moc_qquicklistview_p.cpp" -- cgit v1.2.3 From b753d40f67e20031a307d0fe016d63e3a1463f14 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 20 Nov 2019 10:15:37 +0100 Subject: QQuickListView: document delegate item recycling Change-Id: I6777eb179643ca2d5fb14f96f5f5ac02f5f2fb04 Reviewed-by: Venugopal Shivashankar --- src/quick/items/qquicklistview.cpp | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/quick/items/qquicklistview.cpp') diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 4dbb2b792c..0f62a1a61c 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -1928,6 +1928,39 @@ QQuickItemViewAttached *QQuickListViewPrivate::getAttachedObject(const QObject * of type \l [QML] {real}, so it is possible to set fractional values like \c 0.1. + \section1 Reusing items + + Since 5.15, ListView can be configured to recycle items instead of instantiating + from the \l delegate whenever new rows are flicked into view. This approach improves + performance, depending on the complexity of the delegate. Reusing + items is off by default (for backwards compatibility reasons), but can be switched + on by setting the \l reuseItems property to \c true. + + When an item is flicked out, it moves to the \e{reuse pool}, which is an + internal cache of unused items. When this happens, the \l ListView::pooled + signal is emitted to inform the item about it. Likewise, when the item is + moved back from the pool, the \l ListView::reused signal is emitted. + + Any item properties that come from the model are updated when the + item is reused. This includes \c index and \c row, but also + any model roles. + + \note Avoid storing any state inside a delegate. If you do, reset it + manually on receiving the \l ListView::reused signal. + + If an item has timers or animations, consider pausing them on receiving + the \l ListView::pooled signal. That way you avoid using the CPU resources + for items that are not visible. Likewise, if an item has resources that + cannot be reused, they could be freed up. + + \note While an item is in the pool, it might still be alive and respond + to connected signals and bindings. + + The following example shows a delegate that animates a spinning rectangle. When + it is pooled, the animation is temporarily paused: + + \snippet qml/listview/reusabledelegate.qml 0 + \sa {QML Data Models}, GridView, PathView, {Qt Quick Examples - Views} */ QQuickListView::QQuickListView(QQuickItem *parent) @@ -2093,6 +2126,20 @@ QQuickListView::~QQuickListView() This property holds the number of items in the view. */ +/*! + \qmlproperty bool QtQuick::ListView::reuseItems + + This property enables you to reuse items that are instantiated + from the \l delegate. If set to \c false, any currently + pooled items are destroyed. + + This property is \c false by default. + + \since 5.15 + + \sa {Reusing items}, ListView::pooled, ListView::reused +*/ + /*! \qmlproperty Component QtQuick::ListView::highlight This property holds the component to use as the highlight. -- cgit v1.2.3