diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-06-08 11:18:50 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-06-08 14:26:31 +0000 |
commit | 56c9ce5fac873e5c1e20a6a965eb750a81373968 (patch) | |
tree | 080e425a1d0f4690ccc55a13b7da567aa5f223b6 | |
parent | 6d32604fd1560fd0dbf10eac702bbf3e9c448875 (diff) |
Fix QQuickContainerPrivate::itemSiblingOrderChanged()
Repeaters are not part of the content model. Exclude them when
calculating the target index when the order of items changes.
Task-number: QTBUG-61310
Change-Id: Iaedd59288ed38e985a34ed8e1f515fdfb50d74e6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickcontainer.cpp | 6 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_container.qml | 27 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp index 6177d200..919eff70 100644 --- a/src/quicktemplates2/qquickcontainer.cpp +++ b/src/quicktemplates2/qquickcontainer.cpp @@ -332,10 +332,14 @@ void QQuickContainerPrivate::itemSiblingOrderChanged(QQuickItem *) // reorder the restacked items (eg. by a Repeater) Q_Q(QQuickContainer); QList<QQuickItem *> siblings = effectiveContentItem(contentItem)->childItems(); + + int to = 0; for (int i = 0; i < siblings.count(); ++i) { QQuickItem* sibling = siblings.at(i); + if (QQuickItemPrivate::get(sibling)->isTransparentForPositioner()) + continue; int index = contentModel->indexOf(sibling, nullptr); - q->moveItem(index, i); + q->moveItem(index, to++); } } diff --git a/tests/auto/controls/data/tst_container.qml b/tests/auto/controls/data/tst_container.qml index 049982fb..b8de2b08 100644 --- a/tests/auto/controls/data/tst_container.qml +++ b/tests/auto/controls/data/tst_container.qml @@ -126,4 +126,31 @@ TestCase { compare(control1.currentIndex, 1) compare(control2.currentIndex, 1) } + + Component { + id: repeaterContainer + Container { + id: container + Item { objectName: "0" } + Item { objectName: "1" } + Item { objectName: "2" } + Item { objectName: "3" } + contentItem: Row { + Repeater { + model: container.contentModel + } + } + } + } + + // don't crash (QTBUG-61310) + function test_repeater() { + var control = createTemporaryObject(repeaterContainer) + verify(control) + + compare(control.itemAt(0).objectName, "0") + compare(control.itemAt(1).objectName, "1") + compare(control.itemAt(2).objectName, "2") + compare(control.itemAt(3).objectName, "3") + } } |