OpenCoverage

qquickitemview_p_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickitemview_p_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#ifndef QQUICKITEMVIEW_P_P_H-
41#define QQUICKITEMVIEW_P_P_H-
42-
43//-
44// W A R N I N G-
45// --------------
46//-
47// This file is not part of the Qt API. It exists purely as an-
48// implementation detail. This header file may change from version to-
49// version without notice, or even be removed.-
50//-
51// We mean it.-
52//-
53-
54#include <QtQuick/private/qtquickglobal_p.h>-
55-
56QT_REQUIRE_CONFIG(quick_itemview);-
57-
58#include "qquickitemview_p.h"-
59#include "qquickitemviewfxitem_p_p.h"-
60#include "qquickitemviewtransition_p.h"-
61#include "qquickflickable_p_p.h"-
62#include <QtQml/private/qqmlobjectmodel_p.h>-
63#include <QtQml/private/qqmldelegatemodel_p.h>-
64#include <QtQml/private/qqmlchangeset_p.h>-
65-
66-
67QT_BEGIN_NAMESPACE-
68-
69class Q_AUTOTEST_EXPORT FxViewItem : public QQuickItemViewFxItem-
70{-
71public:-
72 FxViewItem(QQuickItem *, QQuickItemView *, bool own, QQuickItemViewAttached *attached);-
73-
74 QQuickItemView *view;-
75 QQuickItemViewAttached *attached;-
76};-
77-
78-
79class QQuickItemViewChangeSet-
80{-
81public:-
82 QQuickItemViewChangeSet();-
83-
84 bool hasPendingChanges() const;-
85 void prepare(int currentIndex, int count);-
86 void reset();-
87-
88 void applyChanges(const QQmlChangeSet &changeSet);-
89-
90 void applyBufferedChanges(const QQuickItemViewChangeSet &other);-
91-
92 int itemCount;-
93 int newCurrentIndex;-
94 QQmlChangeSet pendingChanges;-
95 QHash<QQmlChangeSet::MoveKey, FxViewItem *> removedItems;-
96-
97 bool active : 1;-
98 bool currentChanged : 1;-
99 bool currentRemoved : 1;-
100};-
101-
102-
103class Q_AUTOTEST_EXPORT QQuickItemViewPrivate : public QQuickFlickablePrivate, public QQuickItemViewTransitionChangeListener, public QAnimationJobChangeListener-
104{-
105 Q_DECLARE_PUBLIC(QQuickItemView)-
106public:-
107 QQuickItemViewPrivate();-
108 ~QQuickItemViewPrivate();-
109-
110 static inline QQuickItemViewPrivate *get(QQuickItemView *o) { return o->d_func(); }
executed 88082 times by 11 tests: return o->d_func();
Executed by:
  • tst_examples
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickanimations
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
88082
111-
112 struct ChangeResult {-
113 QQmlNullableValue<qreal> visiblePos;-
114 bool changedFirstItem;-
115 qreal sizeChangesBeforeVisiblePos;-
116 qreal sizeChangesAfterVisiblePos;-
117 int countChangeBeforeVisible;-
118 int countChangeAfterVisibleItems;-
119-
120 ChangeResult()-
121 : visiblePos(0), changedFirstItem(false),-
122 sizeChangesBeforeVisiblePos(0), sizeChangesAfterVisiblePos(0),-
123 countChangeBeforeVisible(0), countChangeAfterVisibleItems(0) {}
executed 14770 times by 8 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmltypeloader
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
14770
124-
125 ChangeResult(const QQmlNullableValue<qreal> &p)-
126 : visiblePos(p), changedFirstItem(false),-
127 sizeChangesBeforeVisiblePos(0), sizeChangesAfterVisiblePos(0),-
128 countChangeBeforeVisible(0), countChangeAfterVisibleItems(0) {}
executed 7662 times by 4 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickvisualdatamodel
7662
129-
130 ChangeResult &operator+=(const ChangeResult &other) {-
131 if (&other == this)
&other == thisDescription
TRUEnever evaluated
FALSEevaluated 6354 times by 4 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickvisualdatamodel
0-6354
132 return *this;
never executed: return *this;
0
133 changedFirstItem &= other.changedFirstItem;-
134 sizeChangesBeforeVisiblePos += other.sizeChangesBeforeVisiblePos;-
135 sizeChangesAfterVisiblePos += other.sizeChangesAfterVisiblePos;-
136 countChangeBeforeVisible += other.countChangeBeforeVisible;-
137 countChangeAfterVisibleItems += other.countChangeAfterVisibleItems;-
138 return *this;
executed 6354 times by 4 tests: return *this;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickvisualdatamodel
6354
139 }-
140-
141 void reset() {-
142 changedFirstItem = false;-
143 sizeChangesBeforeVisiblePos = 0.0;-
144 sizeChangesAfterVisiblePos = 0.0;-
145 countChangeBeforeVisible = 0;-
146 countChangeAfterVisibleItems = 0;-
147 }
executed 8894 times by 3 tests: end of block
Executed by:
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickvisualdatamodel
8894
148 };-
149-
150 enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };-
151 enum MovementReason { Other, SetIndex, Mouse };-
152-
153 bool isValid() const;-
154 qreal position() const;-
155 qreal size() const;-
156 qreal startPosition() const;-
157 qreal endPosition() const;-
158 qreal contentStartOffset() const;-
159 int findLastVisibleIndex(int defaultValue = -1) const;-
160 FxViewItem *visibleItem(int modelIndex) const;-
161 FxViewItem *firstVisibleItem() const;-
162 int findLastIndexInView() const;-
163 int mapFromModel(int modelIndex) const;-
164-
165 virtual void init();-
166 virtual void clear();-
167 virtual void updateViewport();-
168-
169 void regenerate(bool orientationChanged=false);-
170 void layout();-
171 void animationFinished(QAbstractAnimationJob *) override;-
172 void refill();-
173 void refill(qreal from, qreal to);-
174 void mirrorChange() override;-
175-
176 FxViewItem *createItem(int modelIndex,QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested);-
177 virtual bool releaseItem(FxViewItem *item);-
178-
179 QQuickItem *createHighlightItem() const;-
180 QQuickItem *createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault = false) const;-
181-
182 void updateCurrent(int modelIndex);-
183 void updateTrackedItem();-
184 void updateUnrequestedIndexes();-
185 void updateUnrequestedPositions();-
186 void updateVisibleIndex();-
187 void positionViewAtIndex(int index, int mode);-
188-
189 qreal minExtentForAxis(const AxisData &axisData, bool forXAxis) const;-
190 qreal maxExtentForAxis(const AxisData &axisData, bool forXAxis) const;-
191 qreal calculatedMinExtent() const;-
192 qreal calculatedMaxExtent() const;-
193-
194 void applyPendingChanges();-
195 bool applyModelChanges(ChangeResult *insertionResult, ChangeResult *removalResult);-
196 bool applyRemovalChange(const QQmlChangeSet::Change &removal, ChangeResult *changeResult, int *removedCount);-
197 void removeItem(FxViewItem *item, const QQmlChangeSet::Change &removal, ChangeResult *removeResult);-
198 virtual void updateSizeChangesBeforeVisiblePos(FxViewItem *item, ChangeResult *removeResult);-
199 void repositionFirstItem(FxViewItem *prevVisibleItemsFirst, qreal prevVisibleItemsFirstPos,-
200 FxViewItem *prevFirstVisible, ChangeResult *insertionResult, ChangeResult *removalResult);-
201-
202 void createTransitioner();-
203 void prepareVisibleItemTransitions();-
204 void prepareRemoveTransitions(QHash<QQmlChangeSet::MoveKey, FxViewItem *> *removedItems);-
205 bool prepareNonVisibleItemTransition(FxViewItem *item, const QRectF &viewBounds);-
206 void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override;-
207-
208 int findMoveKeyIndex(QQmlChangeSet::MoveKey key, const QVector<QQmlChangeSet::Change> &changes) const;-
209-
210 void checkVisible() const;-
211 void showVisibleItems() const;-
212-
213 void markExtentsDirty() {-
214 if (layoutOrientation() == Qt::Vertical)
layoutOrientat...= Qt::VerticalDescription
TRUEevaluated 28216 times by 12 tests
Evaluated by:
  • tst_examples
  • tst_qqmlecmascript
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickanimations
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
FALSEevaluated 6528 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
6528-28216
215 vData.markExtentsDirty();
executed 28216 times by 12 tests: vData.markExtentsDirty();
Executed by:
  • tst_examples
  • tst_qqmlecmascript
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickanimations
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
28216
216 else-
217 hData.markExtentsDirty();
executed 6528 times by 3 tests: hData.markExtentsDirty();
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
6528
218 }-
219-
220 bool hasPendingChanges() const {-
221 return currentChanges.hasPendingChanges()
executed 27099 times by 8 tests: return currentChanges.hasPendingChanges() || bufferedChanges.hasPendingChanges() ||runDelayedRemoveTransition;
Executed by:
  • tst_examples
  • tst_qqmltypeloader
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
27099
222 || bufferedChanges.hasPendingChanges()
executed 27099 times by 8 tests: return currentChanges.hasPendingChanges() || bufferedChanges.hasPendingChanges() ||runDelayedRemoveTransition;
Executed by:
  • tst_examples
  • tst_qqmltypeloader
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
27099
223 ||runDelayedRemoveTransition;
executed 27099 times by 8 tests: return currentChanges.hasPendingChanges() || bufferedChanges.hasPendingChanges() ||runDelayedRemoveTransition;
Executed by:
  • tst_examples
  • tst_qqmltypeloader
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
27099
224 }-
225-
226 void refillOrLayout() {-
227 if (hasPendingChanges())
hasPendingChanges()Description
TRUEevaluated 31 times by 2 tests
Evaluated by:
  • tst_qquickgridview
  • tst_qquicklistview
FALSEevaluated 16757 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickvisualdatamodel
31-16757
228 layout();
executed 31 times by 2 tests: layout();
Executed by:
  • tst_qquickgridview
  • tst_qquicklistview
31
229 else-
230 refill();
executed 16757 times by 5 tests: refill();
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickvisualdatamodel
16757
231 }-
232-
233 void forceLayoutPolish() {-
234 Q_Q(QQuickItemView);-
235 forceLayout = true;-
236 q->polish();-
237 }
executed 7637 times by 11 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickanimations
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
7637
238-
239 void releaseVisibleItems() {-
240 // make a copy and clear the visibleItems first to avoid destroyed-
241 // items being accessed during the loop (QTBUG-61294)-
242 const QList<FxViewItem *> oldVisible = visibleItems;-
243 visibleItems.clear();-
244 for (FxViewItem *item : oldVisible)-
245 releaseItem(item);
executed 61007 times by 10 tests: releaseItem(item);
Executed by:
  • tst_examples
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
61007
246 }
executed 11450 times by 12 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlecmascript
  • tst_qqmllistmodel
  • tst_qqmltypeloader
  • tst_qqmlvaluetypes
  • tst_qquickanimations
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquicklistview
  • tst_qquickmousearea
  • tst_qquickspringanimation
  • tst_qquickvisualdatamodel
11450
247-
248 QPointer<QQmlInstanceModel> model;-
249 QVariant modelVariant;-
250 int itemCount;-
251 int buffer;-
252 int bufferMode;-
253 int displayMarginBeginning;-
254 int displayMarginEnd;-
255 Qt::LayoutDirection layoutDirection;-
256 QQuickItemView::VerticalLayoutDirection verticalLayoutDirection;-
257-
258 MovementReason moveReason;-
259-
260 QList<FxViewItem *> visibleItems;-
261 int visibleIndex;-
262 int currentIndex;-
263 FxViewItem *currentItem;-
264 FxViewItem *trackedItem;-
265 QHash<QQuickItem*,int> unrequestedItems;-
266 int requestedIndex;-
267 QQuickItemViewChangeSet currentChanges;-
268 QQuickItemViewChangeSet bufferedChanges;-
269 QPauseAnimationJob bufferPause;-
270-
271 QQmlComponent *highlightComponent;-
272 FxViewItem *highlight;-
273 int highlightRange; // enum value-
274 qreal highlightRangeStart;-
275 qreal highlightRangeEnd;-
276 int highlightMoveDuration;-
277-
278 QQmlComponent *headerComponent;-
279 FxViewItem *header;-
280 QQmlComponent *footerComponent;-
281 FxViewItem *footer;-
282-
283 struct MovedItem {-
284 FxViewItem *item;-
285 QQmlChangeSet::MoveKey moveKey;-
286 MovedItem(FxViewItem *i, QQmlChangeSet::MoveKey k)-
287 : item(i), moveKey(k) {}
executed 90 times by 2 tests: end of block
Executed by:
  • tst_qquickgridview
  • tst_qquicklistview
90
288 };-
289 QQuickItemViewTransitioner *transitioner;-
290 QList<FxViewItem *> releasePendingTransition;-
291-
292 mutable qreal minExtent;-
293 mutable qreal maxExtent;-
294-
295 bool ownModel : 1;-
296 bool wrap : 1;-
297 bool keyNavigationEnabled : 1;-
298 bool explicitKeyNavigationEnabled : 1;-
299 bool inLayout : 1;-
300 bool inViewportMoved : 1;-
301 bool forceLayout : 1;-
302 bool currentIndexCleared : 1;-
303 bool haveHighlightRange : 1;-
304 bool autoHighlight : 1;-
305 bool highlightRangeStartValid : 1;-
306 bool highlightRangeEndValid : 1;-
307 bool fillCacheBuffer : 1;-
308 bool inRequest : 1;-
309 bool runDelayedRemoveTransition : 1;-
310 bool delegateValidated : 1;-
311-
312protected:-
313 virtual Qt::Orientation layoutOrientation() const = 0;-
314 virtual bool isContentFlowReversed() const = 0;-
315-
316 virtual qreal positionAt(int index) const = 0;-
317 virtual qreal endPositionAt(int index) const = 0;-
318 virtual qreal originPosition() const = 0;-
319 virtual qreal lastPosition() const = 0;-
320-
321 virtual qreal headerSize() const = 0;-
322 virtual qreal footerSize() const = 0;-
323 virtual bool showHeaderForIndex(int index) const = 0;-
324 virtual bool showFooterForIndex(int index) const = 0;-
325 virtual void updateHeader() = 0;-
326 virtual void updateFooter() = 0;-
327 virtual bool hasStickyHeader() const { return false; }
executed 130 times by 1 test: return false;
Executed by:
  • tst_qquickgridview
130
328 virtual bool hasStickyFooter() const { return false; }
executed 130 times by 1 test: return false;
Executed by:
  • tst_qquickgridview
130
329-
330 virtual void createHighlight() = 0;-
331 virtual void updateHighlight() = 0;-
332 virtual void resetHighlightPosition() = 0;-
333 virtual bool movingFromHighlight() { return false; }
executed 3523 times by 4 tests: return false;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquickimage
  • tst_qquickvisualdatamodel
3523
334-
335 virtual void setPosition(qreal pos) = 0;-
336 virtual void fixupPosition() = 0;-
337-
338 virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) = 0;-
339 virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0;-
340 virtual void visibleItemsChanged() {}-
341-
342 virtual FxViewItem *newViewItem(int index, QQuickItem *item) = 0;-
343 virtual void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) = 0;-
344 virtual void repositionPackageItemAt(QQuickItem *item, int index) = 0;-
345 virtual void resetFirstItemPosition(qreal pos = 0.0) = 0;-
346 virtual void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) = 0;-
347-
348 virtual void layoutVisibleItems(int fromModelIndex = 0) = 0;-
349 virtual void changedVisibleIndex(int newIndex) = 0;-
350-
351 virtual bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult,-
352 QList<FxViewItem *> *newItems, QList<MovedItem> *movingIntoView) = 0;-
353-
354 virtual bool needsRefillForAddedOrRemovedIndex(int) const { return false; }
executed 79 times by 1 test: return false;
Executed by:
  • tst_qquicklistview
79
355 virtual void translateAndTransitionItemsAfter(int afterIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) = 0;-
356-
357 virtual void initializeViewItem(FxViewItem *) {}-
358 virtual void initializeCurrentItem() {}-
359 virtual void updateSectionCriteria() {}-
360 virtual void updateSections() {}-
361-
362 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;-
363};-
364-
365-
366QT_END_NAMESPACE-
367-
368#endif // QQUICKITEMVIEW_P_P_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0