diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-02-13 16:18:26 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-02-16 15:17:30 +0000 |
commit | f6eb6a3661f5c8c47c539d38b5bcb0a33c22d904 (patch) | |
tree | 72dbe00758ea1565f554834d6a71d86984891e85 /tests/auto/controls/data/tst_tumbler.qml | |
parent | acfe7fc8bb19c591a4c44d88aac95b3caa3d445f (diff) |
Tumbler: add positionViewAtIndex() function
This calls the respective PathView/ListView function (depending on
the value of wrap), and allows users to change the current index
without animations.
[ChangeLog][Controls][Tumbler] Added positionViewAtIndex() function
that calls the respective PathView/ListView function, depending on
the value of wrap. This allows changing currentIndex without
animations.
Task-number: QTBUG-66358
Change-Id: I7fe73bd3e53548ef41a165b68637d99f3171e02e
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/controls/data/tst_tumbler.qml')
-rw-r--r-- | tests/auto/controls/data/tst_tumbler.qml | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_tumbler.qml b/tests/auto/controls/data/tst_tumbler.qml index 058cbeca..d64f7c9c 100644 --- a/tests/auto/controls/data/tst_tumbler.qml +++ b/tests/auto/controls/data/tst_tumbler.qml @@ -107,6 +107,10 @@ TestCase { return Qt.point(tumblerXCenter(), yCenter); } + function itemTopLeftPos(visualItemIndex) { + return Qt.point(tumbler.leftPadding, tumbler.topPadding + (tumblerDelegateHeight * visualItemIndex)); + } + function checkItemSizes() { var contentChildren = tumbler.wrap ? tumblerView.children : tumblerView.contentItem.children; verify(contentChildren.length >= tumbler.count); @@ -131,6 +135,21 @@ TestCase { return null; } + function findDelegateWithText(parent, text) { + for (var i = 0; i < parent.children.length; ++i) { + var child = parent.children[i]; + if (child.hasOwnProperty("text") && child.text === text) { + return child; + } + + var grandChild = findDelegateWithText(child, text); + if (grandChild) + return grandChild; + } + + return null; + } + property Component noAttachedPropertiesDelegate: Text { text: modelData } @@ -1112,4 +1131,49 @@ TestCase { var label = row.label; compare(label.text, "2"); } + + function test_positionViewAtIndex_data() { + return [ + // Should be 20, 21, ... but there is a documented limitation for this in positionViewAtIndex()'s docs. + { tag: "wrap=true, mode=Beginning", wrap: true, mode: Tumbler.Beginning, expectedVisibleIndices: [21, 22, 23, 24, 25] }, + { tag: "wrap=true, mode=Center", wrap: true, mode: Tumbler.Center, expectedVisibleIndices: [18, 19, 20, 21, 22] }, + { tag: "wrap=true, mode=End", wrap: true, mode: Tumbler.End, expectedVisibleIndices: [16, 17, 18, 19, 20] }, + // Same as Beginning; should start at 20. + { tag: "wrap=true, mode=Contain", wrap: true, mode: Tumbler.Contain, expectedVisibleIndices: [21, 22, 23, 24, 25] }, + { tag: "wrap=true, mode=SnapPosition", wrap: true, mode: Tumbler.SnapPosition, expectedVisibleIndices: [18, 19, 20, 21, 22] }, + { tag: "wrap=false, mode=Beginning", wrap: false, mode: Tumbler.Beginning, expectedVisibleIndices: [20, 21, 22, 23, 24] }, + { tag: "wrap=false, mode=Center", wrap: false, mode: Tumbler.Center, expectedVisibleIndices: [18, 19, 20, 21, 22] }, + { tag: "wrap=false, mode=End", wrap: false, mode: Tumbler.End, expectedVisibleIndices: [16, 17, 18, 19, 20] }, + { tag: "wrap=false, mode=Visible", wrap: false, mode: Tumbler.Visible, expectedVisibleIndices: [16, 17, 18, 19, 20] }, + { tag: "wrap=false, mode=Contain", wrap: false, mode: Tumbler.Contain, expectedVisibleIndices: [16, 17, 18, 19, 20] }, + { tag: "wrap=false, mode=SnapPosition", wrap: false, mode: Tumbler.SnapPosition, expectedVisibleIndices: [18, 19, 20, 21, 22] } + ] + } + + function test_positionViewAtIndex(data) { + createTumbler({ wrap: data.wrap, model: 40, visibleItemCount: 5 }) + compare(tumbler.wrap, data.wrap) + + waitForRendering(tumbler) + + tumbler.positionViewAtIndex(20, data.mode) + tryCompare(tumbler, "moving", false) + + compare(tumbler.visibleItemCount, 5) + for (var i = 0; i < 5; ++i) { + // Find the item through its text, as that's easier than child/itemAt(). + var text = data.expectedVisibleIndices[i].toString() + var item = findDelegateWithText(tumblerView, text) + verify(item, "found no item with text \"" + text + "\"") + compare(item.text, data.expectedVisibleIndices[i].toString()) + + // Ensure that it's at the position we expect. + var expectedPos = itemTopLeftPos(i) + var actualPos = testCase.mapFromItem(item, 0, 0) + compare(actualPos.x, expectedPos.x, "expected delegate with text " + item.text + + " to have an x pos of " + expectedPos.x + " but it was " + actualPos.x) + compare(actualPos.y, expectedPos.y, "expected delegate with text " + item.text + + " to have an y pos of " + expectedPos.y + " but it was " + actualPos.y) + } + } } |