on xenial help sign in
Make LVWPH provide a delegateIndex for sectionHeaders
1fbfcd7Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+21−3
@@ -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(QString());
283+ m_topSectionItem = getSectionItem(-1, 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
@@ -599,16 +599,17 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
599 }
599 }
600 }
600 }
601
601
602− return getSectionItem(section);
602+ return getSectionItem(modelIndex, section);
603}
603}
604
604
605−QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText)
605+QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, const QString &sectionText)
606{
606{
607 QQuickItem *sectionItem = nullptr;
607 QQuickItem *sectionItem = nullptr;
608
608
609 QQmlContext *creationContext = m_sectionDelegate->creationContext();
609 QQmlContext *creationContext = m_sectionDelegate->creationContext();
610 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
610 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
611 context->setContextProperty(QLatin1String("section"), sectionText);
611 context->setContextProperty(QLatin1String("section"), sectionText);
612+ context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
612 QObject *nobj = m_sectionDelegate->beginCreate(context);
613 QObject *nobj = m_sectionDelegate->beginCreate(context);
613 if (nobj) {
614 if (nobj) {
614 QQml_setParent_noEvent(context, nobj);
615 QQml_setParent_noEvent(context, nobj);
@@ -932,6 +933,14 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
932 adjustMinYExtent();
933 adjustMinYExtent();
933 }
934 }
934
935
936+ for (int i = 0; i < m_visibleItems.count(); ++i) {
937+ ListItem *item = m_visibleItems[i];
938+ if (item->m_sectionItem) {
939+ QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
940+ context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
941+ }
942+ }
943+
935 layout();
944 layout();
936 polish();
945 polish();
937 m_contentHeightDirty = true;
946 m_contentHeightDirty = true;
@@ -1060,6 +1069,15 @@ void ListViewWithPageHeader::layout()
1060
1069
1061 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1070 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1062 m_topSectionItem->setY(topSectionStickPos);
1071 m_topSectionItem->setY(topSectionStickPos);
1072+ int delegateIndex = modelIndex;
1073+ // Look for the first index with this section text
1074+ while (delegateIndex > 0) {
1075+ const QString prevSection = m_delegateModel->stringValue(delegateIndex - 1, m_sectionProperty);
1076+ if (prevSection != section)
1077+ break;
1078+ delegateIndex--;
1079+ }
1080+ context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1063 if (item->m_sectionItem) {
1081 if (item->m_sectionItem) {
1064 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1082 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1065 }
1083 }
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1−1
@@ -152,7 +152,7 @@ private:
152 void reallyReleaseItem(ListItem *item);
152 void reallyReleaseItem(ListItem *item);
153 void updateWatchedRoles();
153 void updateWatchedRoles();
154 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
154 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
155− QQuickItem *getSectionItem(const QString &sectionText);
155+ QQuickItem *getSectionItem(int modelIndex, const QString &sectionText);
156
156
157#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
157#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
158 QQuickVisualDataModel *m_delegateModel;
158 QQuickVisualDataModel *m_delegateModel;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+51−2
@@ -45,6 +45,7 @@ private:
45 QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), sectionHeader);
45 QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), sectionHeader);
46 if (!sectionHeader.isNull()) {
46 if (!sectionHeader.isNull()) {
47 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_sectionItem)->culled, sectionHeaderCulled);
47 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_sectionItem)->culled, sectionHeaderCulled);
48+ QCOMPARE(sectionDelegateIndex(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), lvwph->m_firstVisibleIndex + visibleIndex);
48 }
49 }
49 }
50 }
50
51
@@ -116,6 +117,11 @@ private:
116 return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
117 return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
117 }
118 }
118
119
120+ int sectionDelegateIndex(QQuickItem *item)
121+ {
122+ return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("delegateIndex")).toInt() : -1;
123+ }
124+
119private Q_SLOTS:
125private Q_SLOTS:
120
126
121 void initTestCase()
127 void initTestCase()
@@ -220,6 +226,7 @@ private Q_SLOTS:
220 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
226 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
221 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
227 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
222 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
228 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
229+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
223 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
230 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
224 }
231 }
225
232
@@ -241,6 +248,7 @@ private Q_SLOTS:
241 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
248 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
242 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
249 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
243 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
250 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
251+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
244 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
252 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
245 }
253 }
246
254
@@ -262,6 +270,7 @@ private Q_SLOTS:
262 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
270 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
263 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
271 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
264 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
272 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
273+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
265 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
274 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
266
275
267 changeContentY(-30);
276 changeContentY(-30);
@@ -280,6 +289,7 @@ private Q_SLOTS:
280 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
289 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
281 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
290 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
282 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
291 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
292+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
283 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
293 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
284 }
294 }
285
295
@@ -335,6 +345,7 @@ private Q_SLOTS:
335 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
345 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
336 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
346 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
337 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
347 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
348+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
338 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
349 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
339
350
340 lvwph->positionAtBeginning();
351 lvwph->positionAtBeginning();
@@ -360,6 +371,7 @@ private Q_SLOTS:
360 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
371 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
361 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
372 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
362 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
373 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
374+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
363 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
375 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
364
376
365 lvwph->positionAtBeginning();
377 lvwph->positionAtBeginning();
@@ -404,6 +416,7 @@ private Q_SLOTS:
404 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
416 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
405 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
417 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
406 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
418 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
419+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
407 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
420 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
408
421
409 model->setProperty(0, "size", 400);
422 model->setProperty(0, "size", 400);
@@ -423,6 +436,7 @@ private Q_SLOTS:
423 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
436 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
424 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
437 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
425 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
438 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
439+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
426 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
440 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
427
441
428 scrollToTop();
442 scrollToTop();
@@ -476,6 +490,7 @@ private Q_SLOTS:
476 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
490 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
477 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
491 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
478 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
492 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
493+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
479 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
494 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
480
495
481 model->setProperty(0, "size", 400);
496 model->setProperty(0, "size", 400);
@@ -495,6 +510,7 @@ private Q_SLOTS:
495 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
510 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
496 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
511 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
497 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
512 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
513+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
498 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
514 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
499
515
500 scrollToTop();
516 scrollToTop();
@@ -531,6 +547,7 @@ private Q_SLOTS:
531 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
547 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
532 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
548 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
533 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
549 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
550+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
534 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
551 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
535
552
536 changeContentY(-30);
553 changeContentY(-30);
@@ -548,6 +565,7 @@ private Q_SLOTS:
548 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
565 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
549 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
566 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
550 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
567 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
568+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
551 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
569 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
552
570
553 changeContentY(30);
571 changeContentY(30);
@@ -565,6 +583,7 @@ private Q_SLOTS:
565 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
583 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
566 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
584 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
567 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
585 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
586+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
568 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
587 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
569
588
570 changeContentY(-30);
589 changeContentY(-30);
@@ -582,6 +601,7 @@ private Q_SLOTS:
582 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
601 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
583 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
602 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
584 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
603 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
604+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
585 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
605 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
586 }
606 }
587
607
@@ -602,6 +622,7 @@ private Q_SLOTS:
602 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
622 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
603 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
623 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
604 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
624 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
625+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
605 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
626 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
606
627
607 lvwph->setDelegate(otherDelegate);
628 lvwph->setDelegate(otherDelegate);
@@ -660,6 +681,7 @@ private Q_SLOTS:
660 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
681 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
661 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
682 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
662 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
683 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
684+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
663 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
685 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
664
686
665 scrollToTop();
687 scrollToTop();
@@ -698,6 +720,7 @@ private Q_SLOTS:
698 QTRY_VERIFY(lvwph->isAtYEnd());
720 QTRY_VERIFY(lvwph->isAtYEnd());
699 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
721 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
700 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
722 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
723+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
701 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
724 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
702
725
703 scrollToTop();
726 scrollToTop();
@@ -734,6 +757,7 @@ private Q_SLOTS:
734 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
757 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
735 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
758 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
736 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
759 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
760+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
737 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
761 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
738 }
762 }
739
763
@@ -818,6 +842,7 @@ private Q_SLOTS:
818 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
842 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
819 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
843 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
820 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
844 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
845+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
821 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
846 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
822
847
823 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
848 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -838,6 +863,7 @@ private Q_SLOTS:
838 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
863 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
839 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
864 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
840 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
865 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
866+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
841 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
867 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
842
868
843 scrollToTop();
869 scrollToTop();
@@ -878,6 +904,7 @@ private Q_SLOTS:
878 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
904 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
879 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
905 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
880 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
906 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
907+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
881 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
908 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
882
909
883 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 3), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
910 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 3), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -898,6 +925,7 @@ private Q_SLOTS:
898 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
925 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
899 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
926 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
900 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
927 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
928+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
901 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
929 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
902 }
930 }
903
931
@@ -920,6 +948,7 @@ private Q_SLOTS:
920 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
948 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
921 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
949 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
922 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
950 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
951+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
923 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
952 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
924
953
925 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
954 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -940,6 +969,7 @@ private Q_SLOTS:
940 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
969 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
941 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
970 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
942 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
971 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
972+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
943 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
973 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
944 }
974 }
945
975
@@ -962,6 +992,7 @@ private Q_SLOTS:
962 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
992 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
963 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
993 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
964 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
994 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
995+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
965 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
996 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
966
997
967 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
998 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -982,6 +1013,7 @@ private Q_SLOTS:
982 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1013 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
983 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1014 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
984 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1015 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1016+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
985 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1017 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
986
1018
987 scrollToTop();
1019 scrollToTop();
@@ -1029,6 +1061,7 @@ private Q_SLOTS:
1029 QVERIFY(!lvwph->isAtYEnd());
1061 QVERIFY(!lvwph->isAtYEnd());
1030 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1062 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1031 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1063 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1064+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
1032 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1065 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1033
1066
1034 scrollToBottom();
1067 scrollToBottom();
@@ -1049,6 +1082,7 @@ private Q_SLOTS:
1049 QVERIFY(lvwph->isAtYEnd());
1082 QVERIFY(lvwph->isAtYEnd());
1050 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1083 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1051 QCOMPARE(section(lvwph->m_topSectionItem), QString("Lazy"));
1084 QCOMPARE(section(lvwph->m_topSectionItem), QString("Lazy"));
1085+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 5);
1052 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1086 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1053 }
1087 }
1054
1088
@@ -1102,6 +1136,7 @@ private Q_SLOTS:
1102 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1136 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1103 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1137 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1104 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1138 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1139+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 13);
1105 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1140 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1106
1141
1107 changeContentY(-1700);
1142 changeContentY(-1700);
@@ -1126,6 +1161,7 @@ private Q_SLOTS:
1126 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1161 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1127 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1162 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1128 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1163 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1164+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
1129 QCOMPARE(lvwph->m_topSectionItem->y(), -23.);
1165 QCOMPARE(lvwph->m_topSectionItem->y(), -23.);
1130 }
1166 }
1131
1167
@@ -1187,6 +1223,7 @@ private Q_SLOTS:
1187 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1223 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1188 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1224 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1189 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1225 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1226+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1190 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1227 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1191 }
1228 }
1192
1229
@@ -1210,6 +1247,7 @@ private Q_SLOTS:
1210 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1247 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1211 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1248 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1212 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1249 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1250+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1213 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1251 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1214 }
1252 }
1215
1253
@@ -1232,6 +1270,7 @@ private Q_SLOTS:
1232 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1270 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1233 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1271 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1234 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1272 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1273+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1235 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1274 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1236
1275
1237 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 1), Q_ARG(QVariant, 1));
1276 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 1), Q_ARG(QVariant, 1));
@@ -1251,6 +1290,7 @@ private Q_SLOTS:
1251 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1290 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1252 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1291 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1253 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1292 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1293+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1254 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1294 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1255 }
1295 }
1256
1296
@@ -1273,6 +1313,7 @@ private Q_SLOTS:
1273 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1313 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1274 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1314 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1275 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1315 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1316+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1276 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1317 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1277
1318
1278 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 3), Q_ARG(QVariant, 1));
1319 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 3), Q_ARG(QVariant, 1));
@@ -1292,6 +1333,7 @@ private Q_SLOTS:
1292 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1333 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1293 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1334 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1294 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1335 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1336+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1295 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1337 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1296 }
1338 }
1297
1339
@@ -1371,6 +1413,7 @@ private Q_SLOTS:
1371 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1413 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1372 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1414 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1373 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1415 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1416+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
1374 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1417 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1375
1418
1376 QMetaObject::invokeMethod(model, "moveItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 5), Q_ARG(QVariant, 1));
1419 QMetaObject::invokeMethod(model, "moveItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 5), Q_ARG(QVariant, 1));
@@ -1391,6 +1434,7 @@ private Q_SLOTS:
1391 QVERIFY(!lvwph->isAtYEnd());
1434 QVERIFY(!lvwph->isAtYEnd());
1392 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1435 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1393 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1436 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1437+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1394 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1438 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1395 }
1439 }
1396
1440
@@ -1414,6 +1458,7 @@ private Q_SLOTS:
1414 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1458 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1415 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1459 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1416 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1460 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1461+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1417 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1462 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1418
1463
1419 model->setProperty(1, "size", 100);
1464 model->setProperty(1, "size", 100);
@@ -1434,6 +1479,7 @@ private Q_SLOTS:
1434 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1479 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1435 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1480 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1436 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1481 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1482+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1437 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1483 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1438 }
1484 }
1439
1485
@@ -1455,7 +1501,7 @@ private Q_SLOTS:
1455 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1501 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1456 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1502 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1457 QCOMPARE(lvwph->contentY(), 20.);
1503 QCOMPARE(lvwph->contentY(), 20.);
1458− QCOMPARE(lvwph->m_headerItemShownHeight, 0.);;
1504+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1459 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1505 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1460
1506
1461 lvwph->showHeader();
1507 lvwph->showHeader();
@@ -1475,6 +1521,7 @@ private Q_SLOTS:
1475 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1521 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1476 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1522 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1477 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
1523 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
1524+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
1478 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1525 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1479
1526
1480 scrollToTop();
1527 scrollToTop();
@@ -1510,9 +1557,10 @@ private Q_SLOTS:
1510 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1557 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1511 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1558 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1512 QCOMPARE(lvwph->contentY(), 375.);
1559 QCOMPARE(lvwph->contentY(), 375.);
1513− QCOMPARE(lvwph->m_headerItemShownHeight, 0.);;
1560+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1514 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1561 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1515 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1562 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1563+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1516 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1564 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1517
1565
1518 lvwph->showHeader();
1566 lvwph->showHeader();
@@ -1533,6 +1581,7 @@ private Q_SLOTS:
1533 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1581 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1534 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1582 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1535 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1583 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1584+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1536 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1585 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1537
1586
1538 scrollToTop();
1587 scrollToTop();