diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-10-29 15:50:39 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-11-02 15:23:50 +0000 |
commit | 497ac61380d4b6ebfef88923131f61d648857943 (patch) | |
tree | 90f8cb1c4de949ffacedac5c23427508814d1b3b | |
parent | 2ee0e8770bf43182aae7fd4420e7bd986ecdd68e (diff) |
Fix StackView::busy and child event filtering
1) renamed busy() to isBusy() to follow the Qt convention :)
2) fixed spurious busyChanged() emissions (it was always emitted on
push/replace/pop even when the state didn't change (null transitions)
3) with null transitions, the child event filter was never turned off
and therefore StackView "froze" after the first push/replace/pop
Change-Id: I07fffa73db5a182865c7b2779641e1f95ed8b30b
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r-- | src/templates/qquickstackview.cpp | 4 | ||||
-rw-r--r-- | src/templates/qquickstackview_p.cpp | 32 | ||||
-rw-r--r-- | src/templates/qquickstackview_p.h | 4 | ||||
-rw-r--r-- | src/templates/qquickstackview_p_p.h | 1 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_stackview.qml | 154 |
5 files changed, 175 insertions, 20 deletions
diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp index 075830a4..2dcae1a1 100644 --- a/src/templates/qquickstackview.cpp +++ b/src/templates/qquickstackview.cpp @@ -292,10 +292,10 @@ QQuickStackAttached *QQuickStackView::qmlAttachedProperties(QObject *object) \readonly This property holds whether a transition is running. */ -bool QQuickStackView::busy() const +bool QQuickStackView::isBusy() const { Q_D(const QQuickStackView); - return d->transitioner && !d->transitioner->runningJobs.isEmpty(); + return d->busy; } /*! diff --git a/src/templates/qquickstackview_p.cpp b/src/templates/qquickstackview_p.cpp index 9ee0bdb3..1a08d349 100644 --- a/src/templates/qquickstackview_p.cpp +++ b/src/templates/qquickstackview_p.cpp @@ -241,7 +241,7 @@ void QQuickStackElement::itemDestroyed(QQuickItem *) item = Q_NULLPTR; } -QQuickStackViewPrivate::QQuickStackViewPrivate() : currentItem(Q_NULLPTR), transitioner(Q_NULLPTR) +QQuickStackViewPrivate::QQuickStackViewPrivate() : busy(false), currentItem(Q_NULLPTR), transitioner(Q_NULLPTR) { } @@ -417,11 +417,10 @@ void QQuickStackViewPrivate::popTransition(QQuickStackElement *enter, QQuickStac enter->startTransition(transitioner); } - if (!immediate) - setBusy(true); - - if (transitioner) + if (transitioner) { + setBusy(!transitioner->runningJobs.isEmpty()); transitioner->resetTargetLists(); + } } void QQuickStackViewPrivate::pushTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate) @@ -450,11 +449,10 @@ void QQuickStackViewPrivate::pushTransition(QQuickStackElement *enter, QQuickSta exit->startTransition(transitioner); } - if (!immediate) - setBusy(true); - - if (transitioner) + if (transitioner) { + setBusy(!transitioner->runningJobs.isEmpty()); transitioner->resetTargetLists(); + } } void QQuickStackViewPrivate::replaceTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate) @@ -484,11 +482,10 @@ void QQuickStackViewPrivate::replaceTransition(QQuickStackElement *enter, QQuick enter->startTransition(transitioner); } - if (!immediate) - setBusy(true); - - if (transitioner) + if (transitioner) { + setBusy(!transitioner->runningJobs.isEmpty()); transitioner->resetTargetLists(); + } } void QQuickStackViewPrivate::completeTransition(QQuickStackElement *element, QQuickTransition *transition) @@ -525,11 +522,14 @@ void QQuickStackViewPrivate::viewItemTransitionFinished(QQuickItemViewTransition } } -void QQuickStackViewPrivate::setBusy(bool busy) +void QQuickStackViewPrivate::setBusy(bool b) { Q_Q(QQuickStackView); - q->setFiltersChildMouseEvents(busy); - emit q->busyChanged(); + if (busy != b) { + busy = b; + q->setFiltersChildMouseEvents(busy); + emit q->busyChanged(); + } } QT_END_NAMESPACE diff --git a/src/templates/qquickstackview_p.h b/src/templates/qquickstackview_p.h index e3121bf9..be73ea85 100644 --- a/src/templates/qquickstackview_p.h +++ b/src/templates/qquickstackview_p.h @@ -61,7 +61,7 @@ class QQuickStackViewPrivate; class Q_LABSTEMPLATES_EXPORT QQuickStackView : public QQuickControl { Q_OBJECT - Q_PROPERTY(bool busy READ busy NOTIFY busyChanged FINAL) + Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged FINAL) Q_PROPERTY(int depth READ depth NOTIFY depthChanged FINAL) Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) Q_PROPERTY(QVariant initialItem READ initialItem WRITE setInitialItem FINAL) @@ -78,7 +78,7 @@ public: static QQuickStackAttached *qmlAttachedProperties(QObject *object); - bool busy() const; + bool isBusy() const; int depth() const; QQuickItem *currentItem() const; diff --git a/src/templates/qquickstackview_p_p.h b/src/templates/qquickstackview_p_p.h index 5dfe7037..94919939 100644 --- a/src/templates/qquickstackview_p_p.h +++ b/src/templates/qquickstackview_p_p.h @@ -132,6 +132,7 @@ public: void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) Q_DECL_OVERRIDE; void setBusy(bool busy); + bool busy; QVariant initialItem; QQuickItem *currentItem; QList<QQuickStackElement*> removals; diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml index 22d4cfe3..23eaf317 100644 --- a/tests/auto/controls/data/tst_stackview.qml +++ b/tests/auto/controls/data/tst_stackview.qml @@ -87,18 +87,63 @@ TestCase { control.destroy() } + SignalSpy { + id: busySpy + signalName: "busyChanged" + } + function test_busy() { var control = stackView.createObject(testCase) verify(control) compare(control.busy, false) + + var busyCount = 0 + busySpy.target = control + verify(busySpy.valid) + control.push(component) compare(control.busy, false) + compare(busySpy.count, busyCount) + control.push(component) compare(control.busy, true) + compare(busySpy.count, ++busyCount) + tryCompare(control, "busy", false) + compare(busySpy.count, ++busyCount) + + control.replace(component) + compare(control.busy, true) + compare(busySpy.count, ++busyCount) tryCompare(control, "busy", false) + compare(busySpy.count, ++busyCount) + control.pop() compare(control.busy, true) + compare(busySpy.count, ++busyCount) tryCompare(control, "busy", false) + compare(busySpy.count, ++busyCount) + + control.pushEnter = null + control.pushExit = null + + control.push(component) + compare(control.busy, false) + compare(busySpy.count, busyCount) + + control.replaceEnter = null + control.replaceExit = null + + control.replace(component) + compare(control.busy, false) + compare(busySpy.count, busyCount) + + control.popEnter = null + control.popExit = null + + control.pop() + compare(control.busy, false) + compare(busySpy.count, busyCount) + control.destroy() } @@ -590,4 +635,113 @@ TestCase { control.destroy() } + + Component { + id: testButton + Button { + property int clicks: 0 + onClicked: ++clicks + } + } + + function test_interaction() { + var control = stackView.createObject(testCase, {initialItem: testButton, width: testCase.width, height: testCase.height}) + verify(control) + + var firstButton = control.currentItem + verify(firstButton) + + var firstClicks = 0 + var secondClicks = 0 + var thirdClicks = 0 + + // push - default transition + var secondButton = control.push(testButton) + compare(control.busy, true) + mouseClick(firstButton) // filtered while busy + mouseClick(secondButton) // filtered while busy + compare(firstButton.clicks, firstClicks) + compare(secondButton.clicks, secondClicks) + tryCompare(control, "busy", false) + mouseClick(secondButton) + compare(secondButton.clicks, ++secondClicks) + + // replace - default transition + var thirdButton = control.replace(testButton) + compare(control.busy, true) + mouseClick(secondButton) // filtered while busy + mouseClick(thirdButton) // filtered while busy + compare(secondButton.clicks, secondClicks) + compare(thirdButton.clicks, thirdClicks) + tryCompare(control, "busy", false) + secondButton = null + secondClicks = 0 + mouseClick(thirdButton) + compare(thirdButton.clicks, ++thirdClicks) + + // pop - default transition + control.pop() + compare(control.busy, true) + mouseClick(firstButton) // filtered while busy + mouseClick(thirdButton) // filtered while busy + compare(firstButton.clicks, firstClicks) + compare(thirdButton.clicks, thirdClicks) + tryCompare(control, "busy", false) + thirdButton = null + thirdClicks = 0 + mouseClick(firstButton) + compare(firstButton.clicks, ++firstClicks) + + // push - immediate operation + secondButton = control.push(testButton, StackView.Immediate) + compare(control.busy, false) + mouseClick(secondButton) + compare(secondButton.clicks, ++secondClicks) + + // replace - immediate operation + thirdButton = control.replace(testButton, StackView.Immediate) + compare(control.busy, false) + secondButton = null + secondClicks = 0 + mouseClick(thirdButton) + compare(thirdButton.clicks, ++thirdClicks) + + // pop - immediate operation + control.pop(StackView.Immediate) + compare(control.busy, false) + thirdButton = null + thirdClicks = 0 + mouseClick(firstButton) + compare(firstButton.clicks, ++firstClicks) + + // push - null transition + control.pushEnter = null + control.pushExit = null + secondButton = control.push(testButton) + compare(control.busy, false) + mouseClick(secondButton) + compare(secondButton.clicks, ++secondClicks) + + // replace - null transition + control.replaceEnter = null + control.replaceExit = null + thirdButton = control.replace(testButton) + compare(control.busy, false) + secondButton = null + secondClicks = 0 + mouseClick(thirdButton) + compare(thirdButton.clicks, ++thirdClicks) + + // pop - null transition + control.popEnter = null + control.popExit = null + control.pop() + compare(control.busy, false) + thirdButton = null + thirdClicks = 0 + mouseClick(firstButton) + compare(firstButton.clicks, ++firstClicks) + + control.destroy() + } } |