on xenial help sign in
Make sure m_firstVisibleIndex is correctly set after processing QQmlChangeSet::Change
4fa1f82Albert Astals Cid
plugins/Dash/listviewwithpageheader.cpp+7−8
@@ -973,14 +973,13 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
973 }
973 }
974 if (growDown) {
974 if (growDown) {
975 adjustMinYExtent();
975 adjustMinYExtent();
976− } else if (remove.index <= m_firstVisibleIndex) {
976+ } else if (remove.index <= m_firstVisibleIndex && !m_visibleItems.isEmpty()) {
977− if (!m_visibleItems.isEmpty()) {
978− // We removed the first item that is the one that positions the rest
979− // position the new first item correctly
980− m_visibleItems.first()->setY(oldFirstValidIndexPos);
977+ m_visibleItems.first()->setY(oldFirstValidIndexPos);
981− } else {
978+ }
979+ if (m_visibleItems.isEmpty()) {
982− m_firstVisibleIndex = -1;
980+ m_firstVisibleIndex = -1;
983− }
981+ } else {
982+ m_firstVisibleIndex -= qMax(0, m_firstVisibleIndex - remove.index);
984 }
983 }
985 } else if (remove.index + remove.count <= m_firstVisibleIndex) {
984 } else if (remove.index + remove.count <= m_firstVisibleIndex) {
986 m_firstVisibleIndex -= remove.count;
985 m_firstVisibleIndex -= remove.count;
tests/plugins/Dash/listviewwithpageheadertest.cpp+11
@@ -1938,6 +1938,17 @@ private Q_SLOTS:
1938 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1938 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
1939 }
1939 }
1940
1940
1941+ void testFirstVisibleIndexRemove()
1942+ {
1943+ changeContentY(520);
1944+ QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1945+ QCOMPARE(lvwph->m_firstVisibleIndex, 1);
1946+
1947+ // Remove 0 and 1, the previously visible index 2 will be 0 and visible
1948+ QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 0), Q_ARG(QVariant, 2));
1949+ QCOMPARE(lvwph->m_firstVisibleIndex, 0);
1950+ }
1951+
1941private:
1952private:
1942 QQuickView *view;
1953 QQuickView *view;
1943 ListViewWithPageHeader *lvwph;
1954 ListViewWithPageHeader *lvwph;