on xenial help sign in
LVPWH: Fix regression handling the sticky top section culling

r166 introduced the regression, this fixes it+tests

commitce0d542562eb3286e2cebe81e77de26f1220b3d8 authorAlbert Astals <albert.astals@canonical.com> dateWed 7 Aug 2013, 16:04 (13 years ago) parenta97b1ba
2 files changed+58−1
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+13−1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+45
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+13−1
@@ -1052,7 +1052,19 @@ void ListViewWithPageHeader::layout()
10521052 // Then after the loop we'll make sure that if there's another section just below it
10531053 // pushed the sticky section up to make it disappear
10541054 const qreal topSectionStickPos = m_headerItemShownHeight + contentY() - m_clipItem->y();
1055− if (topSectionStickPos <= pos) {
1055+ bool showStickySectionItem;
1056+ // We need to show the "top section sticky item" when the position at the "top" of the
1057+ // viewport is bigger than the start of the position of the first visible item
1058+ // i.e. the first visible item starts before the viewport, or when the first
1059+ // visible item starts just at the viewport start and it does not have its own section item
1060+ if (topSectionStickPos > pos) {
1061+ showStickySectionItem = true;
1062+ } else if (topSectionStickPos == pos) {
1063+ showStickySectionItem = !item->m_sectionItem;
1064+ } else {
1065+ showStickySectionItem = false;
1066+ }
1067+ if (!showStickySectionItem) {
10561068 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
10571069 if (item->m_sectionItem) {
10581070 // This seems it should happen since why would we cull the top section
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+45
@@ -1711,6 +1711,51 @@ private Q_SLOTS:
17111711 QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
17121712 }
17131713
1714+ void testSectionItemCullOnFirstSectionItemTopEdge()
1715+ {
1716+ changeContentY(50);
1717+
1718+ verifyItem(0, 0., 190., false, "Agressive", false);
1719+ verifyItem(1, 190., 240., false, "Regular", false);
1720+ verifyItem(2, 430., 390., false, "Mild", false);
1721+ QCOMPARE(lvwph->m_minYExtent, 0.);
1722+ QCOMPARE(lvwph->m_clipItem->y(), 50.);
1723+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1724+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1725+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1726+ QCOMPARE(lvwph->contentY(), 50.);
1727+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1728+ QVERIFY(QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1729+ }
1730+
1731+ void testSectionItemCullOnSecondSectionItemTopEdge()
1732+ {
1733+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1734+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1735+
1736+ changeContentY(140);
1737+
1738+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
1739+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1740+ verifyItem(0, -90., 90., true, "Agressive", true);
1741+ verifyItem(1, 0., 50., false, QString(), false);
1742+ verifyItem(2, 50., 150., false, QString(), false);
1743+ verifyItem(3, 200., 240., false, "Regular", false);
1744+ verifyItem(4, 440., 390., false, "Mild", false);
1745+ QCOMPARE(lvwph->m_minYExtent, 0.);
1746+ QCOMPARE(lvwph->m_clipItem->y(), 140.);
1747+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1748+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1749+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1750+ QCOMPARE(lvwph->contentY(), 140.);
1751+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1752+ QVERIFY(!QQuickItemPrivate::get(lvwph->m_topSectionItem)->culled);
1753+ QCOMPARE(section(lvwph->m_topSectionItem), QString("Agressive"));
1754+ QCOMPARE(sectionDelegateIndex(lvwph->m_topSectionItem), 0);
1755+ QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
1756+ }
1757+
1758+
17141759private:
17151760 QQuickView *view;
17161761 ListViewWithPageHeader *lvwph;