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

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtdeclarative/src/quick/items/qquickitemview_p.h