on xenial help sign in
Do not crash on positionAtBeginning if the list is empty
4bf2e44Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+3
@@ -330,6 +330,9 @@ void ListViewWithPageHeader::setForceNoClip(bool noClip)
330
330
331void ListViewWithPageHeader::positionAtBeginning()
331void ListViewWithPageHeader::positionAtBeginning()
332{
332{
333+ if (m_delegateModel->count() <= 0)
334+ return;
335+
333 qreal headerHeight = (m_headerItem ? m_headerItem->height() : 0);
336 qreal headerHeight = (m_headerItem ? m_headerItem->height() : 0);
334 if (m_firstVisibleIndex != 0) {
337 if (m_firstVisibleIndex != 0) {
335 // TODO This could be optimized by trying to reuse the interesection
338 // TODO This could be optimized by trying to reuse the interesection
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+8
@@ -1816,6 +1816,14 @@ private Q_SLOTS:
1816 verifyItem(0, -50., 800., false);
1816 verifyItem(0, -50., 800., false);
1817 }
1817 }
1818
1818
1819+ void positionAtBeginningEmpty()
1820+ {
1821+ QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 6));
1822+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 0);
1823+
1824+ lvwph->positionAtBeginning();
1825+ }
1826+
1819private:
1827private:
1820 QQuickView *view;
1828 QQuickView *view;
1821 ListViewWithPageHeader *lvwph;
1829 ListViewWithPageHeader *lvwph;