diff options
-rw-r--r-- | src/quicktemplates2/qquickstackview.cpp | 17 | ||||
-rw-r--r-- | src/quicktemplates2/qquickstackview_p.cpp | 7 | ||||
-rw-r--r-- | src/quicktemplates2/qquickstackview_p_p.h | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_stackview.qml | 51 |
4 files changed, 58 insertions, 19 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index ee975056..3767d143 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -516,8 +516,9 @@ void QQuickStackView::push(QQmlV4Function *args) if (!d->elements.isEmpty()) exit = d->elements.top(); + int oldDepth = d->elements.count(); if (d->pushElements(elements)) { - d->depthChange(); + d->depthChange(d->elements.count(), oldDepth); QQuickStackElement *enter = d->elements.top(); d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this), QQuickStackTransition::pushExit(operation, exit, this), @@ -574,6 +575,7 @@ void QQuickStackView::pop(QQmlV4Function *args) return; } + int oldDepth = d->elements.count(); QQuickStackElement *exit = d->elements.pop(); QQuickStackElement *enter = d->elements.top(); @@ -612,7 +614,7 @@ void QQuickStackView::pop(QQmlV4Function *args) d->removing.insert(exit); previousItem = exit->item; } - d->depthChange(); + d->depthChange(d->elements.count(), oldDepth); d->startTransition(QQuickStackTransition::popExit(operation, exit, this), QQuickStackTransition::popEnter(operation, enter, this), operation == Immediate); @@ -752,14 +754,13 @@ void QQuickStackView::replace(QQmlV4Function *args) return; } - int depth = d->elements.count(); + int oldDepth = d->elements.count(); QQuickStackElement* exit = nullptr; if (!d->elements.isEmpty()) exit = d->elements.pop(); if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) { - if (depth != d->elements.count()) - d->depthChange(); + d->depthChange(d->elements.count(), oldDepth); if (exit) { exit->removal = true; d->removing.insert(exit); @@ -820,10 +821,11 @@ void QQuickStackView::clear(Operation operation) QQuickStackTransition::popEnter(operation, nullptr, this), false); } + int oldDepth = d->elements.count(); d->setCurrentItem(nullptr); qDeleteAll(d->elements); d->elements.clear(); - d->depthChange(); + d->depthChange(0, oldDepth); } /*! @@ -1020,6 +1022,7 @@ void QQuickStackView::componentComplete() QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("initialItem")); QQuickStackElement *element = nullptr; QString error; + int oldDepth = d->elements.count(); if (QObject *o = d->initialItem.value<QObject *>()) element = QQuickStackElement::fromObject(o, this, &error); else if (d->initialItem.canConvert<QString>()) @@ -1027,7 +1030,7 @@ void QQuickStackView::componentComplete() if (!error.isEmpty()) { d->warn(error); } else if (d->pushElement(element)) { - d->depthChange(); + d->depthChange(d->elements.count(), oldDepth); d->setCurrentItem(element); element->setStatus(QQuickStackView::Active); } diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp index 69ad7848..f4405246 100644 --- a/src/quicktemplates2/qquickstackview_p.cpp +++ b/src/quicktemplates2/qquickstackview_p.cpp @@ -297,11 +297,14 @@ void QQuickStackViewPrivate::setBusy(bool b) emit q->busyChanged(); } -void QQuickStackViewPrivate::depthChange() +void QQuickStackViewPrivate::depthChange(int newDepth, int oldDepth) { Q_Q(QQuickStackView); + if (newDepth == oldDepth) + return; + emit q->depthChanged(); - if (elements.count() <= 1) + if (newDepth == 0 || oldDepth == 0) emit q->emptyChanged(); } diff --git a/src/quicktemplates2/qquickstackview_p_p.h b/src/quicktemplates2/qquickstackview_p_p.h index 871891aa..d86f35cd 100644 --- a/src/quicktemplates2/qquickstackview_p_p.h +++ b/src/quicktemplates2/qquickstackview_p_p.h @@ -92,7 +92,7 @@ public: void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override; void setBusy(bool busy); - void depthChange(); + void depthChange(int newDepth, int oldDepth); bool busy; QString operation; diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml index 77929a0a..097180b8 100644 --- a/tests/auto/controls/data/tst_stackview.qml +++ b/tests/auto/controls/data/tst_stackview.qml @@ -221,42 +221,75 @@ TestCase { function test_depth() { var control = createTemporaryObject(stackView, testCase) verify(control) + + var depthChanges = 0 + var emptyChanges = 0 var depthSpy = signalSpy.createObject(control, {target: control, signalName: "depthChanged"}) + var emptySpy = signalSpy.createObject(control, {target: control, signalName: "emptyChanged"}) verify(depthSpy.valid) + verify(emptySpy.valid) compare(control.depth, 0) compare(control.empty, true) + control.push(item, StackView.Immediate) compare(control.depth, 1) - compare(depthSpy.count, 1) + compare(depthSpy.count, ++depthChanges) compare(control.empty, false) + compare(emptySpy.count, ++emptyChanges) + control.clear() compare(control.depth, 0) - compare(depthSpy.count, 2) + compare(depthSpy.count, ++depthChanges) compare(control.empty, true) + compare(emptySpy.count, ++emptyChanges) + control.push(component, StackView.Immediate) compare(control.depth, 1) - compare(depthSpy.count, 3) + compare(depthSpy.count, ++depthChanges) compare(control.empty, false) + compare(emptySpy.count, ++emptyChanges) + control.push(component, StackView.Immediate) compare(control.depth, 2) - compare(depthSpy.count, 4) + compare(depthSpy.count, ++depthChanges) compare(control.empty, false) - control.pop(StackView.Immediate) + compare(emptySpy.count, emptyChanges) + + control.replace(component, StackView.Immediate) + compare(control.depth, 2) + compare(depthSpy.count, depthChanges) + compare(control.empty, false) + compare(emptySpy.count, emptyChanges) + + control.replace([component, component], StackView.Immediate) + compare(control.depth, 3) + compare(depthSpy.count, ++depthChanges) + compare(control.empty, false) + compare(emptySpy.count, emptyChanges) + + control.pop(null, StackView.Immediate) compare(control.depth, 1) - compare(depthSpy.count, 5) + compare(depthSpy.count, ++depthChanges) compare(control.empty, false) + compare(emptySpy.count, emptyChanges) + control.pop(StackView.Immediate) // ignored compare(control.depth, 1) - compare(depthSpy.count, 5) + compare(depthSpy.count, depthChanges) compare(control.empty, false) + compare(emptySpy.count, emptyChanges) + control.clear() compare(control.depth, 0) - compare(depthSpy.count, 6) + compare(depthSpy.count, ++depthChanges) compare(control.empty, true) + compare(emptySpy.count, ++emptyChanges) + control.clear() compare(control.depth, 0) - compare(depthSpy.count, 6) + compare(depthSpy.count, depthChanges) compare(control.empty, true) + compare(emptySpy.count, emptyChanges) } function test_size() { |