diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-06 09:31:22 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-12-06 11:24:05 +0000 |
commit | 1bcd068c082b3fab92637686447c2c82b4a0968c (patch) | |
tree | 218351c814a784cfa92a7ade55195574f7be4ebc /src/quicktemplates2 | |
parent | 3bea717006ae660a933025514f21b7810262535a (diff) |
StackView: don’t push duplicate items
It doesn’t make sense to do this.
Task-number: QTBUG-57266
Change-Id: I23f740356f2727a59aa0a68cb57d2c44edfb6046
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickstackview.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index d16d7b16..07c471b5 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -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()); |