on xenial help sign in
sectionDelegates get the delegateIndex first as -1 and then to the correct value
f580988Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+4−4
@@ -280,7 +280,7 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
280
280
281 m_sectionDelegate = delegate;
281 m_sectionDelegate = delegate;
282
282
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);
286
286
@@ -651,17 +651,17 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
651 }
651 }
652 }
652 }
653
653
654− return getSectionItem(modelIndex, section);
654+ return getSectionItem(section);
655}
655}
656
656
657−QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, const QString &sectionText)
657+QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText)
658{
658{
659 QQuickItem *sectionItem = nullptr;
659 QQuickItem *sectionItem = nullptr;
660
660
661 QQmlContext *creationContext = m_sectionDelegate->creationContext();
661 QQmlContext *creationContext = m_sectionDelegate->creationContext();
662 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
662 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
663 context->setContextProperty(QLatin1String("section"), sectionText);
663 context->setContextProperty(QLatin1String("section"), sectionText);
664− context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
664+ context->setContextProperty(QLatin1String("delegateIndex"), -1);
665 QObject *nobj = m_sectionDelegate->beginCreate(context);
665 QObject *nobj = m_sectionDelegate->beginCreate(context);
666 if (nobj) {
666 if (nobj) {
667 QQml_setParent_noEvent(context, nobj);
667 QQml_setParent_noEvent(context, nobj);
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1−1
@@ -158,7 +158,7 @@ private:
158 void reallyReleaseItem(ListItem *item);
158 void reallyReleaseItem(ListItem *item);
159 void updateWatchedRoles();
159 void updateWatchedRoles();
160 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
160 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
161− QQuickItem *getSectionItem(int modelIndex, const QString &sectionText);
161+ QQuickItem *getSectionItem(const QString &sectionText);
162
162
163#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
163#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
164 QQuickVisualDataModel *m_delegateModel;
164 QQuickVisualDataModel *m_delegateModel;