on xenial help sign in
Fix issues when resizing the list

Also rework contentHeight so that it is always lastKnownItemY + lastKnownItemHeight + guessedSizeOfMissingItemsAtTheEnd otherwise with the old formula it could happen that lastKnownItemY + lastKnownItemHeight was already bigger than the total guessed size

commit4462ed503c558870b69a8ba0045ebfb570175dd6 authorAlbert Astals <albert.astals@canonical.com> dateTue 25 Jun 2013, 17:24 (13 years ago) parent46b72d9
3 files changed+147−15
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+26−15 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+41 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+80
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+26−15
@@ -663,6 +663,7 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
663663 }
664664 if (m_firstVisibleIndex < 0 || modelIndex < m_firstVisibleIndex) {
665665 m_firstVisibleIndex = modelIndex;
666+ polish();
666667 }
667668 adjustMinYExtent();
668669 }
@@ -704,6 +705,7 @@ void ListViewWithPageHeader::onHeightChanged()
704705{
705706 setMaximumFlickVelocity(height() * 10);
706707 setFlickDeceleration(height() * 2);
708+ polish();
707709}
708710
709711void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
@@ -933,7 +935,13 @@ void ListViewWithPageHeader::layout()
933935 const qreal topSectionStickPos = m_headerItemShownHeight + contentY() - m_clipItem->y();
934936 if (topSectionStickPos <= pos) {
935937 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
936− QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
938+ if (item->m_sectionItem) {
939+ // This seems it should happen since why would we cull the top section
940+ // if the first visible item has no section header? This only happens briefly
941+ // when increasing the height of a list that is at the bottom, the m_topSectionItem
942+ // gets shown shortly in the next polish call
943+ QQuickItemPrivate::get(item->m_sectionItem)->setCulled(false);
944+ }
937945 } else {
938946 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
939947 m_topSectionItem->setY(topSectionStickPos);
@@ -987,25 +995,28 @@ void ListViewWithPageHeader::updatePolish()
987995
988996 if (m_contentHeightDirty) {
989997 qreal contentHeight;
990− const int modelCount = model()->rowCount();
991− const int visibleItems = m_visibleItems.count();
992− const int lastValidIndex = m_firstVisibleIndex + visibleItems - 1;
993− if (lastValidIndex == modelCount - 1) {
998+ if (m_visibleItems.isEmpty()) {
999+ contentHeight = m_headerItem ? m_headerItem->height() : 0;
1000+ } else {
1001+ const int modelCount = model()->rowCount();
1002+ const int visibleItems = m_visibleItems.count();
1003+ const int lastValidIndex = m_firstVisibleIndex + visibleItems - 1;
1004+ qreal nonCreatedHeight = 0;
1005+ if (lastValidIndex != modelCount - 1) {
1006+ const int visibleItems = m_visibleItems.count();
1007+ qreal visibleItemsHeight = 0;
1008+ foreach(ListItem *item, m_visibleItems) {
1009+ visibleItemsHeight += item->height();
1010+ }
1011+ const int unknownSizes = modelCount - (m_firstVisibleIndex + visibleItems);
1012+ nonCreatedHeight = unknownSizes * visibleItemsHeight / visibleItems;
1013+ }
9941014 ListItem *item = m_visibleItems.last();
995− contentHeight = item->y() + item->height() + m_clipItem->y();
1015+ contentHeight = nonCreatedHeight + item->y() + item->height() + m_clipItem->y();
9961016 if (m_firstVisibleIndex != 0) {
9971017 // Make sure that if we are shrinking we tell the view we still fit
9981018 m_minYExtent = qMax(m_minYExtent, -(contentHeight - height()));
9991019 }
1000− } else {
1001− contentHeight = m_headerItem ? m_headerItem->implicitHeight() : 0;
1002− if (!m_visibleItems.isEmpty()) {
1003− foreach(ListItem *item, m_visibleItems) {
1004− contentHeight += item->height();
1005− }
1006− const int unknownSizes = modelCount - visibleItems;
1007− contentHeight += unknownSizes * contentHeight / visibleItems;
1008− }
10091020 }
10101021
10111022 m_contentHeightDirty = false;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+41
@@ -1258,6 +1258,47 @@ private Q_SLOTS:
12581258 QVERIFY (lvwph->isAtYEnd());
12591259 }
12601260
1261+ void growWindow()
1262+ {
1263+ view->rootObject()->setHeight(850);
1264+
1265+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
1266+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1267+ verifyItem(0, 50., 150., false);
1268+ verifyItem(1, 200., 200., false);
1269+ verifyItem(2, 400., 350., false);
1270+ verifyItem(3, 750., 350., false);
1271+ verifyItem(4, 1100., 350., true);
1272+ QCOMPARE(lvwph->m_minYExtent, 0.);
1273+ QCOMPARE(lvwph->m_clipItem->y(), 0.);
1274+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1275+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1276+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1277+ QCOMPARE(lvwph->contentY(), 0.);
1278+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1279+ }
1280+
1281+ void growWindowAtBottom()
1282+ {
1283+ scrollToBottom();
1284+
1285+ view->rootObject()->setHeight(850);
1286+
1287+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1288+ QCOMPARE(lvwph->m_firstVisibleIndex, 2);
1289+ verifyItem(0, -550., 350., true);
1290+ verifyItem(1, -200., 350., false);
1291+ verifyItem(2, 150, 350., false);
1292+ verifyItem(3, 500, 350., false);
1293+ QCOMPARE(lvwph->m_minYExtent, 350.);
1294+ QCOMPARE(lvwph->m_clipItem->y(), 950.);
1295+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1296+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1297+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1298+ QCOMPARE(lvwph->contentY(), 950.);
1299+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1300+ }
1301+
12611302private:
12621303 QQuickView *view;
12631304 ListViewWithPageHeader *lvwph;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+80
@@ -1456,6 +1456,86 @@ private Q_SLOTS:
14561456 QVERIFY (lvwph->isAtYEnd());
14571457 }
14581458
1459+ void growWindow()
1460+ {
1461+ view->rootObject()->setHeight(850);
1462+
1463+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
1464+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1465+ verifyItem(0, 50., 190., false, "Agressive", false);
1466+ verifyItem(1, 240., 240., false, "Regular", false);
1467+ verifyItem(2, 480., 390., false, "Mild", false);
1468+ verifyItem(3, 870., 390., true, "Bold", true);
1469+ verifyItem(4, 1260., 350., true, QString(), true);
1470+ QCOMPARE(lvwph->m_minYExtent, 0.);
1471+ QCOMPARE(lvwph->m_clipItem->y(), 0.);
1472+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1473+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1474+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1475+ QCOMPARE(lvwph->contentY(), 0.);
1476+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1477+ }
1478+
1479+ void growWindowAtBottom()
1480+ {
1481+ // Need a bunch small items at the bottom to trigger the problem
1482+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1483+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1484+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1485+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1486+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1487+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1488+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1489+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1490+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1491+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1492+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1493+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Regular"));
1494+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1495+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1496+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1497+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1498+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1499+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1500+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1501+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 6), Q_ARG(QVariant, 50), Q_ARG(QVariant, "Agressive"));
1502+
1503+ scrollToBottom();
1504+
1505+ view->rootObject()->setHeight(850);
1506+
1507+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 21);
1508+ QCOMPARE(lvwph->m_firstVisibleIndex, 5);
1509+ verifyItem(0, -660., 390., true, "Lazy", true);
1510+ verifyItem(1, -270., 90., true, "Agressive", true);
1511+ verifyItem(2, -180, 50., true, QString(), true);
1512+ verifyItem(3, -130, 50., true, QString(), true);
1513+ verifyItem(4, -80, 50., true, QString(), true);
1514+ verifyItem(5, -30, 50., false, QString(), true);
1515+ verifyItem(6, 20, 50., false, QString(), true);
1516+ verifyItem(7, 70, 50., false, QString(), true);
1517+ verifyItem(8, 120, 50., false, QString(), true);
1518+ verifyItem(9, 170, 90., false, "Regular", false);
1519+ verifyItem(10, 260, 50., false, QString(), true);
1520+ verifyItem(11, 310, 50., false, QString(), true);
1521+ verifyItem(12, 360, 50., false, QString(), true);
1522+ verifyItem(13, 410, 50., false, QString(), true);
1523+ verifyItem(14, 460, 50., false, QString(), true);
1524+ verifyItem(15, 510, 90., false, "Agressive", false);
1525+ verifyItem(16, 600, 50., false, QString(), true);
1526+ verifyItem(17, 650, 50., false, QString(), true);
1527+ verifyItem(18, 700, 50., false, QString(), true);
1528+ verifyItem(19, 750, 50., false, QString(), true);
1529+ verifyItem(20, 800, 50., false, QString(), true);
1530+ QCOMPARE(lvwph->m_minYExtent, 5 * 1510./21. + 660 - 1970 + 50);
1531+ QCOMPARE(lvwph->m_clipItem->y(), 1970.);
1532+ QCOMPARE(lvwph->m_clipItem->clip(), false);
1533+ QCOMPARE(lvwph->m_headerItem->y(), 0.);
1534+ QCOMPARE(lvwph->m_headerItem->height(), 50.);
1535+ QCOMPARE(lvwph->contentY(), 1970.);
1536+ QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1537+ }
1538+
14591539private:
14601540 QQuickView *view;
14611541 ListViewWithPageHeader *lvwph;