aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickstackview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickstackview.cpp')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index d16d7b16..a7853df7 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
@@ -464,6 +464,8 @@ QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavio
\value StackView.ReplaceTransition An operation with replace transitions (since QtQuick.Controls 2.1).
\value StackView.PopTransition An operation with pop transitions (since QtQuick.Controls 2.1).
+ \note Items that already exist in the stack are not pushed.
+
\sa initialItem, {Pushing Items}
*/
void QQuickStackView::push(QQmlV4Function *args)
@@ -484,6 +486,15 @@ void QQuickStackView::push(QQmlV4Function *args)
operation = static_cast<Operation>(lastArg->toInt32());
QList<QQuickStackElement *> elements = d->parseElements(args);
+ // Remove any items that are already in the stack, as they can't be in two places at once.
+ for (int i = 0; i < elements.size(); ) {
+ QQuickStackElement *element = elements.at(i);
+ if (element->item && d->findElement(element->item))
+ elements.removeAt(i);
+ else
+ ++i;
+ }
+
if (elements.isEmpty()) {
qmlInfo(this) << "push: nothing to push";
args->setReturnValue(QV4::Encode::null());