on xenial help sign in
LVWPH: Fix header going bad when setContentHeight ends up moving the viewport

How to reproduce the bug easily without the patch: * In the Dash Home, search for london * Scroll to the bottom * Start moving to the apps scope very slowly * At around 3/4 of the move you'll see the header in the home scope went to a bad position * Go back to the Dash Home. Fixes: https://bugs.launchpad.net/bugs/1237942, https://bugs.launchpad.net/bugs/1246351. Approved by Nick Dedekind, PS Jenkins bot, Michal Hruby.

commitd4653996dbd840236f005c4e3ea0462b16fa183a authorAlbert Astals <albert.astals@canonical.com> dateMon 18 Nov 2013, 08:33 (13 years ago) parentaec7f63a749d40
3 files changed+22−1
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+4−1 plugins/ListViewWithPageHeader/listviewwithpageheader.h+1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+17
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+4−1
@@ -155,6 +155,7 @@ ListViewWithPageHeader::ListViewWithPageHeader()
155155 , m_topSectionItem(nullptr)
156156 , m_forceNoClip(false)
157157 , m_inLayout(false)
158+ , m_inContentHeightKeepHeaderShown(false)
158159{
159160 m_clipItem = new QQuickItem(contentItem());
160161// m_clipItem = new QQuickRectangle(contentItem());
@@ -494,7 +495,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
494495 if (!scrolledUp && contentY() == -m_minYExtent) {
495496 m_headerItemShownHeight = 0;
496497 m_headerItem->setY(contentY());
497− } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0)) {
498+ } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
498499 if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
499500 m_headerItemShownHeight -= diff;
500501 else
@@ -1267,7 +1268,9 @@ void ListViewWithPageHeader::updatePolish()
12671268
12681269 m_contentHeightDirty = false;
12691270 adjustMinYExtent();
1271+ m_inContentHeightKeepHeaderShown = m_headerItem && m_headerItem->y() == contentY();
12701272 setContentHeight(contentHeight);
1273+ m_inContentHeightKeepHeaderShown = false;
12711274 }
12721275}
12731276
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1
@@ -202,6 +202,7 @@ private:
202202
203203 bool m_forceNoClip;
204204 bool m_inLayout;
205+ bool m_inContentHeightKeepHeaderShown;
205206
206207 // Qt 5.0 doesn't like releasing the items just after itemCreated
207208 // so we delay the releasing until the next updatePolish
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+17
@@ -1827,6 +1827,23 @@ private Q_SLOTS:
18271827 lvwph->positionAtBeginning();
18281828 }
18291829
1830+ void testHeaderPositionBug1240118()
1831+ {
1832+ scrollToBottom();
1833+ lvwph->showHeader();
1834+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
1835+ QTest::qWait(100); // Make sure stuff is stable
1836+ QMetaObject::invokeMethod(model, "insertItem", Q_ARG(QVariant, 0), Q_ARG(QVariant, 100));
1837+ model->setProperty(3, "size", 10);
1838+ model->setProperty(4, "size", 10);
1839+ model->setProperty(5, "size", 10);
1840+ model->setProperty(6, "size", 10);
1841+#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 3))
1842+ QTRY_COMPARE(lvwph->m_minYExtent, 210.);
1843+#endif
1844+ QTRY_COMPARE(lvwph->m_headerItem->y(), -lvwph->m_minYExtent);
1845+ }
1846+
18301847private:
18311848 QQuickView *view;
18321849 ListViewWithPageHeader *lvwph;