diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-18 10:57:18 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-18 16:28:07 +0200 |
commit | 838b9ee9fe3ad26e5b1fac1616cb575288f4f8a1 (patch) | |
tree | cf0c64ccea98950de7846e39d2e0e65580c0f64a | |
parent | c23afb324708af2489a88a187d88b23d0e884eb3 (diff) |
StackView: emit depthChanged when clearing with transition
When a transition is used in the call to clear(), then we pop the top
element off the stack and start the transition for it. If we read the
old depth after doing that, then it will be off by one and prevent the
emission of the changed signal if that was the last element on the
stack.
So read the old depth already before we pop, and add a test.
Fixes: QTBUG-84920
Pick-to: 6.5 6.2
Change-Id: Idae619efa25729fafbf238cb4db62472042b1cb7
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
-rw-r--r-- | src/quicktemplates/qquickstackview.cpp | 3 | ||||
-rw-r--r-- | tests/auto/quickcontrols/controls/data/tst_stackview.qml | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/quicktemplates/qquickstackview.cpp b/src/quicktemplates/qquickstackview.cpp index d232ae5b84..01b1386822 100644 --- a/src/quicktemplates/qquickstackview.cpp +++ b/src/quicktemplates/qquickstackview.cpp @@ -925,6 +925,8 @@ void QQuickStackView::clear(Operation operation) return; } + const int oldDepth = d->elements.size(); + QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true); QScopedValueRollback<QString> operationNameRollback(d->operation, operationName); #if QT_CONFIG(quick_viewtransitions) @@ -937,7 +939,6 @@ void QQuickStackView::clear(Operation operation) } #endif - int oldDepth = d->elements.size(); d->setCurrentItem(nullptr); qDeleteAll(d->elements); d->elements.clear(); diff --git a/tests/auto/quickcontrols/controls/data/tst_stackview.qml b/tests/auto/quickcontrols/controls/data/tst_stackview.qml index 8584385cbf..eebaeb357f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_stackview.qml +++ b/tests/auto/quickcontrols/controls/data/tst_stackview.qml @@ -253,6 +253,15 @@ TestCase { compare(depthSpy.count, depthChanges) compare(control.empty, true) compare(emptySpy.count, emptyChanges) + + control.push(item, StackView.PushTransition) + compare(depthSpy.count, ++depthChanges) + compare(emptySpy.count, ++emptyChanges) + compare(control.depth, 1) + control.clear(StackView.PopTransition) + compare(depthSpy.count, ++depthChanges) + compare(emptySpy.count, ++emptyChanges) + compare(control.depth, 0) } function test_size() { |