72 :
public QQuickFlickablePrivate
73#if QT_CONFIG(quick_viewtransitions)
74 ,
public QQuickItemViewTransitionChangeListener
76 ,
public QAnimationJobChangeListener
79 Q_DECLARE_PUBLIC(QQuickItemView)
80 QQuickItemViewPrivate();
81 ~QQuickItemViewPrivate();
83 static inline QQuickItemViewPrivate *get(QQuickItemView *o) {
return o->d_func(); }
86 QQmlNullableValue<qreal> visiblePos;
87 bool changedFirstItem;
88 qreal sizeChangesBeforeVisiblePos;
89 qreal sizeChangesAfterVisiblePos;
90 int countChangeBeforeVisible;
91 int countChangeAfterVisibleItems;
94 : visiblePos(0), changedFirstItem(
false),
95 sizeChangesBeforeVisiblePos(0), sizeChangesAfterVisiblePos(0),
96 countChangeBeforeVisible(0), countChangeAfterVisibleItems(0) {}
98 ChangeResult(
const QQmlNullableValue<qreal> &p)
99 : visiblePos(p), changedFirstItem(
false),
100 sizeChangesBeforeVisiblePos(0), sizeChangesAfterVisiblePos(0),
101 countChangeBeforeVisible(0), countChangeAfterVisibleItems(0) {}
103 ChangeResult &operator+=(
const ChangeResult &other) {
106 changedFirstItem &= other.changedFirstItem;
107 sizeChangesBeforeVisiblePos += other.sizeChangesBeforeVisiblePos;
108 sizeChangesAfterVisiblePos += other.sizeChangesAfterVisiblePos;
109 countChangeBeforeVisible += other.countChangeBeforeVisible;
110 countChangeAfterVisibleItems += other.countChangeAfterVisibleItems;
115 changedFirstItem =
false;
116 sizeChangesBeforeVisiblePos = 0.0;
117 sizeChangesAfterVisiblePos = 0.0;
118 countChangeBeforeVisible = 0;
119 countChangeAfterVisibleItems = 0;
123 enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
125 bool isValid()
const;
126 qreal position()
const;
128 qreal startPosition()
const;
129 qreal endPosition()
const;
130 qreal contentStartOffset()
const;
131 int findLastVisibleIndex(
int defaultValue = -1)
const;
132 FxViewItem *visibleItem(
int modelIndex)
const;
133 FxViewItem *firstItemInView()
const;
134 int findLastIndexInView()
const;
135 int mapFromModel(
int modelIndex)
const;
138 virtual void clear(
bool onDestruction=
false);
139 virtual void updateViewport();
141 void regenerate(
bool orientationChanged=
false);
143 void animationFinished(QAbstractAnimationJob *) override;
145 void refill(qreal from, qreal to);
146 void mirrorChange() override;
148 FxViewItem *createItem(
int modelIndex,QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested);
149 bool releaseCurrentItem(QQmlInstanceModel::ReusableFlag reusableFlag)
151 auto oldCurrentItem = std::exchange(currentItem,
nullptr);
152 return releaseItem(oldCurrentItem, reusableFlag);
154 virtual bool releaseItem(FxViewItem *item, QQmlInstanceModel::ReusableFlag reusableFlag);
155 void itemDestroyed(QQuickItem *item) override;
157 QQuickItem *createHighlightItem();
158 QQuickItem *createComponentItem(QQmlComponent *component, qreal zValue,
bool createDefault =
false)
const;
159 virtual void initializeComponentItem(QQuickItem *)
const;
161 void updateCurrent(
int modelIndex);
162 void updateTrackedItem();
163 void updateUnrequestedIndexes();
164 void updateUnrequestedPositions();
165 void updateVisibleIndex();
166 void positionViewAtIndex(
int index,
int mode);
168 qreal minExtentForAxis(
const AxisData &axisData,
bool forXAxis)
const;
169 qreal maxExtentForAxis(
const AxisData &axisData,
bool forXAxis)
const;
170 qreal calculatedMinExtent()
const;
171 qreal calculatedMaxExtent()
const;
173 void connectModel(QQuickItemView *q, QQmlDelegateModelPointer *model);
174 void disconnectModel(QQuickItemView *q, QQmlDelegateModelPointer *model);
176 void applyDelegateChange();
177 void applyDelegateModelAccessChange()
179 QQmlDelegateModel::applyDelegateModelAccessChangeOnView(q_func(),
this);
182 void applyPendingChanges();
183 bool applyModelChanges(ChangeResult *insertionResult, ChangeResult *removalResult);
184 bool applyRemovalChange(
const QQmlChangeSet::Change &removal, ChangeResult *changeResult,
int *removedCount);
185 void removeItem(FxViewItem *item,
const QQmlChangeSet::Change &removal, ChangeResult *removeResult);
186 virtual void updateSizeChangesBeforeVisiblePos(FxViewItem *item, ChangeResult *removeResult);
187 void repositionFirstItem(FxViewItem *prevVisibleItemsFirst, qreal prevVisibleItemsFirstPos,
188 FxViewItem *prevFirstVisible, ChangeResult *insertionResult, ChangeResult *removalResult);
190#if QT_CONFIG(quick_viewtransitions)
191 void createTransitioner();
192 void prepareVisibleItemTransitions();
193 void prepareRemoveTransitions(QMultiHash<QQmlChangeSet::MoveKey, FxViewItem *> *removedItems);
194 bool prepareNonVisibleItemTransition(FxViewItem *item,
const QRectF &viewBounds);
195 void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override;
198 int findMoveKeyIndex(QQmlChangeSet::MoveKey key,
const QVector<QQmlChangeSet::Change> &changes)
const;
200 void checkVisible()
const;
201 void showVisibleItems()
const;
203 void markExtentsDirty() {
204 if (layoutOrientation() == Qt::Vertical)
205 vData.markExtentsDirty();
207 hData.markExtentsDirty();
210 bool hasPendingChanges()
const {
211 return currentChanges.hasPendingChanges()
212 || bufferedChanges.hasPendingChanges()
213#if QT_CONFIG(quick_viewtransitions)
214 ||runDelayedRemoveTransition
219 void refillOrLayout() {
220 if (hasPendingChanges())
226 void forceLayoutPolish() {
232 void releaseVisibleItems(QQmlInstanceModel::ReusableFlag reusableFlag) {
235 const QList<FxViewItem *> oldVisible = visibleItems;
236 visibleItems.clear();
237 for (FxViewItem *item : oldVisible)
238 releaseItem(item, reusableFlag);
241 void emitCountChanged();
243 virtual QQuickItemViewAttached *getAttachedObject(
const QObject *)
const {
return nullptr; }
245 QPointer<QQmlInstanceModel> model;
249 int displayMarginBeginning;
250 int displayMarginEnd;
251 Qt::LayoutDirection layoutDirection;
252 QQuickItemView::VerticalLayoutDirection verticalLayoutDirection;
254 QList<FxViewItem *> visibleItems;
255 qreal firstVisibleItemPosition = 0;
256 void storeFirstVisibleItemPosition() {
257 if (!visibleItems.isEmpty()) {
258 firstVisibleItemPosition = visibleItems.constFirst()->position();
263 FxViewItem *currentItem;
264 FxViewItem *trackedItem;
265 QHash<QQuickItem*,
int> unrequestedItems;
267 QQuickItemViewChangeSet currentChanges;
268 QQuickItemViewChangeSet bufferedChanges;
269 QPauseAnimationJob bufferPause;
271 QQmlComponent *highlightComponent;
272 std::unique_ptr<FxViewItem> highlight;
274 qreal highlightRangeStart;
275 qreal highlightRangeEnd;
276 int highlightMoveDuration;
278 QQmlComponent *headerComponent;
280 QQmlComponent *footerComponent;
286 QQmlInstanceModel::ReusableFlag reusableFlag = QQmlInstanceModel::NotReusable;
290 QQmlChangeSet::MoveKey moveKey;
291 MovedItem(FxViewItem *i, QQmlChangeSet::MoveKey k)
292 : item(i), moveKey(k) {}
294#if QT_CONFIG(quick_viewtransitions)
295 QQuickItemViewTransitioner *transitioner;
296 QVector<FxViewItem *> releasePendingTransition;
299 mutable qreal minExtent;
300 mutable qreal maxExtent;
304 bool keyNavigationEnabled : 1;
305 bool explicitKeyNavigationEnabled : 1;
307 bool inViewportMoved : 1;
308 bool forceLayout : 1;
309 bool currentIndexCleared : 1;
310 bool haveHighlightRange : 1;
311 bool autoHighlight : 1;
312 bool highlightRangeStartValid : 1;
313 bool highlightRangeEndValid : 1;
314 bool fillCacheBuffer : 1;
316#if QT_CONFIG(quick_viewtransitions)
317 bool runDelayedRemoveTransition : 1;
319 bool delegateValidated : 1;
321 bool explicitDelegate: 1;
322 bool explicitDelegateModelAccess: 1;
325 virtual Qt::Orientation layoutOrientation()
const = 0;
326 virtual bool isContentFlowReversed()
const = 0;
328 virtual qreal positionAt(
int index)
const = 0;
329 virtual qreal endPositionAt(
int index)
const = 0;
330 virtual qreal originPosition()
const = 0;
331 virtual qreal lastPosition()
const = 0;
333 virtual qreal headerSize()
const = 0;
334 virtual qreal footerSize()
const = 0;
335 virtual bool showHeaderForIndex(
int index)
const = 0;
336 virtual bool showFooterForIndex(
int index)
const = 0;
337 virtual void updateHeader() = 0;
338 virtual void updateFooter() = 0;
339 virtual bool hasStickyHeader()
const {
return false; }
340 virtual bool hasStickyFooter()
const {
return false; }
342 virtual void createHighlight(
bool onDestruction =
false) = 0;
343 virtual void updateHighlight() = 0;
344 virtual void resetHighlightPosition() = 0;
345 virtual bool movingFromHighlight() {
return false; }
347 virtual void setPosition(qreal pos) = 0;
348 virtual void fixupPosition() = 0;
350 virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo,
bool doBuffer) = 0;
351 virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0;
352 virtual void visibleItemsChanged() {}
354 virtual FxViewItem *newViewItem(
int index, QQuickItem *item) = 0;
355 virtual void repositionItemAt(FxViewItem *item,
int index, qreal sizeBuffer) = 0;
356 virtual void repositionPackageItemAt(QQuickItem *item,
int index) = 0;
357 virtual void resetFirstItemPosition(qreal pos = 0.0) = 0;
358 virtual void adjustFirstItem(qreal forwards, qreal backwards,
int changeBeforeVisible) = 0;
360 virtual void layoutVisibleItems(
int fromModelIndex = 0) = 0;
361 virtual void changedVisibleIndex(
int newIndex) = 0;
363 virtual bool applyInsertionChange(
const QQmlChangeSet::Change &insert, ChangeResult *changeResult,
364 QList<FxViewItem *> *newItems, QList<MovedItem> *movingIntoView) = 0;
366 virtual bool needsRefillForAddedOrRemovedIndex(
int)
const {
return false; }
367#if QT_CONFIG(quick_viewtransitions)
368 virtual void translateAndTransitionItemsAfter(
int afterIndex,
const ChangeResult &insertionResult,
const ChangeResult &removalResult) = 0;
371 virtual void initializeViewItem(FxViewItem *) {}
372 virtual void initializeCurrentItem() {}
373 virtual void updateSectionCriteria() {}
374 virtual void updateSections() {}
376 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change,
const QRectF &) override;