on xenial help sign in
Fix crash when inserting items

If the list had to grow up and the next item to the inserted shared the same section header

commit9f40510e5e69eb54606beab54baa45a3a1a25910 authorAlbert Astals <albert.astals@canonical.com> dateThu 27 Jun 2013, 10:14 (13 years ago) parent183438a
2 files changed+26−7
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+1−1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+25−6
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+1−1
@@ -814,7 +814,7 @@ void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bo
814814 ListItem *nextItem = itemAtIndex(modelIndex + 1);
815815 if (nextItem && !nextItem->m_sectionItem) {
816816 nextItem->m_sectionItem = getSectionItem(modelIndex + 1, true /* alredy inserted into m_visibleItems*/);
817− if (growUp) {
817+ if (growUp && nextItem->m_sectionItem) {
818818 ListItem *firstItem = m_visibleItems.first();
819819 firstItem->setY(firstItem->y() - nextItem->m_sectionItem->height());
820820 adjustMinYExtent();
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+25−6
@@ -32,13 +32,12 @@ private:
3232 void verifyItem(int visibleIndex, qreal pos, qreal height, bool culled, const QString &sectionHeader, bool sectionHeaderCulled)
3333 {
3434 QTRY_VERIFY(visibleIndex < lvwph->m_visibleItems.count());
35− ListViewWithPageHeader::ListItem *item = lvwph->m_visibleItems[visibleIndex];
36− QTRY_COMPARE(item->y(), pos);
37− QTRY_COMPARE(item->height(), height);
38− QCOMPARE(QQuickItemPrivate::get(item->m_item)->culled, culled);
39− QCOMPARE(section(item->m_sectionItem), sectionHeader);
35+ QTRY_COMPARE(lvwph->m_visibleItems[visibleIndex]->y(), pos);
36+ QTRY_COMPARE(lvwph->m_visibleItems[visibleIndex]->height(), height);
37+ QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_item)->culled, culled);
38+ QCOMPARE(section(lvwph->m_visibleItems[visibleIndex]->m_sectionItem), sectionHeader);
4039 if (!sectionHeader.isNull()) {
41− QCOMPARE(QQuickItemPrivate::get(item->m_sectionItem)->culled, sectionHeaderCulled);
40+ QCOMPARE(QQuickItemPrivate::get(lvwph->m_visibleItems[visibleIndex]->m_sectionItem)->culled, sectionHeaderCulled);
4241 }
4342 }
4443
@@ -1266,6 +1265,26 @@ private Q_SLOTS:
12661265 QCOMPARE(lvwph->m_topSectionItem->y(), 0.);
12671266 }
12681267
1268+ void testAddSecondToCulledCategoryOfTwo()
1269+ {
1270+ // Do some setup
1271+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 25), Q_ARG(QVariant, "Agressive"));
1272+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 25), Q_ARG(QVariant, "Agressive"));
1273+
1274+ changeContentY(200);
1275+
1276+ // Very the items are culled
1277+ verifyItem(0, -150., 65., true, "Agressive", true);
1278+ verifyItem(1, -85, 25., true, QString(), true);
1279+
1280+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 1), Q_ARG(QVariant, 25), Q_ARG(QVariant, "Agressive"));
1281+
1282+ // Very the new item is there correctly
1283+ verifyItem(0, -175., 65., true, "Agressive", true);
1284+ verifyItem(1, -110, 25., true, QString(), true);
1285+ verifyItem(2, -85, 25., true, QString(), true);
1286+ }
1287+
12691288 void testMoveFirstItems()
12701289 {
12711290 QMetaObject::invokeMethod(model, "moveItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 1), Q_ARG(QVariant, 1));