@@ -280,7 +280,7 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
281 m_sectionDelegate = delegate;
281 m_sectionDelegate = delegate;
283− m_topSectionItem = getSectionItem(-1, QString());
283+ m_topSectionItem = getSectionItem(QString());
284 m_topSectionItem->setZ(3);
284 m_topSectionItem->setZ(3);
285 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
285 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
@@ -380,20 +380,51 @@ void ListViewWithPageHeader::showHeader()
383+QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
385+ ListItem *item = itemAtIndex(modelIndex);
387+ return item->m_item;
383bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
392bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
385 ListItem *listItem = itemAtIndex(modelIndex);
394 ListItem *listItem = itemAtIndex(modelIndex);
386− if (listItem)
395+ if (listItem) {
387− {
396+ return maximizeVisibleArea(listItem, listItem->height());
402+bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex, int itemHeight)
407+ ListItem *listItem = itemAtIndex(modelIndex);
409+ return maximizeVisibleArea(listItem, itemHeight + (listItem->m_sectionItem ? listItem->m_sectionItem->height() : 0));
415+bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listItemHeight)
388 const auto listItemY = m_clipItem->y() + listItem->y();
419 const auto listItemY = m_clipItem->y() + listItem->y();
389− if (listItemY > contentY() && listItemY + listItem->height() > contentY() + height()) {
420+ if (listItemY > contentY() && listItemY + listItemHeight > contentY() + height()) {
390 // we can scroll the list up to show more stuff
421 // we can scroll the list up to show more stuff
391− const auto to = qMin(listItemY, listItemY + listItem->height() - height());
422+ const auto to = qMin(listItemY, listItemY + listItemHeight - height());
392 m_contentYAnimation->setTo(to);
423 m_contentYAnimation->setTo(to);
393 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
424 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
394 m_contentYAnimation->start();
425 m_contentYAnimation->start();
395− } else if ((listItemY < contentY() && listItemY + listItem->height() < contentY() + height()) ||
426+ } else if ((listItemY < contentY() && listItemY + listItemHeight < contentY() + height()) ||
396− (m_topSectionItem && !listItem->m_sectionItem && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItem->height() < contentY() + height()))
427+ (m_topSectionItem && !listItem->m_sectionItem && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItemHeight < contentY() + height()))
398 // we can scroll the list down to show more stuff
429 // we can scroll the list down to show more stuff
399 auto realVisibleListItemY = listItemY;
430 auto realVisibleListItemY = listItemY;
@@ -406,7 +437,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
406 realVisibleListItemY -= m_topSectionItem->height();
437 realVisibleListItemY -= m_topSectionItem->height();
409− const auto to = qMax(realVisibleListItemY, listItemY + listItem->height() - height());
440+ const auto to = qMax(realVisibleListItemY, listItemY + listItemHeight - height());
410 m_contentYAnimation->setTo(to);
441 m_contentYAnimation->setTo(to);
411 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
442 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
412 m_contentYAnimation->start();
443 m_contentYAnimation->start();
@@ -641,17 +672,17 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
644− return getSectionItem(modelIndex, section);
675+ return getSectionItem(section);
647−QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, const QString §ionText)
678+QQuickItem *ListViewWithPageHeader::getSectionItem(const QString §ionText)
649 QQuickItem *sectionItem = nullptr;
680 QQuickItem *sectionItem = nullptr;
651 QQmlContext *creationContext = m_sectionDelegate->creationContext();
682 QQmlContext *creationContext = m_sectionDelegate->creationContext();
652 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
683 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
653 context->setContextProperty(QLatin1String("section"), sectionText);
684 context->setContextProperty(QLatin1String("section"), sectionText);
654− context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
685+ context->setContextProperty(QLatin1String("delegateIndex"), -1);
655 QObject *nobj = m_sectionDelegate->beginCreate(context);
686 QObject *nobj = m_sectionDelegate->beginCreate(context);
656 if (nobj) {
687 if (nobj) {
657 QQml_setParent_noEvent(context, nobj);
688 QQml_setParent_noEvent(context, nobj);
@@ -786,6 +817,10 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
786 m_firstVisibleIndex = modelIndex;
817 m_firstVisibleIndex = modelIndex;
787 polish();
818 polish();
820+ if (listItem->m_sectionItem) {
821+ QQmlContext *context = QQmlEngine::contextForObject(listItem->m_sectionItem)->parentContext();
822+ context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
789 adjustMinYExtent();
824 adjustMinYExtent();
790 m_contentHeightDirty = true;
825 m_contentHeightDirty = true;