2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#ifndef LISTVIEWWITHPAGEHEADER_H
18#define LISTVIEWWITHPAGEHEADER_H
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-pedantic"
22#include <private/qquickitemchangelistener_p.h>
23#include <private/qquickflickable_p.h>
24#pragma GCC diagnostic pop
26class QAbstractItemModel;
27class QQuickNumberAnimation;
28#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
30class QQuickVisualDataModel;
33class QQmlDelegateModel;
38 Note for users of this class
40 ListViewWithPageHeader already loads delegates async when appropiate so if
41 your delegate uses a Loader you should not enable the asynchronous feature since
42 that will need to introduce sizing problems
44 With the double async it may happen what while we are scrolling down
45 we reach to a point where given the size of the just created delegate with loader not yet loaded (which will be very close to 0)
46 we are already "at the end" of the list, but then a few milliseconds later the loader finishes loading and we could
47 have kept scrolling. This is specially visible at the end of the list where you realize
48 that scrolling ended a bit before the end of the list but the speed of the flicking was good
51 By not having the second async we get a better sizing when the delegate is created and things work better
54class ListViewWithPageHeader : public QQuickFlickable, public QQuickItemChangeListener
57 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
58 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
59 Q_PROPERTY(QQuickItem *pageHeader READ header WRITE setHeader NOTIFY headerChanged)
60 Q_PROPERTY(QQmlComponent *sectionDelegate READ sectionDelegate WRITE setSectionDelegate NOTIFY sectionDelegateChanged)
61 Q_PROPERTY(QString sectionProperty READ sectionProperty WRITE setSectionProperty NOTIFY sectionPropertyChanged)
62 Q_PROPERTY(bool forceNoClip READ forceNoClip WRITE setForceNoClip NOTIFY forceNoClipChanged)
64 friend class ListViewWithPageHeaderTest;
65 friend class ListViewWithPageHeaderTestSection;
68 ListViewWithPageHeader();
69 ~ListViewWithPageHeader();
71 QAbstractItemModel *model() const;
72 void setModel(QAbstractItemModel *model);
74 QQmlComponent *delegate() const;
75 void setDelegate(QQmlComponent *delegate);
77 QQuickItem *header() const;
78 void setHeader(QQuickItem *header);
80 QQmlComponent *sectionDelegate() const;
81 void setSectionDelegate(QQmlComponent *delegate);
83 QString sectionProperty() const;
84 void setSectionProperty(const QString &property);
86 bool forceNoClip() const;
87 void setForceNoClip(bool noClip);
89 Q_INVOKABLE void positionAtBeginning();
90 Q_INVOKABLE void showHeader();
91 Q_INVOKABLE QQuickItem *item(int modelIndex) const;
93 // The index has to be created for this to try to do something
94 // Created items are those visible and the precached ones
95 // Returns if the item existed or not
96 Q_INVOKABLE bool maximizeVisibleArea(int modelIndex);
97 Q_INVOKABLE bool maximizeVisibleArea(int modelIndex, int itemHeight);
101 void delegateChanged();
102 void headerChanged();
103 void sectionDelegateChanged();
104 void sectionPropertyChanged();
105 void forceNoClipChanged();
108 void componentComplete();
109 void viewportMoved(Qt::Orientations orient);
110 qreal minYExtent() const;
111 void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
115#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
116 void itemCreated(int modelIndex, QQuickItem *item);
118 void itemCreated(int modelIndex, QObject *object);
120 void onContentHeightChanged();
121 void onContentWidthChanged();
122 void onHeightChanged();
123#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
124 void onModelUpdated(const QQuickChangeSet &changeSet, bool reset);
126 void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
128 void onShowHeaderAnimationFinished();
134 qreal height() const;
137 void setY(qreal newY);
140 void setCulled(bool culled);
143 QQuickItem *m_sectionItem;
146 bool maximizeVisibleArea(ListItem *listItem, int listItemHeight);
148 void createDelegateModel();
152 bool addVisibleItems(qreal fillFrom, qreal fillTo, bool asynchronous);
153 bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo);
154 ListItem *createItem(int modelIndex, bool asynchronous);
156 void adjustMinYExtent();
157 void updateClipItem();
158 void headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY);
159 ListItem *itemAtIndex(int modelIndex) const; // Returns the item at modelIndex if has been created
160 void releaseItem(ListItem *item);
161 void reallyReleaseItem(ListItem *item);
162 void updateWatchedRoles();
163 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
164 QQuickItem *getSectionItem(const QString §ionText);
166#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
167 QQuickVisualDataModel *m_delegateModel;
169 QQmlDelegateModel *m_delegateModel;
172 // Index we are waiting because we requested it asynchronously
173 int m_asyncRequestedIndex;
175 // Used to only give a warning once if the delegate does not return objects
176 bool m_delegateValidated;
178 // Visible indexes, [0] is m_firstValidIndex, [0+1] is m_firstValidIndex +1, ...
179 QList<ListItem *> m_visibleItems;
180 int m_firstVisibleIndex;
184 QQuickItem *m_clipItem;
186 // If any of the heights has changed
187 // or new items have been added/removed
188 bool m_contentHeightDirty;
190 QQuickItem *m_headerItem;
191 qreal m_previousContentY;
192 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
193 // i.e. it's being shown after dragging down in the middle of the list
194 enum ContentYAnimationType { ContentYAnimationShowHeader, ContentYAnimationMaximizeVisibleArea };
195 ContentYAnimationType contentYAnimationType;
196 QQuickNumberAnimation *m_contentYAnimation;
198 QQmlComponent *m_sectionDelegate;
199 QString m_sectionProperty;
200 QQuickItem *m_topSectionItem;
205 // Qt 5.0 doesn't like releasing the items just after itemCreated
206 // so we delay the releasing until the next updatePolish
207 QList<ListItem *> m_itemsToRelease;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list