diff options
author | Nikita Krupenko <krnekit@gmail.com> | 2016-01-04 20:08:27 +0200 |
---|---|---|
committer | Nikita Krupenko <krnekit@gmail.com> | 2016-01-04 21:48:58 +0000 |
commit | cf58057988464f68e23c4d52598fd9de791f4af7 (patch) | |
tree | b76385eb9182cdbcc6ebcf42aac2b2aaad9df3de | |
parent | aa7a41c5ac4b93f00f41a405da9907660fd772a6 (diff) |
StackView: fix stack clear on replace of the topmost item
On item replace, StackView pops the topmost item (to use in transition)
and call QQuickStackViewPrivate::replaceElements(), which delete items
until it find the target item. When replacing the topmost item, it just
clear the whole stack, as the target item not in the stack already and
it procced to the bottom of the stack.
This commit changes StackView to use pushElements() for replacing the
topmost item, as there is nothing to replace.
Task-number: QTBUG-50274
Change-Id: Iff2e1177ee2f8b2d4518b519b450ae4e89a4c963
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r-- | src/templates/qquickstackview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_stackview.qml | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp index 2128f3b1..e127d79f 100644 --- a/src/templates/qquickstackview.cpp +++ b/src/templates/qquickstackview.cpp @@ -636,7 +636,7 @@ void QQuickStackView::replace(QQmlV4Function *args) if (!d->elements.isEmpty()) exit = d->elements.pop(); - if (d->replaceElements(target, elements)) { + if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) { if (depth != d->elements.count()) emit depthChanged(); QQuickStackElement *enter = d->elements.top(); diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml index aee82eec..2eb802bf 100644 --- a/tests/auto/controls/data/tst_stackview.qml +++ b/tests/auto/controls/data/tst_stackview.qml @@ -459,6 +459,22 @@ TestCase { compare(control.depth, 1) compare(control.currentItem, item6) + // replace the topmost item + control.push(component) + compare(control.depth, 2) + var item7 = control.replace(control.get(1), component, StackView.Immediate) + compare(control.depth, 2) + compare(control.currentItem, item7) + + // replace the item in the middle + control.push(component) + control.push(component) + control.push(component) + compare(control.depth, 5) + var item8 = control.replace(control.get(2), component, StackView.Immediate) + compare(control.depth, 3) + compare(control.currentItem, item8) + control.destroy() } |