@@ -138,6 +138,13 @@ void ListViewWithPageHeader::ListItem::setCulled(bool culled)
138 QQuickItemPrivate::get(m_sectionItem)->setCulled(culled);
138 QQuickItemPrivate::get(m_sectionItem)->setCulled(culled);
141+void ListViewWithPageHeader::ListItem::setSectionItem(QQuickItem *sectionItem)
143+ m_sectionItem = sectionItem;
144+ QQmlContext *context = QQmlEngine::contextForObject(m_item)->parentContext();
145+ context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(sectionItem != nullptr));
141ListViewWithPageHeader::ListViewWithPageHeader()
148ListViewWithPageHeader::ListViewWithPageHeader()
142 : m_delegateModel(nullptr)
149 : m_delegateModel(nullptr)
143 , m_asyncRequestedIndex(-1)
150 , m_asyncRequestedIndex(-1)
@@ -424,7 +431,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(int modelIndex, int itemHeight)
425 ListItem *listItem = itemAtIndex(modelIndex);
432 ListItem *listItem = itemAtIndex(modelIndex);
426 if (listItem) {
433 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));
430 return false;
437 return false;
@@ -442,7 +449,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listIte
442 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
449 contentYAnimationType = ContentYAnimationMaximizeVisibleArea;
443 m_contentYAnimation->start();
450 m_contentYAnimation->start();
444 } else if ((listItemY < contentY() && listItemY + listItemHeight < contentY() + height()) ||
451 } 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()))
447 // we can scroll the list down to show more stuff
454 // we can scroll the list down to show more stuff
448 auto realVisibleListItemY = listItemY;
455 auto realVisibleListItemY = listItemY;
@@ -451,7 +458,7 @@ bool ListViewWithPageHeader::maximizeVisibleArea(ListItem *listItem, int listIte
451 // item we have to make sure to scroll it a bit more so that it is not underlapping
458 // item we have to make sure to scroll it a bit more so that it is not underlapping
452 // the top section sticky item
459 // the top section sticky item
453 bool topSectionShown = !QQuickItemPrivate::get(m_topSectionItem)->culled;
460 bool topSectionShown = !QQuickItemPrivate::get(m_topSectionItem)->culled;
454− if (topSectionShown && !listItem->m_sectionItem) {
461+ if (topSectionShown && !listItem->sectionItem()) {
455 realVisibleListItemY -= m_topSectionItem->height();
462 realVisibleListItemY -= m_topSectionItem->height();
@@ -651,7 +658,7 @@ void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
651 if (flags & QQmlDelegateModel::Destroyed) {
658 if (flags & QQmlDelegateModel::Destroyed) {
652 item->setParentItem(nullptr);
659 item->setParentItem(nullptr);
654− delete listItem->m_sectionItem;
661+ delete listItem->sectionItem();
655 delete listItem;
662 delete listItem;
@@ -678,6 +685,9 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
678 return nullptr;
685 return nullptr;
680 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
687 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
688+ if (section.isEmpty())
681 if (modelIndex > 0) {
691 if (modelIndex > 0) {
682 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
692 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
683 if (section == prevSection)
693 if (section == prevSection)
@@ -690,8 +700,8 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
690 // Steal the section header
700 // Steal the section header
691 ListItem *nextItem = itemAtIndex(modelIndex); // Not +1 since not yet inserted into m_visibleItems
701 ListItem *nextItem = itemAtIndex(modelIndex); // Not +1 since not yet inserted into m_visibleItems
692 if (nextItem) {
702 if (nextItem) {
693− QQuickItem *sectionItem = nextItem->m_sectionItem;
703+ QQuickItem *sectionItem = nextItem->sectionItem();
694− nextItem->m_sectionItem = nullptr;
704+ nextItem->setSectionItem(nullptr);
695 return sectionItem;
705 return sectionItem;
@@ -799,7 +809,7 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
799// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
809// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
800 ListItem *listItem = new ListItem;
810 ListItem *listItem = new ListItem;
801 listItem->m_item = item;
811 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*/));
803 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
813 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
804 ListItem *prevItem = itemAtIndex(modelIndex - 1);
814 ListItem *prevItem = itemAtIndex(modelIndex - 1);
805 bool lostItem = false; // Is an item that we requested async but because of model changes
815 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
838 m_firstVisibleIndex = modelIndex;
848 m_firstVisibleIndex = modelIndex;
839 polish();
849 polish();
841− if (listItem->m_sectionItem) {
851+ if (listItem->sectionItem()) {
842− QQmlContext *context = QQmlEngine::contextForObject(listItem->m_sectionItem)->parentContext();
852+ QQmlContext *context = QQmlEngine::contextForObject(listItem->sectionItem())->parentContext();
843 context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
853 context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
845 adjustMinYExtent();
855 adjustMinYExtent();
@@ -867,6 +877,7 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
867 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
877 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
868 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
878 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
869 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
879 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
880+ context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(false));
870 if (modelIndex == m_asyncRequestedIndex) {
881 if (modelIndex == m_asyncRequestedIndex) {
871 createItem(modelIndex, false);
882 createItem(modelIndex, false);
872 refill();
883 refill();
@@ -921,11 +932,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
921 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
932 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
922 ListItem *item = m_visibleItems[visibleIndex];
933 ListItem *item = m_visibleItems[visibleIndex];
923 // Pass the section item down if needed
934 // 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()) {
925 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
936 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
926− if (!nextItem->m_sectionItem) {
937+ if (!nextItem->sectionItem()) {
927− nextItem->m_sectionItem = item->m_sectionItem;
938+ nextItem->setSectionItem(item->sectionItem());
928− item->m_sectionItem = nullptr;
939+ item->setSectionItem(nullptr);
931 releaseItem(item);
942 releaseItem(item);
@@ -988,11 +999,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
988 // if we need adding a new section item
999 // if we need adding a new section item
989 if (m_sectionDelegate) {
1000 if (m_sectionDelegate) {
990 ListItem *nextItem = itemAtIndex(modelIndex + 1);
1001 ListItem *nextItem = itemAtIndex(modelIndex + 1);
991− if (nextItem && !nextItem->m_sectionItem) {
1002+ if (nextItem && !nextItem->sectionItem()) {
992− nextItem->m_sectionItem = getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/);
1003+ nextItem->setSectionItem(getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/));
993− if (growUp && nextItem->m_sectionItem) {
1004+ if (growUp && nextItem->sectionItem()) {
994 ListItem *firstItem = m_visibleItems.first();
1005 ListItem *firstItem = m_visibleItems.first();
995− firstItem->setY(firstItem->y() - nextItem->m_sectionItem->height());
1006+ firstItem->setY(firstItem->y() - nextItem->sectionItem()->height());
@@ -1018,8 +1029,8 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
1018// qDebug() << "ListViewWithPageHeader::onModelUpdated Change" << change.index << change.count;
1029// qDebug() << "ListViewWithPageHeader::onModelUpdated Change" << change.index << change.count;
1019 for (int i = change.index; i < change.count; ++i) {
1030 for (int i = change.index; i < change.count; ++i) {
1020 ListItem *item = itemAtIndex(i);
1031 ListItem *item = itemAtIndex(i);
1021− if (item && item->m_sectionItem) {
1032+ if (item && item->sectionItem()) {
1022− QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1033+ QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
1023 const QString sectionText = m_delegateModel->stringValue(i, m_sectionProperty);
1034 const QString sectionText = m_delegateModel->stringValue(i, m_sectionProperty);
1024 context->setContextProperty(QLatin1String("section"), sectionText);
1035 context->setContextProperty(QLatin1String("section"), sectionText);
@@ -1032,8 +1043,8 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
1033 for (int i = 0; i < m_visibleItems.count(); ++i) {
1044 for (int i = 0; i < m_visibleItems.count(); ++i) {
1034 ListItem *item = m_visibleItems[i];
1045 ListItem *item = m_visibleItems[i];
1035− if (item->m_sectionItem) {
1046+ if (item->sectionItem()) {
1036− QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1047+ QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
1037 context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
1048 context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
@@ -1176,18 +1187,18 @@ void ListViewWithPageHeader::layout()
1176 if (topSectionStickPos > pos) {
1187 if (topSectionStickPos > pos) {
1177 showStickySectionItem = true;
1188 showStickySectionItem = true;
1178 } else if (topSectionStickPos == pos) {
1189 } else if (topSectionStickPos == pos) {
1179− showStickySectionItem = !item->m_sectionItem;
1190+ showStickySectionItem = !item->sectionItem();
1180 } else {
1191 } else {
1181 showStickySectionItem = false;
1192 showStickySectionItem = false;
1183 if (!showStickySectionItem) {
1194 if (!showStickySectionItem) {
1184 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
1195 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
1185− if (item->m_sectionItem) {
1196+ if (item->sectionItem()) {
1186 // This seems it should happen since why would we cull the top section
1197 // This seems it should happen since why would we cull the top section
1187 // if the first visible item has no section header? This only happens briefly
1198 // if the first visible item has no section header? This only happens briefly
1188 // when increasing the height of a list that is at the bottom, the m_topSectionItem
1199 // when increasing the height of a list that is at the bottom, the m_topSectionItem
1189 // gets shown shortly in the next polish call
1200 // gets shown shortly in the next polish call
1190− QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
1201+ QQuickItemPrivate::get(item->sectionItem())->setCulled(false);
1192 } else {
1203 } else {
1193 // Update the top sticky section header
1204 // Update the top sticky section header
@@ -1206,14 +1217,14 @@ void ListViewWithPageHeader::layout()
1206 delegateIndex--;
1217 delegateIndex--;
1208 context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1219 context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1209− if (item->m_sectionItem) {
1220+ if (item->sectionItem()) {
1210− QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1221+ QQuickItemPrivate::get(item->sectionItem())->setCulled(true);
1215 QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1226 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);
1217 if (!cull && pos < clipFrom) {
1228 if (!cull && pos < clipFrom) {
1218 context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
1229 context->setContextProperty(QLatin1String("heightToClip"), clipFrom - pos);
1219 } else {
1230 } else {
@@ -1230,7 +1241,7 @@ void ListViewWithPageHeader::layout()
1230 if (firstReallyVisibleItem >= 0) {
1241 if (firstReallyVisibleItem >= 0) {
1231 for (int i = firstReallyVisibleItem - m_firstVisibleIndex + 1; i < m_visibleItems.count(); ++i) {
1242 for (int i = firstReallyVisibleItem - m_firstVisibleIndex + 1; i < m_visibleItems.count(); ++i) {
1232 ListItem *item = m_visibleItems[i];
1243 ListItem *item = m_visibleItems[i];
1233− if (item->m_sectionItem) {
1244+ if (item->sectionItem()) {
1234 if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
1245 if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
1235 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
1246 m_topSectionItem->setY(item->y() - m_topSectionItem->height());