aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2017-07-10 13:52:35 -0500
committerMichael Brasser <michael.brasser@live.com>2017-08-09 13:20:02 +0000
commitd419377d2041b35639a5ab81688a0bc30b5e2994 (patch)
tree6bd462b08675da01147417331d1208545c11197a
parent9e1497bed6f68d76e1ba8639a5ee9ca7056ef503 (diff)
Fix ListView::StrictlyEnforceRange with resizing delegate
When fixupPosition is called for a ListView with StrictlyEnforceRange, the original reason for the move is lost, and the fixup is applied immediately. There are already checks for whether the view is moving, so expand these checks to include movement caused by highlight. Change-Id: I25f771b9a529d31dc28acb9f91fcd2b582428200 Task-number: QTBUG-33568 Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
-rw-r--r--src/quick/items/qquickitemview.cpp2
-rw-r--r--src/quick/items/qquickitemview_p_p.h1
-rw-r--r--src/quick/items/qquicklistview.cpp12
-rw-r--r--tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml31
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp24
5 files changed, 69 insertions, 1 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index 084b1f197a..1d0d042839 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -1921,7 +1921,7 @@ void QQuickItemViewPrivate::layout()
markExtentsDirty();
updateHighlight();
- if (!q->isMoving() && !q->isFlicking()) {
+ if (!q->isMoving() && !q->isFlicking() && !movingFromHighlight()) {
fixupPosition();
refill();
}
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index b6353246e8..2c04022cde 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -363,6 +363,7 @@ protected:
virtual void createHighlight() = 0;
virtual void updateHighlight() = 0;
virtual void resetHighlightPosition() = 0;
+ virtual bool movingFromHighlight() { return false; }
virtual void setPosition(qreal pos) = 0;
virtual void fixupPosition() = 0;
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index 979a3557a1..edfa970035 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -101,6 +101,7 @@ public:
void createHighlight() override;
void updateHighlight() override;
void resetHighlightPosition() override;
+ bool movingFromHighlight() override;
void setPosition(qreal pos) override;
void layoutVisibleItems(int fromModelIndex = 0) override;
@@ -945,6 +946,17 @@ void QQuickListViewPrivate::resetHighlightPosition()
static_cast<FxListItemSG*>(highlight)->setPosition(static_cast<FxListItemSG*>(currentItem)->itemPosition());
}
+bool QQuickListViewPrivate::movingFromHighlight()
+{
+ if (!haveHighlightRange || highlightRange != QQuickListView::StrictlyEnforceRange)
+ return false;
+
+ return (highlightPosAnimator && highlightPosAnimator->isRunning()) ||
+ (highlightHeightAnimator && highlightHeightAnimator->isRunning()) ||
+ (highlightWidthAnimator && highlightWidthAnimator->isRunning());
+}
+
+
QQuickItem * QQuickListViewPrivate::getSectionItem(const QString &section)
{
Q_Q(QQuickListView);
diff --git a/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml b/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml
new file mode 100644
index 0000000000..338af38475
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml
@@ -0,0 +1,31 @@
+import QtQuick 2.0
+
+ListView {
+ width: 400
+ height: 400
+ focus: true
+
+ highlightRangeMode: ListView.StrictlyEnforceRange
+ highlightMoveVelocity: 200
+ preferredHighlightBegin: 150
+ preferredHighlightEnd: 150
+
+ property bool completed
+ Component.onCompleted: completed = true
+
+ model: 10
+ delegate: Item {
+ width: parent.width
+ height: ListView.isCurrentItem ? 100 : 50
+
+ Text {
+ anchors.centerIn: parent
+ text: index
+ }
+
+ Behavior on height {
+ enabled: completed
+ SmoothedAnimation { velocity: 200 }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 98c628068d..2eb87b9431 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -182,6 +182,7 @@ private slots:
void snapOneItemCurrentIndexRemoveAnimation();
void QTBUG_9791();
+ void QTBUG_33568();
void QTBUG_11105();
void QTBUG_21742();
@@ -3470,6 +3471,29 @@ void tst_QQuickListView::QTBUG_9791()
QTRY_COMPARE(listview->contentX(), 590.0);
}
+void tst_QQuickListView::QTBUG_33568()
+{
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("strictlyenforcerange-resize.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject());
+ QVERIFY(listview != 0);
+
+ // we want to verify that the change animates smoothly, rather than jumping into place
+ QSignalSpy spy(listview, SIGNAL(contentYChanged()));
+
+ listview->incrementCurrentIndex();
+ QTRY_COMPARE(listview->contentY(), -100.0);
+ QVERIFY(spy.count() > 1);
+
+ spy.clear();
+ listview->incrementCurrentIndex();
+ QTRY_COMPARE(listview->contentY(), -50.0);
+ QVERIFY(spy.count() > 1);
+}
+
void tst_QQuickListView::manualHighlight()
{
QQuickView *window = new QQuickView(0);