on xenial help sign in
Make LVWPH provide a delegateIndex for sectionHeaders
ad92746Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+21−3
@@ -269,7 +269,7 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
269
269
270 m_sectionDelegate = delegate;
270 m_sectionDelegate = delegate;
271
271
272− m_topSectionItem = getSectionItem(QString());
272+ m_topSectionItem = getSectionItem(-1, QString());
273 m_topSectionItem->setZ(3);
273 m_topSectionItem->setZ(3);
274 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
274 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
275
275
@@ -578,16 +578,17 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
578 }
578 }
579 }
579 }
580
580
581− return getSectionItem(section);
581+ return getSectionItem(modelIndex, section);
582}
582}
583
583
584−QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText)
584+QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, const QString &sectionText)
585{
585{
586 QQuickItem *sectionItem = nullptr;
586 QQuickItem *sectionItem = nullptr;
587
587
588 QQmlContext *creationContext = m_sectionDelegate->creationContext();
588 QQmlContext *creationContext = m_sectionDelegate->creationContext();
589 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
589 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
590 context->setContextProperty(QLatin1String("section"), sectionText);
590 context->setContextProperty(QLatin1String("section"), sectionText);
591+ context->setContextProperty(QLatin1String("delegateIndex"), modelIndex);
591 QObject *nobj = m_sectionDelegate->beginCreate(context);
592 QObject *nobj = m_sectionDelegate->beginCreate(context);
592 if (nobj) {
593 if (nobj) {
593 QQml_setParent_noEvent(context, nobj);
594 QQml_setParent_noEvent(context, nobj);
@@ -870,6 +871,14 @@ void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bo
870 adjustMinYExtent();
871 adjustMinYExtent();
871 }
872 }
872
873
874+ for (int i = 0; i < m_visibleItems.count(); ++i) {
875+ ListItem *item = m_visibleItems[i];
876+ if (item->m_sectionItem) {
877+ QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
878+ context->setContextProperty(QLatin1String("delegateIndex"), m_firstVisibleIndex + i);
879+ }
880+ }
881+
873 layout();
882 layout();
874 polish();
883 polish();
875 m_contentHeightDirty = true;
884 m_contentHeightDirty = true;
@@ -998,6 +1007,15 @@ void ListViewWithPageHeader::layout()
998 } else {
1007 } else {
999 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1008 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1000 m_topSectionItem->setY(topSectionStickPos);
1009 m_topSectionItem->setY(topSectionStickPos);
1010+ int delegateIndex = modelIndex;
1011+ // Look for the first index with this section text
1012+ while (delegateIndex > 0) {
1013+ const QString prevSection = m_delegateModel->stringValue(delegateIndex - 1, m_sectionProperty);
1014+ if (prevSection != section)
1015+ break;
1016+ delegateIndex--;
1017+ }
1018+ context->setContextProperty(QLatin1String("delegateIndex"), delegateIndex);
1001 if (item->m_sectionItem) {
1019 if (item->m_sectionItem) {
1002 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1020 QQuickItemPrivate::get(item->m_sectionItem)->setCulled(true);
1003 }
1021 }
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1−1
@@ -139,7 +139,7 @@ private:
139 void reallyReleaseItem(ListItem *item);
139 void reallyReleaseItem(ListItem *item);
140 void updateWatchedRoles();
140 void updateWatchedRoles();
141 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
141 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
142− QQuickItem *getSectionItem(const QString &sectionText);
142+ QQuickItem *getSectionItem(int modelIndex, const QString &sectionText);
143
143
144 QQuickVisualDataModel *m_delegateModel;
144 QQuickVisualDataModel *m_delegateModel;
145
145
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+51−2
@@ -41,6 +41,7 @@ private:
41 QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), sectionHeader);
41 QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), sectionHeader);
42 if (!sectionHeader.isNull()) {
42 if (!sectionHeader.isNull()) {
43 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_sectionItem)->culled, sectionHeaderCulled);
43 QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_sectionItem)->culled, sectionHeaderCulled);
44+ QCOMPARE(sectionDelegateIndex(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), lvwph->m_firstVisibleIndex + visibleIndex);
44 }
45 }
45 }
46 }
46
47
@@ -112,6 +113,11 @@ private:
112 return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
113 return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
113 }
114 }
114
115
116+ int sectionDelegateIndex(QQuickItem *item)
117+ {
118+ return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("delegateIndex")).toInt() : -1;
119+ }
120+
115private Q_SLOTS:
121private Q_SLOTS:
116
122
117 void initTestCase()
123 void initTestCase()
@@ -212,6 +218,7 @@ private Q_SLOTS:
212 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
218 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
213 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
219 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
214 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
220 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
221+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
215 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
222 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
216 }
223 }
217
224
@@ -233,6 +240,7 @@ private Q_SLOTS:
233 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
240 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
234 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
241 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
235 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
242 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
243+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
236 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
244 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
237 }
245 }
238
246
@@ -254,6 +262,7 @@ private Q_SLOTS:
254 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
262 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
255 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
263 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
256 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
264 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
265+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
257 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
266 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
258
267
259 changeContentY(-30);
268 changeContentY(-30);
@@ -272,6 +281,7 @@ private Q_SLOTS:
272 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
281 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
273 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
282 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
274 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
283 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
284+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
275 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
285 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
276 }
286 }
277
287
@@ -327,6 +337,7 @@ private Q_SLOTS:
327 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
337 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
328 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
338 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
329 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
339 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
340+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
330 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
341 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
331
342
332 lvwph->positionAtBeginning();
343 lvwph->positionAtBeginning();
@@ -352,6 +363,7 @@ private Q_SLOTS:
352 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
363 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
353 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
364 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
354 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
365 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
366+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
355 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
367 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
356
368
357 lvwph->positionAtBeginning();
369 lvwph->positionAtBeginning();
@@ -396,6 +408,7 @@ private Q_SLOTS:
396 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
408 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
397 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
409 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
398 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
410 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
411+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
399 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
412 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
400
413
401 model->setProperty(0, "size", 400);
414 model->setProperty(0, "size", 400);
@@ -415,6 +428,7 @@ private Q_SLOTS:
415 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
428 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
416 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
429 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
417 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
430 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
431+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
418 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
432 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
419
433
420 scrollToTop();
434 scrollToTop();
@@ -468,6 +482,7 @@ private Q_SLOTS:
468 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
482 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
469 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
483 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
470 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
484 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
485+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
471 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
486 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
472
487
473 model->setProperty(0, "size", 400);
488 model->setProperty(0, "size", 400);
@@ -487,6 +502,7 @@ private Q_SLOTS:
487 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
502 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
488 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
503 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
489 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
504 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
505+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
490 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
506 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
491
507
492 scrollToTop();
508 scrollToTop();
@@ -523,6 +539,7 @@ private Q_SLOTS:
523 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
539 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
524 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
540 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
525 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
541 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
542+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
526 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
543 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
527
544
528 changeContentY(-30);
545 changeContentY(-30);
@@ -540,6 +557,7 @@ private Q_SLOTS:
540 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
557 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
541 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
558 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
542 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
559 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
560+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
543 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
561 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
544
562
545 changeContentY(30);
563 changeContentY(30);
@@ -557,6 +575,7 @@ private Q_SLOTS:
557 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
575 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
558 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
576 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
559 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
577 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
578+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
560 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
579 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
561
580
562 changeContentY(-30);
581 changeContentY(-30);
@@ -574,6 +593,7 @@ private Q_SLOTS:
574 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
593 QCOMPARE(lvwph->m_headerItemShownHeight, 30.);
575 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
594 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
576 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
595 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
596+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
577 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
597 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
578 }
598 }
579
599
@@ -594,6 +614,7 @@ private Q_SLOTS:
594 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
614 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
595 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
615 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
596 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
616 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
617+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
597 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
618 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
598
619
599 lvwph->setDelegate(otherDelegate);
620 lvwph->setDelegate(otherDelegate);
@@ -652,6 +673,7 @@ private Q_SLOTS:
652 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
673 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
653 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
674 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
654 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
675 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
676+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
655 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
677 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
656
678
657 scrollToTop();
679 scrollToTop();
@@ -690,6 +712,7 @@ private Q_SLOTS:
690 QTRY_VERIFY(lvwph->isAtYEnd());
712 QTRY_VERIFY(lvwph->isAtYEnd());
691 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
713 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
692 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
714 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
715+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
693 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
716 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
694
717
695 scrollToTop();
718 scrollToTop();
@@ -726,6 +749,7 @@ private Q_SLOTS:
726 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
749 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
727 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
750 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
728 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
751 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
752+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
729 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
753 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
730 }
754 }
731
755
@@ -810,6 +834,7 @@ private Q_SLOTS:
810 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
834 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
811 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
835 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
812 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
836 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
837+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
813 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
838 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
814
839
815 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
840 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -830,6 +855,7 @@ private Q_SLOTS:
830 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
855 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
831 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
856 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
832 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
857 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
858+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
833 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
859 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
834
860
835 scrollToTop();
861 scrollToTop();
@@ -870,6 +896,7 @@ private Q_SLOTS:
870 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
896 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
871 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
897 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
872 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
898 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
899+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
873 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
900 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
874
901
875 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 3), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
902 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 3), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -890,6 +917,7 @@ private Q_SLOTS:
890 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
917 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
891 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
918 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
892 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
919 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
920+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
893 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
921 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
894 }
922 }
895
923
@@ -912,6 +940,7 @@ private Q_SLOTS:
912 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
940 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
913 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
941 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
914 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
942 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
943+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
915 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
944 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
916
945
917 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
946 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -932,6 +961,7 @@ private Q_SLOTS:
932 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
961 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
933 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
962 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
934 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
963 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
964+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
935 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
965 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
936 }
966 }
937
967
@@ -954,6 +984,7 @@ private Q_SLOTS:
954 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
984 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
955 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
985 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
956 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
986 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
987+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
957 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
988 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
958
989
959 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
990 QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 100), Q_ARG(QVariant, "Agressive"));
@@ -974,6 +1005,7 @@ private Q_SLOTS:
974 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1005 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
975 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1006 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
976 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1007 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1008+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
977 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1009 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
978
1010
979 scrollToTop();
1011 scrollToTop();
@@ -1021,6 +1053,7 @@ private Q_SLOTS:
1021 QVERIFY(!lvwph->isAtYEnd());
1053 QVERIFY(!lvwph->isAtYEnd());
1022 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1054 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1023 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1055 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1056+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
1024 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1057 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1025
1058
1026 scrollToBottom();
1059 scrollToBottom();
@@ -1041,6 +1074,7 @@ private Q_SLOTS:
1041 QVERIFY(lvwph->isAtYEnd());
1074 QVERIFY(lvwph->isAtYEnd());
1042 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1075 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1043 QCOMPARE(section(lvwph->m_topSectionItem), QString("Lazy"));
1076 QCOMPARE(section(lvwph->m_topSectionItem), QString("Lazy"));
1077+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 5);
1044 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1078 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1045 }
1079 }
1046
1080
@@ -1094,6 +1128,7 @@ private Q_SLOTS:
1094 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1128 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1095 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1129 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1096 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1130 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1131+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 13);
1097 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1132 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1098
1133
1099 changeContentY(-1700);
1134 changeContentY(-1700);
@@ -1118,6 +1153,7 @@ private Q_SLOTS:
1118 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1153 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1119 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1154 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1120 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1155 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1156+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 4);
1121 QCOMPARE(lvwph->m_topSectionItem->y(), -23.);
1157 QCOMPARE(lvwph->m_topSectionItem->y(), -23.);
1122 }
1158 }
1123
1159
@@ -1179,6 +1215,7 @@ private Q_SLOTS:
1179 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1215 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1180 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1216 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1181 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1217 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1218+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1182 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1219 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1183 }
1220 }
1184
1221
@@ -1202,6 +1239,7 @@ private Q_SLOTS:
1202 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1239 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1203 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1240 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1204 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1241 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1242+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1205 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1243 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1206 }
1244 }
1207
1245
@@ -1224,6 +1262,7 @@ private Q_SLOTS:
1224 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1262 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1225 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1263 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1226 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1264 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1265+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1227 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1266 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1228
1267
1229 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 1), Q_ARG(QVariant, 1));
1268 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 1), Q_ARG(QVariant, 1));
@@ -1243,6 +1282,7 @@ private Q_SLOTS:
1243 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1282 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1244 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1283 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1245 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1284 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1285+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1246 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1286 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1247 }
1287 }
1248
1288
@@ -1265,6 +1305,7 @@ private Q_SLOTS:
1265 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1305 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1266 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1306 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1267 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1307 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1308+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1268 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1309 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1269
1310
1270 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 3), Q_ARG(QVariant, 1));
1311 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 3), Q_ARG(QVariant, 1));
@@ -1284,6 +1325,7 @@ private Q_SLOTS:
1284 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1325 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1285 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1326 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1286 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1327 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1328+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1287 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1329 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1288 }
1330 }
1289
1331
@@ -1363,6 +1405,7 @@ private Q_SLOTS:
1363 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1405 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1364 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1406 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1365 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1407 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1408+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 3);
1366 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1409 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1367
1410
1368 QMetaObject::invokeMethod(model, "moveItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 5), Q_ARG(QVariant, 1));
1411 QMetaObject::invokeMethod(model, "moveItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 5), Q_ARG(QVariant, 1));
@@ -1383,6 +1426,7 @@ private Q_SLOTS:
1383 QVERIFY(!lvwph->isAtYEnd());
1426 QVERIFY(!lvwph->isAtYEnd());
1384 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1427 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1385 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1428 QCOMPARE(section(lvwph->m_topSectionItem), QString("Bold"));
1429+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1386 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1430 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1387 }
1431 }
1388
1432
@@ -1406,6 +1450,7 @@ private Q_SLOTS:
1406 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1450 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1407 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1451 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1408 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1452 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1453+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1409 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1454 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1410
1455
1411 model->setProperty(1, "size", 100);
1456 model->setProperty(1, "size", 100);
@@ -1426,6 +1471,7 @@ private Q_SLOTS:
1426 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1471 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1427 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1472 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1428 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1473 QCOMPARE(section(lvwph->m_topSectionItem), QString("Mild"));
1474+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 2);
1429 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1475 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1430 }
1476 }
1431
1477
@@ -1447,7 +1493,7 @@ private Q_SLOTS:
1447 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1493 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1448 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1494 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1449 QCOMPARE(lvwph->contentY(), 20.);
1495 QCOMPARE(lvwph->contentY(), 20.);
1450− QCOMPARE(lvwph->m_headerItemShownHeight, 0.);;
1496+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1451 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1497 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1452
1498
1453 lvwph->showHeader();
1499 lvwph->showHeader();
@@ -1467,6 +1513,7 @@ private Q_SLOTS:
1467 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1513 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1468 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1514 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1469 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
1515 QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
1516+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
1470 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1517 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1471
1518
1472 scrollToTop();
1519 scrollToTop();
@@ -1502,9 +1549,10 @@ private Q_SLOTS:
1502 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1549 QCOMPARE(lvwph->m_headerItem->y(), 0.);
1503 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1550 QCOMPARE(lvwph->m_headerItem->height(), 50.);
1504 QCOMPARE(lvwph->contentY(), 375.);
1551 QCOMPARE(lvwph->contentY(), 375.);
1505− QCOMPARE(lvwph->m_headerItemShownHeight, 0.);;
1552+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1506 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1553 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1507 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1554 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1555+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1508 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1556 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1509
1557
1510 lvwph->showHeader();
1558 lvwph->showHeader();
@@ -1525,6 +1573,7 @@ private Q_SLOTS:
1525 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1573 QCOMPARE(lvwph->m_headerItemShownHeight, 50.);
1526 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1574 QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1527 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1575 QCOMPARE(section(lvwph->m_topSectionItem), QString("Regular"));
1576+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 1);
1528 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1577 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1529
1578
1530 scrollToTop();
1579 scrollToTop();