Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickitemview_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKITEMVIEW_P_H
6#define QQUICKITEMVIEW_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick/private/qtquickglobal_p.h>
20
22
24
25#include <private/qqmldelegatemodel_p.h>
26
27#include <qpointer.h>
28#include <QtCore/QLoggingCategory>
29
31
32Q_DECLARE_LOGGING_CATEGORY(lcItemViewDelegateLifecycle)
33
34class QQmlChangeSet;
35class QQmlComponent;
36
37class QQuickItemViewPrivate;
38
39class Q_QUICK_EXPORT QQuickItemView : public QQuickFlickable
40{
41 Q_OBJECT
42
43 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
44 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
45 Q_PROPERTY(int count READ count NOTIFY countChanged)
46
47 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
48 Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
49
50 Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
51 Q_PROPERTY(bool keyNavigationEnabled READ isKeyNavigationEnabled WRITE setKeyNavigationEnabled NOTIFY keyNavigationEnabledChanged REVISION(2, 7))
52 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
53 Q_PROPERTY(int displayMarginBeginning READ displayMarginBeginning WRITE setDisplayMarginBeginning NOTIFY displayMarginBeginningChanged REVISION(2, 3))
54 Q_PROPERTY(int displayMarginEnd READ displayMarginEnd WRITE setDisplayMarginEnd NOTIFY displayMarginEndChanged REVISION(2, 3))
55
56 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
57 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
58 Q_PROPERTY(VerticalLayoutDirection verticalLayoutDirection READ verticalLayoutDirection WRITE setVerticalLayoutDirection NOTIFY verticalLayoutDirectionChanged)
59
60 Q_PROPERTY(QQmlComponent *header READ header WRITE setHeader NOTIFY headerChanged)
61 Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged)
62 Q_PROPERTY(QQmlComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
63 Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged)
64
65#if QT_CONFIG(quick_viewtransitions)
66 Q_PROPERTY(QQuickTransition *populate READ populateTransition WRITE setPopulateTransition NOTIFY populateTransitionChanged)
67 Q_PROPERTY(QQuickTransition *add READ addTransition WRITE setAddTransition NOTIFY addTransitionChanged)
68 Q_PROPERTY(QQuickTransition *addDisplaced READ addDisplacedTransition WRITE setAddDisplacedTransition NOTIFY addDisplacedTransitionChanged)
69 Q_PROPERTY(QQuickTransition *move READ moveTransition WRITE setMoveTransition NOTIFY moveTransitionChanged)
70 Q_PROPERTY(QQuickTransition *moveDisplaced READ moveDisplacedTransition WRITE setMoveDisplacedTransition NOTIFY moveDisplacedTransitionChanged)
71 Q_PROPERTY(QQuickTransition *remove READ removeTransition WRITE setRemoveTransition NOTIFY removeTransitionChanged)
72 Q_PROPERTY(QQuickTransition *removeDisplaced READ removeDisplacedTransition WRITE setRemoveDisplacedTransition NOTIFY removeDisplacedTransitionChanged)
73 Q_PROPERTY(QQuickTransition *displaced READ displacedTransition WRITE setDisplacedTransition NOTIFY displacedTransitionChanged)
74#endif
75
76 Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
77 Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
78 Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
79 Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
80 Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin)
81 Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd)
82 Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
83
84 Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged REVISION(2, 15))
85 Q_PROPERTY(QQmlDelegateModel::DelegateModelAccess delegateModelAccess READ delegateModelAccess
86 WRITE setDelegateModelAccess NOTIFY delegateModelAccessChanged REVISION(6, 10) FINAL)
87
88 QML_NAMED_ELEMENT(ItemView)
89 QML_UNCREATABLE("ItemView is an abstract base class.")
90 QML_ADDED_IN_VERSION(2, 1)
91
92public:
93 // this holds all layout enum values so they can be referred to by other enums
94 // to ensure consistent values - e.g. QML references to GridView.TopToBottom flow
95 // and GridView.TopToBottom vertical layout direction should have same value
96 enum LayoutDirection {
97 LeftToRight = Qt::LeftToRight,
98 RightToLeft = Qt::RightToLeft,
99 VerticalTopToBottom,
100 VerticalBottomToTop
101 };
102 Q_ENUM(LayoutDirection)
103
104 enum VerticalLayoutDirection {
105 TopToBottom = VerticalTopToBottom,
106 BottomToTop = VerticalBottomToTop
107 };
108 Q_ENUM(VerticalLayoutDirection)
109
110 QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = nullptr);
111 ~QQuickItemView();
112
113 QVariant model() const;
114 void setModel(const QVariant &);
115
116 QQmlComponent *delegate() const;
117 void setDelegate(QQmlComponent *);
118
119 int count() const;
120
121 int currentIndex() const;
122 void setCurrentIndex(int idx);
123
124 QQuickItem *currentItem() const;
125
126 bool isWrapEnabled() const;
127 void setWrapEnabled(bool);
128
129 bool isKeyNavigationEnabled() const;
130 void setKeyNavigationEnabled(bool);
131
132 int cacheBuffer() const;
133 void setCacheBuffer(int);
134
135 int displayMarginBeginning() const;
136 void setDisplayMarginBeginning(int);
137
138 int displayMarginEnd() const;
139 void setDisplayMarginEnd(int);
140
141 Qt::LayoutDirection layoutDirection() const;
142 void setLayoutDirection(Qt::LayoutDirection);
143 Qt::LayoutDirection effectiveLayoutDirection() const;
144
145 VerticalLayoutDirection verticalLayoutDirection() const;
146 void setVerticalLayoutDirection(VerticalLayoutDirection layoutDirection);
147
148 QQmlComponent *footer() const;
149 void setFooter(QQmlComponent *);
150 QQuickItem *footerItem() const;
151
152 QQmlComponent *header() const;
153 void setHeader(QQmlComponent *);
154 QQuickItem *headerItem() const;
155
156#if QT_CONFIG(quick_viewtransitions)
157 QQuickTransition *populateTransition() const;
158 void setPopulateTransition(QQuickTransition *transition);
159
160 QQuickTransition *addTransition() const;
161 void setAddTransition(QQuickTransition *transition);
162
163 QQuickTransition *addDisplacedTransition() const;
164 void setAddDisplacedTransition(QQuickTransition *transition);
165
166 QQuickTransition *moveTransition() const;
167 void setMoveTransition(QQuickTransition *transition);
168
169 QQuickTransition *moveDisplacedTransition() const;
170 void setMoveDisplacedTransition(QQuickTransition *transition);
171
172 QQuickTransition *removeTransition() const;
173 void setRemoveTransition(QQuickTransition *transition);
174
175 QQuickTransition *removeDisplacedTransition() const;
176 void setRemoveDisplacedTransition(QQuickTransition *transition);
177
178 QQuickTransition *displacedTransition() const;
179 void setDisplacedTransition(QQuickTransition *transition);
180#endif
181
182 QQmlComponent *highlight() const;
183 void setHighlight(QQmlComponent *);
184
185 QQuickItem *highlightItem() const;
186
187 bool highlightFollowsCurrentItem() const;
188 virtual void setHighlightFollowsCurrentItem(bool);
189
190 enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
191 Q_ENUM(HighlightRangeMode)
192 HighlightRangeMode highlightRangeMode() const;
193 void setHighlightRangeMode(HighlightRangeMode mode);
194
195 qreal preferredHighlightBegin() const;
196 void setPreferredHighlightBegin(qreal);
197 void resetPreferredHighlightBegin();
198
199 qreal preferredHighlightEnd() const;
200 void setPreferredHighlightEnd(qreal);
201 void resetPreferredHighlightEnd();
202
203 int highlightMoveDuration() const;
204 virtual void setHighlightMoveDuration(int);
205
206 bool reuseItems() const;
207 void setReuseItems(bool reuse);
208
209 enum PositionMode { Beginning, Center, End, Visible, Contain, SnapPosition };
210 Q_ENUM(PositionMode)
211
212 Q_INVOKABLE void positionViewAtIndex(int index, int mode);
213 Q_INVOKABLE int indexAt(qreal x, qreal y) const;
214 Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
215 Q_REVISION(2, 13) Q_INVOKABLE QQuickItem *itemAtIndex(int index) const;
216 Q_INVOKABLE void positionViewAtBeginning();
217 Q_INVOKABLE void positionViewAtEnd();
218 Q_REVISION(2, 1) Q_INVOKABLE void forceLayout();
219
220 void setContentX(qreal pos) override;
221 void setContentY(qreal pos) override;
222 qreal originX() const override;
223 qreal originY() const override;
224
225 QQmlDelegateModel::DelegateModelAccess delegateModelAccess() const;
226 void setDelegateModelAccess(QQmlDelegateModel::DelegateModelAccess delegateModelAccess);
227
228Q_SIGNALS:
229 void modelChanged();
230 void delegateChanged();
231 void countChanged();
232 void currentIndexChanged();
233 void currentItemChanged();
234
235 void keyNavigationWrapsChanged();
236 Q_REVISION(2, 7) void keyNavigationEnabledChanged();
237 void cacheBufferChanged();
238 void displayMarginBeginningChanged();
239 void displayMarginEndChanged();
240
241 void layoutDirectionChanged();
242 void effectiveLayoutDirectionChanged();
243 void verticalLayoutDirectionChanged();
244
245 void headerChanged();
246 void footerChanged();
247 void headerItemChanged();
248 void footerItemChanged();
249
250#if QT_CONFIG(quick_viewtransitions)
251 void populateTransitionChanged();
252 void addTransitionChanged();
253 void addDisplacedTransitionChanged();
254 void moveTransitionChanged();
255 void moveDisplacedTransitionChanged();
256 void removeTransitionChanged();
257 void removeDisplacedTransitionChanged();
258 void displacedTransitionChanged();
259#endif
260
261 void highlightChanged();
262 void highlightItemChanged();
263 void highlightFollowsCurrentItemChanged();
264 void highlightRangeModeChanged();
265 void preferredHighlightBeginChanged();
266 void preferredHighlightEndChanged();
267 void highlightMoveDurationChanged();
268
269 Q_REVISION(2, 15) void reuseItemsChanged();
270 Q_REVISION(6, 10) void delegateModelAccessChanged();
271
272protected:
273 void updatePolish() override;
274 void componentComplete() override;
275 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
276 qreal minYExtent() const override;
277 qreal maxYExtent() const override;
278 qreal minXExtent() const override;
279 qreal maxXExtent() const override;
280
281protected Q_SLOTS:
282 void destroyRemoved();
283 void createdItem(int index, QObject *item);
284 virtual void initItem(int index, QObject *item);
285 void modelUpdated(const QQmlChangeSet &changeSet, bool reset);
286 void destroyingItem(QObject *item);
287 Q_REVISION(2, 15) void onItemPooled(int modelIndex, QObject *object);
288 Q_REVISION(2, 15) void onItemReused(int modelIndex, QObject *object);
289 void animStopped();
290 void trackedPositionChanged();
291
292private:
293 Q_DECLARE_PRIVATE(QQuickItemView)
294};
295
296
297class Q_QUICK_EXPORT QQuickItemViewAttached : public QObject
298{
299 Q_OBJECT
300
301 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged FINAL)
302 Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged FINAL)
303
304 Q_PROPERTY(QString section READ section NOTIFY sectionChanged FINAL)
305 Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged FINAL)
306 Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged FINAL)
307
308public:
309 QQuickItemViewAttached(QObject *parent)
310 : QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
311 ~QQuickItemViewAttached() {}
312
313 bool isCurrentItem() const { return m_isCurrent; }
314 void setIsCurrentItem(bool c) {
315 if (m_isCurrent != c) {
316 m_isCurrent = c;
317 Q_EMIT currentItemChanged();
318 }
319 }
320
321 bool delayRemove() const { return m_delayRemove; }
322 void setDelayRemove(bool delay) {
323 if (m_delayRemove != delay) {
324 m_delayRemove = delay;
325 Q_EMIT delayRemoveChanged();
326 }
327 }
328
329 QString section() const { return m_section; }
330 void setSection(const QString &sect) {
331 if (m_section != sect) {
332 m_section = sect;
333 Q_EMIT sectionChanged();
334 }
335 }
336
337 QString prevSection() const { return m_prevSection; }
338 void setPrevSection(const QString &sect) {
339 if (m_prevSection != sect) {
340 m_prevSection = sect;
341 Q_EMIT prevSectionChanged();
342 }
343 }
344
345 QString nextSection() const { return m_nextSection; }
346 void setNextSection(const QString &sect) {
347 if (m_nextSection != sect) {
348 m_nextSection = sect;
349 Q_EMIT nextSectionChanged();
350 }
351 }
352
353 void setSections(const QString &prev, const QString &sect, const QString &next) {
354 bool prevChanged = prev != m_prevSection;
355 bool sectChanged = sect != m_section;
356 bool nextChanged = next != m_nextSection;
357 m_prevSection = prev;
358 m_section = sect;
359 m_nextSection = next;
360 if (prevChanged)
361 Q_EMIT prevSectionChanged();
362 if (sectChanged)
363 Q_EMIT sectionChanged();
364 if (nextChanged)
365 Q_EMIT nextSectionChanged();
366 }
367
368 void emitAdd() { Q_EMIT add(); }
369 void emitRemove() { Q_EMIT remove(); }
370
371Q_SIGNALS:
372 void viewChanged();
373 void currentItemChanged();
374 void delayRemoveChanged();
375
376 void add();
377 void remove();
378
379 void sectionChanged();
380 void prevSectionChanged();
381 void nextSectionChanged();
382
383 void pooled();
384 void reused();
385
386public:
387 bool m_isCurrent : 1;
388 bool m_delayRemove : 1;
389
390 // current only used by list view
391 mutable QString m_section;
392 QString m_prevSection;
393 QString m_nextSection;
394};
395
396
397QT_END_NAMESPACE
398
399#endif // QQUICKITEMVIEW_P_H
qreal footerSize() const override
bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) override
qreal snapPosAt(qreal pos) const
void fixupPosition() override
void updateViewport() override
void updateHighlight() override
bool showFooterForIndex(int index) const override
bool isContentFlowReversed() const override
bool flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QQuickTimeLineCallback::Callback fixupCallback, QEvent::Type eventType, qreal velocity) override
void repositionPackageItemAt(QQuickItem *item, int index) override
bool showHeaderForIndex(int index) const override
bool needsRefillForAddedOrRemovedIndex(int index) const override
void createHighlight(bool onDestruction=false) override
QSmoothedAnimation * highlightYAnimator
void initializeViewItem(FxViewItem *item) override
void removeItem(FxViewItem *item)
qreal positionAt(int index) const override
void updateFooter() override
qreal endPositionAt(int index) const override
void setPosition(qreal pos) override
QQuickItemViewAttached * getAttachedObject(const QObject *object) const override
void resetFirstItemPosition(qreal pos=0.0) override
bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList< FxViewItem * > *addedItems, QList< MovedItem > *movingIntoView) override
void initializeComponentItem(QQuickItem *item) const override
void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) override
qreal rowPosAt(int modelIndex) const
void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) override
FxViewItem * snapItemAt(qreal pos) const
void fixup(AxisData &data, qreal minExtent, qreal maxExtent) override
void resetHighlightPosition() override
void changedVisibleIndex(int newIndex) override
void layoutVisibleItems(int fromModelIndex=0) override
qreal contentYForPosition(qreal pos) const
qreal lastPosition() const override
FxViewItem * newViewItem(int index, QQuickItem *item) override
qreal contentXForPosition(qreal pos) const
qreal headerSize() const override
qreal originPosition() const override
void updateHeader() override
bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) override
qreal colPosAt(int modelIndex) const
void initializeCurrentItem() override
QSmoothedAnimation * highlightXAnimator
#define QML_FLICK_SNAPONETHRESHOLD
QT_REQUIRE_CONFIG(quick_gridview)
QT_REQUIRE_CONFIG(quick_itemview)