Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgitemview_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QSGITEMVIEW_P_P_H
43 #define QSGITEMVIEW_P_P_H
44
45 #include "qsgitemview_p.h"
46 #include "qsgflickable_p_p.h"
47 #include "qsgvisualdatamodel_p.h"
48 #include <private/qdeclarativechangeset_p.h>
49
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 QT_MODULE(Declarative)
56
57 class FxViewItem
58 {
59 public:
60     FxViewItem(QSGItem *, bool own);
61     ~FxViewItem();
62
63     // these are positions and sizes along the current direction of scrolling/flicking
64     virtual qreal position() const = 0;
65     virtual qreal endPosition() const = 0;
66     virtual qreal size() const = 0;
67     virtual qreal sectionSize() const = 0;
68
69     virtual bool contains(qreal x, qreal y) const = 0;
70
71     QSGItem *item;
72     bool ownItem;
73     int index;
74     QSGItemViewAttached *attached;
75 };
76
77 class QSGItemViewChangeSet
78 {
79 public:
80     QSGItemViewChangeSet();
81
82     bool hasPendingChanges() const;
83     void prepare(int currentIndex, int count);
84     void reset();
85
86     void applyChanges(const QDeclarativeChangeSet &changeSet);
87
88     int itemCount;
89     int newCurrentIndex;
90     QDeclarativeChangeSet pendingChanges;
91     QHash<QDeclarativeChangeSet::MoveKey, FxViewItem *> removedItems;
92
93     bool active : 1;
94     bool currentChanged : 1;
95     bool currentRemoved : 1;
96 };
97
98 class QSGItemViewPrivate : public QSGFlickablePrivate
99 {
100     Q_DECLARE_PUBLIC(QSGItemView)
101 public:
102     QSGItemViewPrivate();
103
104     struct InsertionsResult {
105         QList<FxViewItem *> addedItems;
106         QList<FxViewItem *> movedBackwards;
107         qreal sizeAddedBeforeVisible;
108
109         InsertionsResult() : sizeAddedBeforeVisible(0) {}
110     };
111
112     enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
113     enum MovementReason { Other, SetIndex, Mouse };
114
115     bool isValid() const;
116     qreal position() const;
117     qreal size() const;
118     qreal startPosition() const;
119     qreal endPosition() const;
120     qreal contentStartPosition() const;
121     int findLastVisibleIndex(int defaultValue = -1) const;
122     FxViewItem *visibleItem(int modelIndex) const;
123     FxViewItem *firstVisibleItem() const;
124     int mapFromModel(int modelIndex) const;
125
126     virtual void init();
127     virtual void clear();
128     virtual void updateViewport();
129
130     void regenerate();
131     void layout();
132     void refill();
133     void refill(qreal from, qreal to, bool doBuffer = false);
134     void mirrorChange();
135
136     FxViewItem *createItem(int modelIndex);
137     virtual void releaseItem(FxViewItem *item);
138
139     QSGItem *createHighlightItem();
140     QSGItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false);
141
142     void updateCurrent(int modelIndex);
143     void updateTrackedItem();
144     void updateUnrequestedIndexes();
145     void updateUnrequestedPositions();
146     void updateVisibleIndex();
147     void positionViewAtIndex(int index, int mode);
148     void applyPendingChanges();
149     bool applyModelChanges();
150
151     void checkVisible() const;
152
153     void markExtentsDirty() {
154         if (layoutOrientation() == Qt::Vertical)
155             vData.markExtentsDirty();
156         else
157             hData.markExtentsDirty();
158     }
159
160     QDeclarativeGuard<QSGVisualModel> model;
161     QVariant modelVariant;
162     int itemCount;
163     int buffer;
164     int bufferMode;
165     Qt::LayoutDirection layoutDirection;
166
167     MovementReason moveReason;
168
169     QList<FxViewItem *> visibleItems;
170     int visibleIndex;
171     int currentIndex;
172     FxViewItem *currentItem;
173     FxViewItem *trackedItem;
174     QHash<QSGItem*,int> unrequestedItems;
175     int requestedIndex;
176     QSGItemViewChangeSet currentChanges;
177
178     // XXX split into struct
179     QDeclarativeComponent *highlightComponent;
180     FxViewItem *highlight;
181     int highlightRange;     // enum value
182     qreal highlightRangeStart;
183     qreal highlightRangeEnd;
184     int highlightMoveDuration;
185
186     QDeclarativeComponent *headerComponent;
187     FxViewItem *header;
188     QDeclarativeComponent *footerComponent;
189     FxViewItem *footer;
190
191     mutable qreal minExtent;
192     mutable qreal maxExtent;
193
194     bool ownModel : 1;
195     bool wrap : 1;
196     bool lazyRelease : 1;
197     bool deferredRelease : 1;
198     bool inApplyModelChanges : 1;
199     bool inViewportMoved : 1;
200     bool forceLayout : 1;
201     bool currentIndexCleared : 1;
202     bool haveHighlightRange : 1;
203     bool autoHighlight : 1;
204     bool highlightRangeStartValid : 1;
205     bool highlightRangeEndValid : 1;
206
207 protected:
208     virtual Qt::Orientation layoutOrientation() const = 0;
209     virtual bool isContentFlowReversed() const = 0;
210
211     virtual qreal positionAt(int index) const = 0;
212     virtual qreal endPositionAt(int index) const = 0;
213     virtual qreal originPosition() const = 0;
214     virtual qreal lastPosition() const = 0;
215
216     virtual qreal headerSize() const = 0;
217     virtual qreal footerSize() const = 0;
218     virtual bool showHeaderForIndex(int index) const = 0;
219     virtual bool showFooterForIndex(int index) const = 0;
220     virtual void updateHeader() = 0;
221     virtual void updateFooter() = 0;
222
223     virtual void createHighlight() = 0;
224     virtual void updateHighlight() = 0;
225     virtual void resetHighlightPosition() = 0;
226
227     virtual void setPosition(qreal pos) = 0;
228     virtual void fixupPosition() = 0;
229
230     virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) = 0;
231     virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0;
232     virtual void visibleItemsChanged() = 0;
233
234     virtual FxViewItem *newViewItem(int index, QSGItem *item) = 0;
235     virtual void repositionPackageItemAt(QSGItem *item, int index) = 0;
236     virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem) = 0;
237     virtual void resetFirstItemPosition() = 0;
238     virtual void moveItemBy(FxViewItem *item, qreal forwards, qreal backwards) = 0;
239
240     virtual void layoutVisibleItems() = 0;
241     virtual void changedVisibleIndex(int newIndex) = 0;
242     virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *) = 0;
243
244     virtual void initializeViewItem(FxViewItem *) {}
245     virtual void initializeCurrentItem() {}
246     virtual void updateSections() {}
247
248     virtual void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
249 };
250
251
252 QT_END_NAMESPACE
253
254 QT_END_HEADER
255
256 #endif // QSGITEMVIEW_P_P_H