aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitemview_p_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickitemview_p_p.h')
-rw-r--r--src/quick/items/qquickitemview_p_p.h111
1 files changed, 54 insertions, 57 deletions
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index aca334d931..c05233d82a 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKITEMVIEW_P_P_H
#define QQUICKITEMVIEW_P_P_H
@@ -57,12 +21,15 @@ QT_REQUIRE_CONFIG(quick_itemview);
#include "qquickitemview_p.h"
#include "qquickitemviewfxitem_p_p.h"
+#if QT_CONFIG(quick_viewtransitions)
#include "qquickitemviewtransition_p.h"
+#endif
#include "qquickflickable_p_p.h"
-#include <QtQml/private/qqmlobjectmodel_p.h>
-#include <QtQml/private/qqmldelegatemodel_p.h>
-#include <QtQml/private/qqmlchangeset_p.h>
+#include <QtQmlModels/private/qqmlobjectmodel_p.h>
+#include <QtQmlModels/private/qqmldelegatemodel_p.h>
+#include <QtQmlModels/private/qqmlchangeset_p.h>
+#include <QtCore/qpointer.h>
QT_BEGIN_NAMESPACE
@@ -76,7 +43,7 @@ public:
};
-class QQuickItemViewChangeSet
+class Q_AUTOTEST_EXPORT QQuickItemViewChangeSet
{
public:
QQuickItemViewChangeSet();
@@ -92,7 +59,7 @@ public:
int itemCount;
int newCurrentIndex;
QQmlChangeSet pendingChanges;
- QHash<QQmlChangeSet::MoveKey, FxViewItem *> removedItems;
+ QMultiHash<QQmlChangeSet::MoveKey, FxViewItem *> removedItems;
bool active : 1;
bool currentChanged : 1;
@@ -100,10 +67,15 @@ public:
};
-class Q_AUTOTEST_EXPORT QQuickItemViewPrivate : public QQuickFlickablePrivate, public QQuickItemViewTransitionChangeListener, public QAnimationJobChangeListener
+class Q_QUICK_AUTOTEST_EXPORT QQuickItemViewPrivate
+ : public QQuickFlickablePrivate
+#if QT_CONFIG(quick_viewtransitions)
+ , public QQuickItemViewTransitionChangeListener
+#endif
+ , public QAnimationJobChangeListener
{
- Q_DECLARE_PUBLIC(QQuickItemView)
public:
+ Q_DECLARE_PUBLIC(QQuickItemView)
QQuickItemViewPrivate();
~QQuickItemViewPrivate();
@@ -148,7 +120,6 @@ public:
};
enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
- enum MovementReason { Other, SetIndex, Mouse };
bool isValid() const;
qreal position() const;
@@ -158,12 +129,12 @@ public:
qreal contentStartOffset() const;
int findLastVisibleIndex(int defaultValue = -1) const;
FxViewItem *visibleItem(int modelIndex) const;
- FxViewItem *firstVisibleItem() const;
+ FxViewItem *firstItemInView() const;
int findLastIndexInView() const;
int mapFromModel(int modelIndex) const;
virtual void init();
- virtual void clear();
+ virtual void clear(bool onDestruction=false);
virtual void updateViewport();
void regenerate(bool orientationChanged=false);
@@ -174,10 +145,11 @@ 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;
+ virtual void initializeComponentItem(QQuickItem *) const;
void updateCurrent(int modelIndex);
void updateTrackedItem();
@@ -191,6 +163,8 @@ public:
qreal calculatedMinExtent() const;
qreal calculatedMaxExtent() const;
+ void applyDelegateChange();
+
void applyPendingChanges();
bool applyModelChanges(ChangeResult *insertionResult, ChangeResult *removalResult);
bool applyRemovalChange(const QQmlChangeSet::Change &removal, ChangeResult *changeResult, int *removedCount);
@@ -199,11 +173,13 @@ public:
void repositionFirstItem(FxViewItem *prevVisibleItemsFirst, qreal prevVisibleItemsFirstPos,
FxViewItem *prevFirstVisible, ChangeResult *insertionResult, ChangeResult *removalResult);
+#if QT_CONFIG(quick_viewtransitions)
void createTransitioner();
void prepareVisibleItemTransitions();
- void prepareRemoveTransitions(QHash<QQmlChangeSet::MoveKey, FxViewItem *> *removedItems);
+ void prepareRemoveTransitions(QMultiHash<QQmlChangeSet::MoveKey, FxViewItem *> *removedItems);
bool prepareNonVisibleItemTransition(FxViewItem *item, const QRectF &viewBounds);
void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override;
+#endif
int findMoveKeyIndex(QQmlChangeSet::MoveKey key, const QVector<QQmlChangeSet::Change> &changes) const;
@@ -220,7 +196,10 @@ public:
bool hasPendingChanges() const {
return currentChanges.hasPendingChanges()
|| bufferedChanges.hasPendingChanges()
- ||runDelayedRemoveTransition;
+#if QT_CONFIG(quick_viewtransitions)
+ ||runDelayedRemoveTransition
+#endif
+ ;
}
void refillOrLayout() {
@@ -236,15 +215,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;
@@ -255,9 +236,13 @@ public:
Qt::LayoutDirection layoutDirection;
QQuickItemView::VerticalLayoutDirection verticalLayoutDirection;
- MovementReason moveReason;
-
QList<FxViewItem *> visibleItems;
+ qreal firstVisibleItemPosition = 0;
+ void storeFirstVisibleItemPosition() {
+ if (!visibleItems.isEmpty()) {
+ firstVisibleItemPosition = visibleItems.constFirst()->position();
+ }
+ }
int visibleIndex;
int currentIndex;
FxViewItem *currentItem;
@@ -269,7 +254,7 @@ public:
QPauseAnimationJob bufferPause;
QQmlComponent *highlightComponent;
- FxViewItem *highlight;
+ std::unique_ptr<FxViewItem> highlight;
int highlightRange; // enum value
qreal highlightRangeStart;
qreal highlightRangeEnd;
@@ -280,14 +265,21 @@ 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;
MovedItem(FxViewItem *i, QQmlChangeSet::MoveKey k)
: item(i), moveKey(k) {}
};
+#if QT_CONFIG(quick_viewtransitions)
QQuickItemViewTransitioner *transitioner;
QVector<FxViewItem *> releasePendingTransition;
+#endif
mutable qreal minExtent;
mutable qreal maxExtent;
@@ -306,8 +298,11 @@ public:
bool highlightRangeEndValid : 1;
bool fillCacheBuffer : 1;
bool inRequest : 1;
+#if QT_CONFIG(quick_viewtransitions)
bool runDelayedRemoveTransition : 1;
+#endif
bool delegateValidated : 1;
+ bool isClearing : 1;
protected:
virtual Qt::Orientation layoutOrientation() const = 0;
@@ -327,7 +322,7 @@ protected:
virtual bool hasStickyHeader() const { return false; }
virtual bool hasStickyFooter() const { return false; }
- virtual void createHighlight() = 0;
+ virtual void createHighlight(bool onDestruction = false) = 0;
virtual void updateHighlight() = 0;
virtual void resetHighlightPosition() = 0;
virtual bool movingFromHighlight() { return false; }
@@ -352,7 +347,9 @@ protected:
QList<FxViewItem *> *newItems, QList<MovedItem> *movingIntoView) = 0;
virtual bool needsRefillForAddedOrRemovedIndex(int) const { return false; }
+#if QT_CONFIG(quick_viewtransitions)
virtual void translateAndTransitionItemsAfter(int afterIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) = 0;
+#endif
virtual void initializeViewItem(FxViewItem *) {}
virtual void initializeCurrentItem() {}