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;
28class QQuickNumberAnimation;
29class QQuickVisualDataModel;
33 Note for users of this class
35 ListViewWithPageHeader already loads delegates async when appropiate so if
36 your delegate uses a Loader you should not enable the asynchronous feature since
37 that will need to introduce sizing problems
39 With the double async it may happen what while we are scrolling down
40 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)
41 we are already "at the end" of the list, but then a few milliseconds later the loader finishes loading and we could
42 have kept scrolling. This is specially visible at the end of the list where you realize
43 that scrolling ended a bit before the end of the list but the speed of the flicking was good
46 By not having the second async we get a better sizing when the delegate is created and things work better
49class ListViewWithPageHeader : public QQuickFlickable, public QQuickItemChangeListener
52 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
53 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
54 Q_PROPERTY(QQuickItem *pageHeader READ header WRITE setHeader NOTIFY headerChanged)
55 Q_PROPERTY(QQmlComponent *sectionDelegate READ sectionDelegate WRITE setSectionDelegate NOTIFY sectionDelegateChanged)
56 Q_PROPERTY(QString sectionProperty READ sectionProperty WRITE setSectionProperty NOTIFY sectionPropertyChanged)
57 Q_PROPERTY(bool forceNoClip READ forceNoClip WRITE setForceNoClip NOTIFY forceNoClipChanged)
59 friend class ListViewWithPageHeaderTest;
60 friend class ListViewWithPageHeaderTestSection;
63 ListViewWithPageHeader();
64 ~ListViewWithPageHeader();
66 QAbstractItemModel *model() const;
67 void setModel(QAbstractItemModel *model);
69 QQmlComponent *delegate() const;
70 void setDelegate(QQmlComponent *delegate);
72 QQuickItem *header() const;
73 void setHeader(QQuickItem *header);
75 QQmlComponent *sectionDelegate() const;
76 void setSectionDelegate(QQmlComponent *delegate);
78 QString sectionProperty() const;
79 void setSectionProperty(const QString &property);
81 bool forceNoClip() const;
82 void setForceNoClip(bool noClip);
84 Q_INVOKABLE void positionAtBeginning();
85 Q_INVOKABLE void showHeader();
89 void delegateChanged();
91 void sectionDelegateChanged();
92 void sectionPropertyChanged();
93 void forceNoClipChanged();
96 void componentComplete();
97 void viewportMoved(Qt::Orientations orient);
98 qreal minYExtent() const;
99 void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
103 void itemCreated(int modelIndex, QQuickItem *item);
104 void onContentHeightChanged();
105 void onContentWidthChanged();
106 void onHeightChanged();
107 void onModelUpdated(const QQuickChangeSet &changeSet, bool reset);
108 void onShowHeaderAnimationFinished();
114 qreal height() const;
117 void setY(qreal newY);
120 void setCulled(bool culled);
123 QQuickItem *m_sectionItem;
126 void createDelegateModel();
130 bool addVisibleItems(qreal fillFrom, qreal fillTo, bool asynchronous);
131 bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo);
132 ListItem *createItem(int modelIndex, bool asynchronous);
134 void adjustMinYExtent();
135 void updateClipItem();
136 void headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY);
137 ListItem *itemAtIndex(int modelIndex) const; // Returns the item at modelIndex if has been created
138 void releaseItem(ListItem *item);
139 void reallyReleaseItem(ListItem *item);
140 void updateWatchedRoles();
141 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
142 QQuickItem *getSectionItem(const QString §ionText);
144 QQuickVisualDataModel *m_delegateModel;
146 // Index we are waiting because we requested it asynchronously
147 int m_asyncRequestedIndex;
149 // Used to only give a warning once if the delegate does not return objects
150 bool m_delegateValidated;
152 // Visible indexes, [0] is m_firstValidIndex, [0+1] is m_firstValidIndex +1, ...
153 QList<ListItem *> m_visibleItems;
154 int m_firstVisibleIndex;
158 QQuickItem *m_clipItem;
160 // If any of the heights has changed
161 // or new items have been added/removed
162 bool m_contentHeightDirty;
164 QQuickItem *m_headerItem;
165 qreal m_previousContentY;
166 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
167 // i.e. it's being shown after dragging down in the middle of the list
168 QQuickNumberAnimation *m_headerShowAnimation;
170 QQmlComponent *m_sectionDelegate;
171 QString m_sectionProperty;
172 QQuickItem *m_topSectionItem;
177 // Qt 5.0 doesn't like releasing the items just after itemCreated
178 // so we delay the releasing until the next updatePolish
179 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