on d8abd84 help sign in
unity8/plugins/ListViewWithPageHeader/listviewwithpageheader.cpp
1265 lines 50 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17/*
18 * Some documentation on how this thing works:
19 *
20 * A flickable has two very important concepts that define the top and
21 * height of the flickable area.
22 * The top is returned in minYExtent()
23 * The height is set using setContentHeight()
24 * By changing those two values we can make the list grow up or down
25 * as needed. e.g. if we are in the middle of the list
26 * and something that is above the viewport grows, since we do not
27 * want to change the viewport because of that we just adjust the
28 * minYExtent so that the list grows up.
29 *
30 * The implementation on the list relies on the delegateModel doing
31 * most of the instantiation work. You call createItem() when you
32 * need to create an item asking for it async or not. If returns null
33 * it means the item will be created async and the model will call the
34 * itemCreated slot with the item.
35 *
36 * updatePolish is the central point of dispatch for the work of the
37 * class. It is called by the scene graph just before drawing the class.
38 * In it we:
39 * * Make sure all items are positioned correctly
40 * * Add/Remove items if needed
41 * * Update the content height if it was dirty
42 *
43 * m_visibleItems contains all the items we have created at the moment.
44 * Actually not all of them are visible since it includes the ones
45 * in the cache area we create asynchronously to help performance.
46 * The first item in m_visibleItems has the m_firstVisibleIndex in
47 * the model. If you actually want to know what is the first
48 * item in the viewport you have to find the first non culled element
49 * in m_visibleItems
50 *
51 * All the items (except the header) are childs of m_clipItem which
52 * is a child of the contentItem() of the flickable (The contentItem()
53 * is what actually 'moves' in a a flickable). This way
54 * we can implement the clipping needed so we can have the header
55 * shown in the middle of the list over the items without the items
56 * leaking under the header in case it is transparent.
57 *
58 * The first item of m_visibleItems is the one that defines the
59 * positions of all the rest of items (see updatePolish()) and
60 * this is why sometimes we move it even if it's not the item
61 * that has triggered the function (i.e. in itemGeometryChanged())
62 *
63 * m_visibleItems is a list of ListItem. Each ListItem
64 * will contain a item and potentially a sectionItem. The sectionItem
65 * is only there when the list is using sectionDelegate+sectionProperty
66 * and this is the first item of the section. Each ListItem is vertically
67 * layouted with the sectionItem first and then the item.
68 *
69 * For sectioning we also have a section item alone (m_topSectionItem)
70 * that is used for the cases we need to show the sticky section item at
71 * the top of the view.
72 *
73 * Each delegate item has a context property called heightToClip that is
74 * used to communicate to the delegate implementation in case it has to
75 * clip itself because of overlapping with the top sticky section item.
76 * This is an implementation decision since it has been agreed it
77 * is easier to implement the clipping in QML with this info than to
78 * do it at the C++ level.
79 *
80 * Note that minYExtent and height are not always totally accurate, since
81 * we don't have the items created we can't guess their heights
82 * so we can only guarantee the values are correct when the first/last
83 * items of the list are visible, otherwise we just live with good enough
84 * values that make the list scrollable
85 *
86 * There are a few things that are not really implemented or tested properly
87 * which we don't use at the moment like changing the model, changing
88 * the section delegate, having a section delegate that changes its size, etc.
89 * The known missing features are marked with TODOs along the code.
90 */
92#include "listviewwithpageheader.h"
94#include <QDebug>
95#include <qqmlinfo.h>
96#include <qqmlengine.h>
97#pragma GCC diagnostic push
98#pragma GCC diagnostic ignored "-pedantic"
99#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
100#include <private/qquickvisualdatamodel_p.h>
101#else
102#include <private/qqmldelegatemodel_p.h>
103#endif
104#include <private/qqmlglobal_p.h>
105#include <private/qquickitem_p.h>
106#include <private/qquickanimation_p.h>
107#pragma GCC diagnostic pop
108// #include <private/qquickrectangle_p.h>
110static const qreal bufferRatio = 0.5;
112qreal ListViewWithPageHeader::ListItem::height() const
114 return m_item->height() + (m_sectionItem ? m_sectionItem->height() : 0);
117qreal ListViewWithPageHeader::ListItem::y() const
119 return m_item->y() - (m_sectionItem ? m_sectionItem->height() : 0);
122void ListViewWithPageHeader::ListItem::setY(qreal newY)
124 if (m_sectionItem) {
125 m_sectionItem->setY(newY);
126 m_item->setY(newY + m_sectionItem->height());
127 } else {
128 m_item->setY(newY);
129 }
132bool ListViewWithPageHeader::ListItem::culled() const
134 return QQuickItemPrivate::get(m_item)->culled;
137void ListViewWithPageHeader::ListItem::setCulled(bool culled)
139 QQuickItemPrivate::get(m_item)->setCulled(culled);
140 if (m_sectionItem)
141 QQuickItemPrivate::get(m_sectionItem)->setCulled(culled);
144ListViewWithPageHeader::ListViewWithPageHeader()
145 : m_delegateModel(nullptr)
146 , m_asyncRequestedIndex(-1)
147 , m_delegateValidated(false)
148 , m_firstVisibleIndex(-1)
149 , m_minYExtent(0)
150 , m_contentHeightDirty(false)
151 , m_headerItem(nullptr)
152 , m_previousContentY(0)
153 , m_headerItemShownHeight(0)
154 , m_sectionDelegate(nullptr)
155 , m_topSectionItem(nullptr)
156 , m_forceNoClip(false)
157 , m_inLayout(false)
159 m_clipItem = new QQuickItem(contentItem());
160// m_clipItem = new QQuickRectangle(contentItem());
161// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
163 m_contentYAnimation = new QQuickNumberAnimation(this);
164 m_contentYAnimation->setEasing(QEasingCurve::OutQuad);
165 m_contentYAnimation->setProperty("contentY");
166 m_contentYAnimation->setDuration(200);
167 m_contentYAnimation->setTargetObject(this);
169 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
170 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
171 connect(this, SIGNAL(heightChanged()), this, SLOT(onHeightChanged()));
172 connect(m_contentYAnimation, SIGNAL(stopped()), this, SLOT(onShowHeaderAnimationFinished()));
175ListViewWithPageHeader::~ListViewWithPageHeader()
179QAbstractItemModel *ListViewWithPageHeader::model() const
181 return m_delegateModel ? m_delegateModel->model().value<QAbstractItemModel *>() : nullptr;
184void ListViewWithPageHeader::setModel(QAbstractItemModel *model)
186 if (model != this->model()) {
187 if (!m_delegateModel) {
188 createDelegateModel();
189 } else {
190#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
191 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
192 }
193 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
194 connect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
195#else
196 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
197 }
198 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
199 connect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
200#endif
201 Q_EMIT modelChanged();
202 polish();
203 // TODO?
204// Q_EMIT contentHeightChanged();
205// Q_EMIT contentYChanged();
206 }
209QQmlComponent *ListViewWithPageHeader::delegate() const
211 return m_delegateModel ? m_delegateModel->delegate() : nullptr;
214void ListViewWithPageHeader::setDelegate(QQmlComponent *delegate)
216 if (delegate != this->delegate()) {
217 if (!m_delegateModel) {
218 createDelegateModel();
219 }
221 // Cleanup the existing items
222 Q_FOREACH(ListItem *item, m_visibleItems)
223 releaseItem(item);
224 m_visibleItems.clear();
225 m_firstVisibleIndex = -1;
226 adjustMinYExtent();
227 setContentY(0);
228 m_clipItem->setY(0);
229 if (m_topSectionItem) {
230 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
231 }
233 m_delegateModel->setDelegate(delegate);
235 Q_EMIT delegateChanged();
236 m_delegateValidated = false;
237 m_contentHeightDirty = true;
238 polish();
239 }
242QQuickItem *ListViewWithPageHeader::header() const
244 return m_headerItem;
247void ListViewWithPageHeader::setHeader(QQuickItem *headerItem)
249 if (m_headerItem != headerItem) {
250 qreal oldHeaderHeight = 0;
251 qreal oldHeaderY = 0;
252 if (m_headerItem) {
253 oldHeaderHeight = m_headerItem->height();
254 oldHeaderY = m_headerItem->y();
255 m_headerItem->setParentItem(nullptr);
256 }
257 m_headerItem = headerItem;
258 if (m_headerItem) {
259 m_headerItem->setParentItem(contentItem());
260 m_headerItem->setZ(1);
261 }
262 qreal newHeaderHeight = m_headerItem ? m_headerItem->height() : 0;
263 if (!m_visibleItems.isEmpty() && newHeaderHeight != oldHeaderHeight) {
264 headerHeightChanged(newHeaderHeight, oldHeaderHeight, oldHeaderY);
265 polish();
266 m_contentHeightDirty = true;
267 }
268 Q_EMIT headerChanged();
269 }
272QQmlComponent *ListViewWithPageHeader::sectionDelegate() const
274 return m_sectionDelegate;
277void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
279 if (delegate != m_sectionDelegate) {
280 // TODO clean existing sections
282 m_sectionDelegate = delegate;
284 m_topSectionItem = getSectionItem(QString());
285 m_topSectionItem->setZ(3);
286 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
288 // TODO create sections for existing items
290 Q_EMIT sectionDelegateChanged();
291 }
294QString ListViewWithPageHeader::sectionProperty() const
296 return m_sectionProperty;
299void ListViewWithPageHeader::setSectionProperty(const QString &property)
301 if (property != m_sectionProperty) {
302 m_sectionProperty = property;
304 updateWatchedRoles();
306 // TODO recreate sections
308 Q_EMIT sectionPropertyChanged();
309 }
312bool ListViewWithPageHeader::forceNoClip() const
314 return m_forceNoClip;
317void ListViewWithPageHeader::setForceNoClip(bool noClip)
319 if (noClip != m_forceNoClip) {
320 m_forceNoClip = noClip;
321 updateClipItem();
322 Q_EMIT forceNoClipChanged();
323 }
326void ListViewWithPageHeader::positionAtBeginning()
328 qreal headerHeight = (m_headerItem ? m_headerItem->height() : 0);
329 if (m_firstVisibleIndex != 0) {
330 // TODO This could be optimized by trying to reuse the interesection
331 // of items that may end up intersecting between the existing
332 // m_visibleItems and the items we are creating in the next loop
333 Q_FOREACH(ListItem *item, m_visibleItems)
334 releaseItem(item);
335 m_visibleItems.clear();
336 m_firstVisibleIndex = -1;
338 // Create the item 0, it will be already correctly positioned at createItem()
339 m_clipItem->setY(0);
340 ListItem *item = createItem(0, false);
341 // Create the subsequent items
342 int modelIndex = 1;
343 qreal pos = item->y() + item->height();
344 const qreal buffer = height() * bufferRatio;
345 const qreal bufferTo = height() + buffer;
346 while (modelIndex < m_delegateModel->count() && pos <= bufferTo) {
347 if (!(item = createItem(modelIndex, false)))
348 break;
349 pos += item->height();
350 ++modelIndex;
351 }
353 m_previousContentY = m_visibleItems.first()->y() - headerHeight;
354 }
355 setContentY(m_visibleItems.first()->y() + m_clipItem->y() - headerHeight);
358void ListViewWithPageHeader::showHeader()
360 if (!m_headerItem)
361 return;
363 auto to = qMax(-minYExtent(), contentY() - m_headerItem->height() + m_headerItemShownHeight);
364 if (to != contentY()) {
365 const bool headerShownByItsOwn = contentY() < m_headerItem->y() + m_headerItem->height();
366 if (headerShownByItsOwn && m_headerItemShownHeight == 0) {
367 // We are not clipping since we are just at the top of the viewport
368 // but because of the showHeader animation we will need to, so
369 // enable the clipping without logically moving the items
370 m_headerItemShownHeight = m_headerItem->y() + m_headerItem->height() - contentY();
371 if (!m_visibleItems.isEmpty()) {
372 updateClipItem();
373 ListItem *firstItem = m_visibleItems.first();
374 firstItem->setY(firstItem->y() - m_headerItemShownHeight);
375 layout();
376 }
377 }
378 m_contentYAnimation->setTo(to);
379 contentYAnimationType = ContentYAnimationShowHeader;
380 m_contentYAnimation->start();
381 }
384QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
386 ListItem *item = itemAtIndex(modelIndex);
387 if (item)
388 return item->m_item;
389 else
390 return nullptr;
393bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
395 ListItem *listItem = itemAtIndex(modelIndex);
396 if (listItem) {
397 return maximizeVisibleArea(listItem, listItem->height());
398 }
400 return false;
403bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex, int itemHeight)
405 if (itemHeight < 0)
406 return false;
408 ListItem *listItem = itemAtIndex(modelIndex);
409 if (listItem) {
410 return maximizeVisibleArea(listItem, itemHeight + (listItem->m_sectionItem ? listItem->m_sectionItem->height() : 0));
411 }
413 return false;
416bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listItemHeight)
418 if (listItem) {
419 layout();
420 const auto listItemY = m_clipItem->y() + listItem->y();
421 if (listItemY > contentY() && listItemY + listItemHeight > contentY() + height()) {
422 // we can scroll the list up to show more stuff
423 const auto to = qMin(listItemY, listItemY + listItemHeight - height());
424 m_contentYAnimation->setTo(to);
425 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
426 m_contentYAnimation->start();
427 } else if ((listItemY < contentY() && listItemY + listItemHeight < contentY() + height()) ||
428 (m_topSectionItem && !listItem->m_sectionItem && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItemHeight < contentY() + height()))
429 {
430 // we can scroll the list down to show more stuff
431 auto realVisibleListItemY = listItemY;
432 if (m_topSectionItem) {
433 // If we are showing the top section sticky item and this item doesn't have a section
434 // item we have to make sure to scroll it a bit more so that it is not underlapping
435 // the top section sticky item
436 bool topSectionShown = !QQuickItemPrivate::get(m_topSectionItem)->culled;
437 if (topSectionShown && !listItem->m_sectionItem) {
438 realVisibleListItemY -= m_topSectionItem->height();
439 }
440 }
441 const auto to = qMax(realVisibleListItemY, listItemY + listItemHeight - height());
442 m_contentYAnimation->setTo(to);
443 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
444 m_contentYAnimation->start();
445 }
446 return true;
447 }
448 return false;
451qreal ListViewWithPageHeader::minYExtent() const
453// qDebug() << "ListViewWithPageHeader::minYExtent" << m_minYExtent;
454 return m_minYExtent;
457void ListViewWithPageHeader::componentComplete()
459 if (m_delegateModel)
460 m_delegateModel->componentComplete();
462 QQuickFlickable::componentComplete();
464 polish();
467void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
469 QQuickFlickable::viewportMoved(orient);
470// qDebug() << "ListViewWithPageHeader::viewportMoved" << contentY();
471 qreal diff = m_previousContentY - contentY();
472 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
473 if (m_headerItem) {
474 auto oldHeaderItemShownHeight = m_headerItemShownHeight;
475 if (contentY() < -m_minYExtent) {
476 // Stick the header item to the top when dragging down
477 m_headerItem->setY(contentY());
478 m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
479 } else {
480 m_headerItem->setHeight(m_headerItem->implicitHeight());
481 // We are going down (but it's not because of the rebound at the end)
482 // (but the header was not shown by it's own position)
483 // or the header is partially shown and we are not doing a maximizeVisibleArea either
484 const bool scrolledUp = m_previousContentY > contentY();
485 const bool notRebounding = contentY() + height() < contentHeight();
486 const bool notShownByItsOwn = contentY() + diff > m_headerItem->y() + m_headerItem->height();
487 const bool maximizeVisibleAreaRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationMaximizeVisibleArea;
489 if (!scrolledUp && contentY() == -m_minYExtent) {
490 m_headerItemShownHeight = 0;
491 m_headerItem->setY(contentY());
492 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0)) {
493 if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
494 m_headerItemShownHeight -= diff;
495 else
496 m_headerItemShownHeight += diff;
497 if (contentY() == -m_minYExtent) {
498 m_headerItemShownHeight = 0;
499 } else {
500 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
501 }
502 if (m_headerItemShownHeight > 0) {
503 m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
504 } else {
505 m_headerItem->setY(-m_minYExtent);
506 }
507 }
508 }
509 // We will be changing the clip item, need to accomadate for it
510 // otherwise we move the firstItem down/up twice (unless the
511 // show header animation is running, where we want to keep the viewport stable)
512 if (!showHeaderAnimationRunning) {
513 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
514 } else {
515 diff = -diff;
516 }
517 }
518 if (!m_visibleItems.isEmpty()) {
519 updateClipItem();
520 ListItem *firstItem = m_visibleItems.first();
521 firstItem->setY(firstItem->y() + diff);
522 if (showHeaderAnimationRunning) {
523 adjustMinYExtent();
524 }
525 }
527 m_previousContentY = contentY();
528 layout();
529 polish();
532void ListViewWithPageHeader::createDelegateModel()
534#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
535 m_delegateModel = new QQuickVisualDataModel(qmlContext(this), this);
536 connect(m_delegateModel, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(itemCreated(int,QQuickItem*)));
537#else
538 m_delegateModel = new QQmlDelegateModel(qmlContext(this), this);
539 connect(m_delegateModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(itemCreated(int,QObject*)));
540#endif
541 if (isComponentComplete())
542 m_delegateModel->componentComplete();
543 updateWatchedRoles();
546void ListViewWithPageHeader::refill()
548 if (m_inLayout) {
549 return;
550 }
551 if (!isComponentComplete()) {
552 return;
553 }
555 const qreal buffer = height() * bufferRatio;
556 const qreal from = contentY();
557 const qreal to = from + height();
558 const qreal bufferFrom = from - buffer;
559 const qreal bufferTo = to + buffer;
561 bool added = addVisibleItems(from, to, false);
562 bool removed = removeNonVisibleItems(bufferFrom, bufferTo);
563 added |= addVisibleItems(bufferFrom, bufferTo, true);
565 if (added || removed) {
566 m_contentHeightDirty = true;
567 }
570bool ListViewWithPageHeader::addVisibleItems(qreal fillFrom, qreal fillTo, bool asynchronous)
572 if (!delegate())
573 return false;
575 if (m_delegateModel->count() == 0)
576 return false;
578 ListItem *item;
579// qDebug() << "ListViewWithPageHeader::addVisibleItems" << fillFrom << fillTo << asynchronous;
581 int modelIndex = 0;
582 qreal pos = 0;
583 if (!m_visibleItems.isEmpty()) {
584 modelIndex = m_firstVisibleIndex + m_visibleItems.count();
585 item = m_visibleItems.last();
586 pos = item->y() + item->height() + m_clipItem->y();
587 }
588 bool changed = false;
589// qDebug() << (modelIndex < m_delegateModel->count()) << pos << fillTo;
590 while (modelIndex < m_delegateModel->count() && pos <= fillTo) {
591// qDebug() << "refill: append item" << modelIndex << "pos" << pos << "asynchronous" << asynchronous;
592 if (!(item = createItem(modelIndex, asynchronous)))
593 break;
594 pos += item->height();
595 ++modelIndex;
596 changed = true;
597 }
599 modelIndex = 0;
600 pos = 0;
601 if (!m_visibleItems.isEmpty()) {
602 modelIndex = m_firstVisibleIndex - 1;
603 item = m_visibleItems.first();
604 pos = item->y() + m_clipItem->y();
605 }
606 while (modelIndex >= 0 && pos > fillFrom) {
607// qDebug() << "refill: prepend item" << modelIndex << "pos" << pos << "fillFrom" << fillFrom << "asynchronous" << asynchronous;
608 if (!(item = createItem(modelIndex, asynchronous)))
609 break;
610 pos -= item->height();
611 --modelIndex;
612 changed = true;
613 }
615 return changed;
618void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
620 QQuickItem *item = listItem->m_item;
621#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
622 QQuickVisualModel::ReleaseFlags flags = m_delegateModel->release(item);
623 if (flags & QQuickVisualModel::Destroyed) {
624#else
625 QQmlDelegateModel::ReleaseFlags flags = m_delegateModel->release(item);
626 if (flags & QQmlDelegateModel::Destroyed) {
627#endif
628 item->setParentItem(nullptr);
629 }
630 delete listItem->m_sectionItem;
631 delete listItem;
634void ListViewWithPageHeader::releaseItem(ListItem *listItem)
636 QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(listItem->m_item);
637 itemPrivate->removeItemChangeListener(this, QQuickItemPrivate::Geometry);
638 m_itemsToRelease << listItem;
641void ListViewWithPageHeader::updateWatchedRoles()
643 if (m_delegateModel) {
644 QList<QByteArray> roles;
645 if (!m_sectionProperty.isEmpty())
646 roles << m_sectionProperty.toUtf8();
647 m_delegateModel->setWatchedRoles(roles);
648 }
651QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyInserted)
653 if (!m_sectionDelegate)
654 return nullptr;
656 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
657 if (modelIndex > 0) {
658 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
659 if (section == prevSection)
660 return nullptr;
661 }
662 if (modelIndex + 1 < model()->rowCount() && !alreadyInserted) {
663 // Already inserted items can't steal next section header
664 const QString nextSection = m_delegateModel->stringValue(modelIndex + 1, m_sectionProperty);
665 if (section == nextSection) {
666 // Steal the section header
667 ListItem *nextItem = itemAtIndex(modelIndex); // Not +1 since not yet inserted into m_visibleItems
668 if (nextItem) {
669 QQuickItem *sectionItem = nextItem->m_sectionItem;
670 nextItem->m_sectionItem = nullptr;
671 return sectionItem;
672 }
673 }
674 }
676 return getSectionItem(section);
679QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText)
681 QQuickItem *sectionItem = nullptr;
683 QQmlContext *creationContext = m_sectionDelegate->creationContext();
684 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
685 context->setContextProperty(QLatin1String("section"), sectionText);
686 context->setContextProperty(QLatin1String("delegateIndex"), -1);
687 QObject *nobj = m_sectionDelegate->beginCreate(context);
688 if (nobj) {
689 QQml_setParent_noEvent(context, nobj);
690 sectionItem = qobject_cast<QQuickItem *>(nobj);
691 if (!sectionItem) {
692 delete nobj;
693 } else {
694 sectionItem->setZ(2);
695 QQml_setParent_noEvent(sectionItem, m_clipItem);
696 sectionItem->setParentItem(m_clipItem);
697 }
698 } else {
699 delete context;
700 }
701 m_sectionDelegate->completeCreate();
703 // TODO attach to sectionItem so we can accomodate to it changing its height
705 return sectionItem;
708bool ListViewWithPageHeader::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo)
710// qDebug() << "ListViewWithPageHeader::removeNonVisibleItems" << bufferFrom << bufferTo;
711 // Do not remove items if we are overshooting up or down, since we'll come back
712 // to the "stable" position and delete/create items without any reason
713 if (contentY() < -m_minYExtent) {
714 return false;
715 } else if (contentY() + height() > contentHeight()) {
716 return false;
717 }
718 bool changed = false;
720 bool foundVisible = false;
721 int i = 0;
722 int removedItems = 0;
723 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
724 while (i < m_visibleItems.count()) {
725 ListItem *item = m_visibleItems[i];
726 const qreal pos = item->y() + m_clipItem->y();
727// qDebug() << i << pos << (pos + item->height()) << bufferFrom << bufferTo;
728 if (pos + item->height() < bufferFrom || pos > bufferTo) {
729// qDebug() << "Releasing" << i << (pos + item->height() < bufferFrom) << pos + item->height() << bufferFrom << (pos > bufferTo) << pos << bufferTo;
730 releaseItem(item);
731 m_visibleItems.removeAt(i);
732 changed = true;
733 ++removedItems;
734 } else {
735 if (!foundVisible) {
736 foundVisible = true;
737 const int itemIndex = m_firstVisibleIndex + removedItems + i;
738 m_firstVisibleIndex = itemIndex;
739 }
740 ++i;
741 }
742 }
743 if (m_firstVisibleIndex != oldFirstVisibleIndex) {
744 adjustMinYExtent();
745 }
747 return changed;
750ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIndex, bool asynchronous)
752// qDebug() << "CREATE ITEM" << modelIndex;
753 if (asynchronous && m_asyncRequestedIndex != -1)
754 return nullptr;
756 m_asyncRequestedIndex = -1;
757#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
758 QQuickItem *item = m_delegateModel->item(modelIndex, asynchronous);
759#else
760 QObject* object = m_delegateModel->object(modelIndex, asynchronous);
761 QQuickItem *item = qmlobject_cast<QQuickItem*>(object);
762#endif
763 if (!item) {
764#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
765 m_asyncRequestedIndex = modelIndex;
766#else
767 if (object) {
768 m_delegateModel->release(object);
769 if (!m_delegateValidated) {
770 m_delegateValidated = true;
771 QObject* delegateObj = delegate();
772 qmlInfo(delegateObj ? delegateObj : this) << "Delegate must be of Item type";
773 }
774 } else {
775 m_asyncRequestedIndex = modelIndex;
776 }
777#endif
778 return 0;
779 } else {
780// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
781 ListItem *listItem = new ListItem;
782 listItem->m_item = item;
783 listItem->m_sectionItem = getSectionItem(modelIndex, false /*Not yet inserted into m_visibleItems*/);
784 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
785 ListItem *prevItem = itemAtIndex(modelIndex - 1);
786 bool lostItem = false; // Is an item that we requested async but because of model changes
787 // it is no longer attached to any of the existing items (has no prev nor next item)
788 // nor is the first item
789 if (prevItem) {
790 listItem->setY(prevItem->y() + prevItem->height());
791 } else {
792 ListItem *currItem = itemAtIndex(modelIndex);
793 if (currItem) {
794 // There's something already in m_visibleItems at out index, meaning this is an insert, so attach to its top
795 listItem->setY(currItem->y() - listItem->height());
796 } else {
797 ListItem *nextItem = itemAtIndex(modelIndex + 1);
798 if (nextItem) {
799 listItem->setY(nextItem->y() - listItem->height());
800 } else if (modelIndex == 0 && m_headerItem) {
801 listItem->setY(m_headerItem->height());
802 } else if (!m_visibleItems.isEmpty()) {
803 lostItem = true;
804 }
805 }
806 }
807 if (lostItem) {
808 releaseItem(listItem);
809 listItem = nullptr;
810 } else {
811 listItem->setCulled(listItem->y() + listItem->height() + m_clipItem->y() <= contentY() || listItem->y() + m_clipItem->y() >= contentY() + height());
812 if (m_visibleItems.isEmpty()) {
813 m_visibleItems << listItem;
814 } else {
815 m_visibleItems.insert(modelIndex - m_firstVisibleIndex, listItem);
816 }
817 if (m_firstVisibleIndex < 0 || modelIndex < m_firstVisibleIndex) {
818 m_firstVisibleIndex = modelIndex;
819 polish();
820 }
821 if (listItem->m_sectionItem) {
822 QQmlContext *context = QQmlEngine::contextForObject(listItem->m_sectionItem)->parentContext();
823 context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
824 }
825 adjustMinYExtent();
826 m_contentHeightDirty = true;
827 }
828 return listItem;
829 }
832#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
833void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
835#else
836void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
838 QQuickItem *item = qmlobject_cast<QQuickItem*>(object);
839 if (!item) {
840 qWarning() << "ListViewWithPageHeader::itemCreated got a non item for index" << modelIndex;
841 return;
842 }
843#endif
844// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
846 item->setParentItem(m_clipItem);
847 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
848 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
849 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
850 if (modelIndex == m_asyncRequestedIndex) {
851 createItem(modelIndex, false);
852 refill();
853 }
856void ListViewWithPageHeader::updateClipItem()
858 m_clipItem->setHeight(height() - m_headerItemShownHeight);
859 m_clipItem->setY(contentY() + m_headerItemShownHeight);
860 m_clipItem->setClip(!m_forceNoClip && m_headerItemShownHeight > 0);
863void ListViewWithPageHeader::onContentHeightChanged()
865 updateClipItem();
868void ListViewWithPageHeader::onContentWidthChanged()
870 m_clipItem->setWidth(contentItem()->width());
873void ListViewWithPageHeader::onHeightChanged()
875 polish();
879#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
880void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
881#else
882void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool /*reset*/)
883#endif
885 // TODO Do something with reset
886// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
887 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
889#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
890 Q_FOREACH(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
891#else
892 Q_FOREACH(const QQmlChangeSet::Remove &remove, changeSet.removes()) {
893#endif
894// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove.index << remove.count;
895 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
896 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
897 // If all the items we are removing are either not created or culled
898 // we have to grow down to avoid viewport changing
899 bool growDown = true;
900 for (int i = 0; growDown && i < remove.count; ++i) {
901 const int modelIndex = remove.index + i;
902 ListItem *item = itemAtIndex(modelIndex);
903 if (item && !item->culled()) {
904 growDown = false;
905 }
906 }
907 for (int i = remove.count - 1; i >= 0; --i) {
908 const int visibleIndex = remove.index + i - m_firstVisibleIndex;
909 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
910 ListItem *item = m_visibleItems[visibleIndex];
911 // Pass the section item down if needed
912 if (item->m_sectionItem && visibleIndex + 1 < m_visibleItems.count()) {
913 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
914 if (!nextItem->m_sectionItem) {
915 nextItem->m_sectionItem = item->m_sectionItem;
916 item->m_sectionItem = nullptr;
917 }
918 }
919 releaseItem(item);
920 m_visibleItems.removeAt(visibleIndex);
921 }
922 }
923 if (growDown) {
924 adjustMinYExtent();
925 } else if (remove.index <= m_firstVisibleIndex) {
926 if (!m_visibleItems.isEmpty()) {
927 // We removed the first item that is the one that positions the rest
928 // position the new first item correctly
929 m_visibleItems.first()->setY(oldFirstValidIndexPos);
930 } else {
931 m_firstVisibleIndex = -1;
932 }
933 }
934 } else if (remove.index + remove.count <= m_firstVisibleIndex) {
935 m_firstVisibleIndex -= remove.count;
936 }
937 for (int i = remove.count - 1; i >= 0; --i) {
938 const int modelIndex = remove.index + i;
939 if (modelIndex == m_asyncRequestedIndex) {
940 m_asyncRequestedIndex = -1;
941 } else if (modelIndex < m_asyncRequestedIndex) {
942 m_asyncRequestedIndex--;
943 }
944 }
945 }
947#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
948 Q_FOREACH(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
949#else
950 Q_FOREACH(const QQmlChangeSet::Insert &insert, changeSet.inserts()) {
951#endif
952// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert.index << insert.count;
953 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
954 const bool firstItemWithViewOnTop = insert.index == 0 && m_firstVisibleIndex == 0 && m_visibleItems.first()->y() + m_clipItem->y() > contentY();
955 if (insertingInValidIndexes || firstItemWithViewOnTop)
956 {
957 // If the items we are adding won't be really visible
958 // we grow up instead of down to not change the viewport
959 bool growUp = false;
960 if (!firstItemWithViewOnTop) {
961 for (int i = 0; i < m_visibleItems.count(); ++i) {
962 if (!m_visibleItems[i]->culled()) {
963 if (insert.index <= m_firstVisibleIndex + i) {
964 growUp = true;
965 }
966 break;
967 }
968 }
969 }
971 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
972 for (int i = insert.count - 1; i >= 0; --i) {
973 const int modelIndex = insert.index + i;
974 ListItem *item = createItem(modelIndex, false);
975 if (growUp) {
976 ListItem *firstItem = m_visibleItems.first();
977 firstItem->setY(firstItem->y() - item->height());
978 adjustMinYExtent();
979 }
980 // Adding an item may break a "same section" chain, so check
981 // if we need adding a new section item
982 if (m_sectionDelegate) {
983 ListItem *nextItem = itemAtIndex(modelIndex + 1);
984 if (nextItem && !nextItem->m_sectionItem) {
985 nextItem->m_sectionItem = getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/);
986 if (growUp && nextItem->m_sectionItem) {
987 ListItem *firstItem = m_visibleItems.first();
988 firstItem->setY(firstItem->y() - nextItem->m_sectionItem->height());
989 adjustMinYExtent();
990 }
991 }
992 }
993 }
994 if (firstItemWithViewOnTop) {
995 ListItem *firstItem = m_visibleItems.first();
996 firstItem->setY(oldFirstValidIndexPos);
997 }
998 } else if (insert.index <= m_firstVisibleIndex) {
999 m_firstVisibleIndex += insert.count;
1002 for (int i = insert.count - 1; i >= 0; --i) {
1003 const int modelIndex = insert.index + i;
1004 if (modelIndex <= m_asyncRequestedIndex) {
1005 m_asyncRequestedIndex++;
1010 Q_FOREACH(const QQuickChangeSet::Change &change, changeSet.changes()) {
1011// qDebug() << "ListViewWithPageHeader::onModelUpdated Change" << change.index << change.count;
1012 for (int i = change.index; i < change.count; ++i) {
1013 ListItem *item = itemAtIndex(i);
1014 if (item && item->m_sectionItem) {
1015 QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1016 const QString sectionText = m_delegateModel->stringValue(i, m_sectionProperty);
1017 context->setContextProperty(QLatin1String("section"), sectionText);
1022 if (m_firstVisibleIndex != oldFirstVisibleIndex) {
1023 adjustMinYExtent();
1026 for (int i = 0; i < m_visibleItems.count(); ++i) {
1027 ListItem *item = m_visibleItems[i];
1028 if (item->m_sectionItem) {
1029 QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1030 context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
1034 layout();
1035 polish();
1036 m_contentHeightDirty = true;
1039void ListViewWithPageHeader::onShowHeaderAnimationFinished()
1041 m_contentHeightDirty = true;
1042 polish();
1045void ListViewWithPageHeader::itemGeometryChanged(QQuickItem * /*item*/, const QRectF &newGeometry, const QRectF &oldGeometry)
1047 const qreal heightDiff = newGeometry.height() - oldGeometry.height();
1048 if (heightDiff != 0) {
1049 if (oldGeometry.y() + oldGeometry.height() + m_clipItem->y() < contentY() && !m_visibleItems.isEmpty()) {
1050 ListItem *firstItem = m_visibleItems.first();
1051 firstItem->setY(firstItem->y() - heightDiff);
1052 adjustMinYExtent();
1053 layout();
1055 refill();
1056 adjustMinYExtent();
1057 polish();
1058 m_contentHeightDirty = true;
1062void ListViewWithPageHeader::headerHeightChanged(qreal newHeaderHeight, qreal oldHeaderHeight, qreal oldHeaderY)
1064 const qreal heightDiff = newHeaderHeight - oldHeaderHeight;
1065 if (m_headerItemShownHeight > 0) {
1066 // If the header is shown because of the clip
1067 // Change its size
1068 m_headerItemShownHeight += heightDiff;
1069 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, newHeaderHeight);
1070 updateClipItem();
1071 adjustMinYExtent();
1072 } else {
1073 if (oldHeaderY + oldHeaderHeight > contentY()) {
1074 // If the header is shown because its position
1075 // Change its size
1076 ListItem *firstItem = m_visibleItems.first();
1077 firstItem->setY(firstItem->y() + heightDiff);
1078 layout();
1079 } else {
1080 // If the header is not on screen, just change the start of the list
1081 // so the viewport is not changed
1082 adjustMinYExtent();
1088void ListViewWithPageHeader::adjustMinYExtent()
1090 if (m_visibleItems.isEmpty()) {
1091 m_minYExtent = 0;
1092 } else {
1093 qreal nonCreatedHeight = 0;
1094 if (m_firstVisibleIndex != 0) {
1095 // Calculate the average height of items to estimate the position of the list start
1096 const int visibleItems = m_visibleItems.count();
1097 qreal visibleItemsHeight = 0;
1098 Q_FOREACH(ListItem *item, m_visibleItems) {
1099 visibleItemsHeight += item->height();
1101 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
1102// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
1104 m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->implicitHeight() : 0);
1108ListViewWithPageHeader::ListItem *ListViewWithPageHeader::itemAtIndex(int modelIndex) const
1110 const int visibleIndexedModelIndex = modelIndex - m_firstVisibleIndex;
1111 if (visibleIndexedModelIndex >= 0 && visibleIndexedModelIndex < m_visibleItems.count())
1112 return m_visibleItems[visibleIndexedModelIndex];
1114 return nullptr;
1117void ListViewWithPageHeader::layout()
1119 if (m_inLayout)
1120 return;
1122 m_inLayout = true;
1123 if (!m_visibleItems.isEmpty()) {
1124 const qreal visibleFrom = contentY() - m_clipItem->y() + m_headerItemShownHeight;
1125 const qreal visibleTo = contentY() + height() - m_clipItem->y();
1127 qreal pos = m_visibleItems.first()->y();
1129// qDebug() << "ListViewWithPageHeader::layout Updating positions and heights. contentY" << contentY() << "minYExtent" << minYExtent();
1130 int firstReallyVisibleItem = -1;
1131 int modelIndex = m_firstVisibleIndex;
1132 Q_FOREACH(ListItem *item, m_visibleItems) {
1133 const bool cull = pos + item->height() <= visibleFrom || pos >= visibleTo;
1134 item->setCulled(cull);
1135 item->setY(pos);
1136 if (!cull && firstReallyVisibleItem == -1) {
1137 firstReallyVisibleItem = modelIndex;
1138 if (m_topSectionItem) {
1139 // Positing the top section sticky item is a two step process
1140 // First we set it either we cull it (because it doesn't need to be sticked to the top)
1141 // or stick it to the top
1142 // Then after the loop we'll make sure that if there's another section just below it
1143 // pushed the sticky section up to make it disappear
1144 const qreal topSectionStickPos = m_headerItemShownHeight + contentY() - m_clipItem->y();
1145 bool showStickySectionItem;
1146 // We need to show the "top section sticky item" when the position at the "top" of the
1147 // viewport is bigger than the start of the position of the first visible item
1148 // i.e. the first visible item starts before the viewport, or when the first
1149 // visible item starts just at the viewport start and it does not have its own section item
1150 if (topSectionStickPos > pos) {
1151 showStickySectionItem = true;
1152 } else if (topSectionStickPos == pos) {
1153 showStickySectionItem = !item->m_sectionItem;
1154 } else {
1155 showStickySectionItem = false;
1157 if (!showStickySectionItem) {
1158 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
1159 if (item->m_sectionItem) {
1160 // This seems it should happen since why would we cull the top section
1161 // if the first visible item has no section header? This only happens briefly
1162 // when increasing the height of a list that is at the bottom, the m_topSectionItem
1163 // gets shown shortly in the next polish call
1164 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
1166 } else {
1167 // Update the top sticky section header
1168 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1169 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1170 context->setContextProperty(QLatin1String("section"), section);
1172 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1173 m_topSectionItem->setY(topSectionStickPos);
1174 int delegateIndex = modelIndex;
1175 // Look for the first index with this section text
1176 while (delegateIndex > 0) {
1177 const QString prevSection = m_delegateModel->stringValue(delegateIndex - 1, m_sectionProperty);
1178 if (prevSection != section)
1179 break;
1180 delegateIndex--;
1182 context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1183 if (item->m_sectionItem) {
1184 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1189 QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1190 const qreal clipFrom = visibleFrom + (!item->m_sectionItem && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1191 if (!cull && pos < clipFrom) {
1192 context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
1193 } else {
1194 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
1196// qDebug() << "ListViewWithPageHeader::layout" << item->m_item;
1197 pos += item->height();
1198 ++modelIndex;
1201 // Second step of section sticky item positioning
1202 // Look at the next section header, check if it's pushing up the sticky one
1203 if (m_topSectionItem) {
1204 if (firstReallyVisibleItem >= 0) {
1205 for (int i = firstReallyVisibleItem - m_firstVisibleIndex + 1; i < m_visibleItems.count(); ++i) {
1206 ListItem *item = m_visibleItems[i];
1207 if (item->m_sectionItem) {
1208 if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
1209 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
1211 break;
1217 m_inLayout = false;
1220void ListViewWithPageHeader::updatePolish()
1222 Q_FOREACH(ListItem *item, m_itemsToRelease)
1223 reallyReleaseItem(item);
1224 m_itemsToRelease.clear();
1226 if (!model())
1227 return;
1229 layout();
1231 refill();
1233 if (m_contentHeightDirty) {
1234 qreal contentHeight;
1235 if (m_visibleItems.isEmpty()) {
1236 contentHeight = m_headerItem ? m_headerItem->height() : 0;
1237 } else {
1238 const int modelCount = model()->rowCount();
1239 const int visibleItems = m_visibleItems.count();
1240 const int lastValidIndex = m_firstVisibleIndex + visibleItems - 1;
1241 qreal nonCreatedHeight = 0;
1242 if (lastValidIndex != modelCount - 1) {
1243 const int visibleItems = m_visibleItems.count();
1244 qreal visibleItemsHeight = 0;
1245 Q_FOREACH(ListItem *item, m_visibleItems) {
1246 visibleItemsHeight += item->height();
1248 const int unknownSizes = modelCount - (m_firstVisibleIndex + visibleItems);
1249 nonCreatedHeight = unknownSizes * visibleItemsHeight / visibleItems;
1251 ListItem *item = m_visibleItems.last();
1252 contentHeight = nonCreatedHeight + item->y() + item->height() + m_clipItem->y();
1253 if (m_firstVisibleIndex != 0) {
1254 // Make sure that if we are shrinking we tell the view we still fit
1255 m_minYExtent = qMax(m_minYExtent, -(contentHeight - height()));
1259 m_contentHeightDirty = false;
1260 adjustMinYExtent();
1261 setContentHeight(contentHeight);
1265#include "moc_listviewwithpageheader.cpp"