@@ -138,6 +138,13 @@ void ListViewWithPageHeader::ListItem::setCulled(bool culled)
138138 QQuickItemPrivate::get(m_sectionItem)->setCulled(culled);
139139}
140140
141+void ListViewWithPageHeader::ListItem::setSectionItem(QQuickItem *sectionItem)
142+{
143+ m_sectionItem = sectionItem;
144+ QQmlContext *context = QQmlEngine::contextForObject(m_item)->parentContext();
145+ context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(sectionItem != nullptr));
146+}
147+
141148ListViewWithPageHeader::ListViewWithPageHeader()
142149 : m_delegateModel(nullptr)
143150 , m_asyncRequestedIndex(-1)
@@ -424,7 +431,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex, int itemHeight)
424431
425432 ListItem *listItem = itemAtIndex(modelIndex);
426433 if (listItem) {
427− return maximizeVisibleArea(listItem, itemHeight + (listItem->m_sectionItem ? listItem->m_sectionItem->height() : 0));
434+ return maximizeVisibleArea(listItem, itemHeight + (listItem->sectionItem() ? listItem->sectionItem()->height() : 0));
428435 }
429436
430437 return false;
@@ -442,7 +449,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listIte
442449 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
443450 m_contentYAnimation->start();
444451 } else if ((listItemY < contentY() && listItemY + listItemHeight < contentY() + height()) ||
445− (m_topSectionItem && !listItem->m_sectionItem && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItemHeight < contentY() + height()))
452+ (m_topSectionItem && !listItem->sectionItem() && listItemY - m_topSectionItem->height() < contentY() && listItemY + listItemHeight < contentY() + height()))
446453 {
447454 // we can scroll the list down to show more stuff
448455 auto realVisibleListItemY = listItemY;
@@ -451,7 +458,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listIte
451458 // item we have to make sure to scroll it a bit more so that it is not underlapping
452459 // the top section sticky item
453460 bool topSectionShown = !QQuickItemPrivate::get(m_topSectionItem)->culled;
454− if (topSectionShown && !listItem->m_sectionItem) {
461+ if (topSectionShown && !listItem->sectionItem()) {
455462 realVisibleListItemY -= m_topSectionItem->height();
456463 }
457464 }
@@ -651,7 +658,7 @@ void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
651658 if (flags & QQmlDelegateModel::Destroyed) {
652659 item->setParentItem(nullptr);
653660 }
654− delete listItem->m_sectionItem;
661+ delete listItem->sectionItem();
655662 delete listItem;
656663}
657664
@@ -678,6 +685,9 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
678685 return nullptr;
679686
680687 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
688+ if (section.isEmpty())
689+ return nullptr;
690+
681691 if (modelIndex > 0) {
682692 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
683693 if (section == prevSection)
@@ -690,8 +700,8 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
690700 // Steal the section header
691701 ListItem *nextItem = itemAtIndex(modelIndex); // Not +1 since not yet inserted into m_visibleItems
692702 if (nextItem) {
693− QQuickItem *sectionItem = nextItem->m_sectionItem;
694− nextItem->m_sectionItem = nullptr;
703+ QQuickItem *sectionItem = nextItem->sectionItem();
704+ nextItem->setSectionItem(nullptr);
695705 return sectionItem;
696706 }
697707 }
@@ -799,7 +809,7 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
799809// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
800810 ListItem *listItem = new ListItem;
801811 listItem->m_item = item;
802− listItem->m_sectionItem = getSectionItem(modelIndex, false /*Not yet inserted into m_visibleItems*/);
812+ listItem->setSectionItem(getSectionItem(modelIndex, false /*Not yet inserted into m_visibleItems*/));
803813 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
804814 ListItem *prevItem = itemAtIndex(modelIndex - 1);
805815 bool lostItem = false; // Is an item that we requested async but because of model changes
@@ -838,8 +848,8 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
838848 m_firstVisibleIndex = modelIndex;
839849 polish();
840850 }
841− if (listItem->m_sectionItem) {
842− QQmlContext *context = QQmlEngine::contextForObject(listItem->m_sectionItem)->parentContext();
851+ if (listItem->sectionItem()) {
852+ QQmlContext *context = QQmlEngine::contextForObject(listItem->sectionItem())->parentContext();
843853 context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
844854 }
845855 adjustMinYExtent();
@@ -867,6 +877,7 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
867877 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
868878 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
869879 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
880+ context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(false));
870881 if (modelIndex == m_asyncRequestedIndex) {
871882 createItem(modelIndex, false);
872883 refill();
@@ -921,11 +932,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
921932 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
922933 ListItem *item = m_visibleItems[visibleIndex];
923934 // Pass the section item down if needed
924− if (item->m_sectionItem && visibleIndex + 1 < m_visibleItems.count()) {
935+ if (item->sectionItem() && visibleIndex + 1 < m_visibleItems.count()) {
925936 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
926− if (!nextItem->m_sectionItem) {
927− nextItem->m_sectionItem = item->m_sectionItem;
928− item->m_sectionItem = nullptr;
937+ if (!nextItem->sectionItem()) {
938+ nextItem->setSectionItem(item->sectionItem());
939+ item->setSectionItem(nullptr);
929940 }
930941 }
931942 releaseItem(item);
@@ -988,11 +999,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
988999 // if we need adding a new section item
9891000 if (m_sectionDelegate) {
9901001 ListItem *nextItem = itemAtIndex(modelIndex + 1);
991− if (nextItem && !nextItem->m_sectionItem) {
992− nextItem->m_sectionItem = getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/);
993− if (growUp && nextItem->m_sectionItem) {
1002+ if (nextItem && !nextItem->sectionItem()) {
1003+ nextItem->setSectionItem(getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/));
1004+ if (growUp && nextItem->sectionItem()) {
9941005 ListItem *firstItem = m_visibleItems.first();
995− firstItem->setY(firstItem->y() - nextItem->m_sectionItem->height());
1006+ firstItem->setY(firstItem->y() - nextItem->sectionItem()->height());
9961007 }
9971008 }
9981009 }
@@ -1018,8 +1029,8 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
10181029// qDebug() << "ListViewWithPageHeader::onModelUpdated Change" << change.index << change.count;
10191030 for (int i = change.index; i < change.count; ++i) {
10201031 ListItem *item = itemAtIndex(i);
1021− if (item && item->m_sectionItem) {
1022− QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1032+ if (item && item->sectionItem()) {
1033+ QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
10231034 const QString sectionText = m_delegateModel->stringValue(i, m_sectionProperty);
10241035 context->setContextProperty(QLatin1String("section"), sectionText);
10251036 }
@@ -1032,8 +1043,8 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
10321043
10331044 for (int i = 0; i < m_visibleItems.count(); ++i) {
10341045 ListItem *item = m_visibleItems[i];
1035− if (item->m_sectionItem) {
1036− QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1046+ if (item->sectionItem()) {
1047+ QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
10371048 context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
10381049 }
10391050 }
@@ -1176,18 +1187,18 @@ void ListViewWithPageHeader::layout()
11761187 if (topSectionStickPos > pos) {
11771188 showStickySectionItem = true;
11781189 } else if (topSectionStickPos == pos) {
1179− showStickySectionItem = !item->m_sectionItem;
1190+ showStickySectionItem = !item->sectionItem();
11801191 } else {
11811192 showStickySectionItem = false;
11821193 }
11831194 if (!showStickySectionItem) {
11841195 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
1185− if (item->m_sectionItem) {
1196+ if (item->sectionItem()) {
11861197 // This seems it should happen since why would we cull the top section
11871198 // if the first visible item has no section header? This only happens briefly
11881199 // when increasing the height of a list that is at the bottom, the m_topSectionItem
11891200 // gets shown shortly in the next polish call
1190− QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
1201+ QQuickItemPrivate::get(item->sectionItem())->setCulled(false);
11911202 }
11921203 } else {
11931204 // Update the top sticky section header
@@ -1206,14 +1217,14 @@ void ListViewWithPageHeader::layout()
12061217 delegateIndex--;
12071218 }
12081219 context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1209− if (item->m_sectionItem) {
1210− QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1220+ if (item->sectionItem()) {
1221+ QQuickItemPrivate::get(item->sectionItem())->setCulled(true);
12111222 }
12121223 }
12131224 }
12141225 }
12151226 QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1216− const qreal clipFrom = visibleFrom + (!item->m_sectionItem && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1227+ const qreal clipFrom = visibleFrom + (!item->sectionItem() && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
12171228 if (!cull && pos < clipFrom) {
12181229 context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
12191230 } else {
@@ -1230,7 +1241,7 @@ void ListViewWithPageHeader::layout()
12301241 if (firstReallyVisibleItem >= 0) {
12311242 for (int i = firstReallyVisibleItem - m_firstVisibleIndex + 1; i < m_visibleItems.count(); ++i) {
12321243 ListItem *item = m_visibleItems[i];
1233− if (item->m_sectionItem) {
1244+ if (item->sectionItem()) {
12341245 if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
12351246 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
12361247 }