on xenial help sign in
Make sure m_firstVisibleIndex is correctly set after processing changeSet.removes

There are two fixes: * Decouple the code that sets the m_firstVisibleIndex that was only done when !growDown * Set m_firstVisibleIndex correctly when the list is not empty Fixes: #1433056 Approved by: Michael Zanetti

commitab3534ec0422642f04552227945f80a8c2c915f0 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 20 Mar 2015, 11:56 (12 years ago) parentf1e1c454fa1f82
2 files changed+18−8
plugins/Dash/listviewwithpageheader.cpp+7−8 tests/plugins/Dash/listviewwithpageheadertest.cpp+11
plugins/Dash/listviewwithpageheader.cpp+7−8
@@ -973,14 +973,13 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
973973 }
974974 if (growDown) {
975975 adjustMinYExtent();
976− } else if (remove.index <= m_firstVisibleIndex) {
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);
981− } else {
982− m_firstVisibleIndex = -1;
983− }
976+ } else if (remove.index <= m_firstVisibleIndex && !m_visibleItems.isEmpty()) {
977+ m_visibleItems.first()->setY(oldFirstValidIndexPos);
978+ }
979+ if (m_visibleItems.isEmpty()) {
980+ m_firstVisibleIndex = -1;
981+ } else {
982+ m_firstVisibleIndex -= qMax(0, m_firstVisibleIndex - remove.index);
984983 }
985984 } else if (remove.index + remove.count <= m_firstVisibleIndex) {
986985 m_firstVisibleIndex -= remove.count;
tests/plugins/Dash/listviewwithpageheadertest.cpp+11
@@ -1938,6 +1938,17 @@ private Q_SLOTS:
19381938 QCOMPARE(lvwph->m_headerItemShownHeight, 0.);
19391939 }
19401940
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+
19411952private:
19421953 QQuickView *view;
19431954 ListViewWithPageHeader *lvwph;