aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-01-11 17:03:21 +0100
committerMitch Curtis <mitch.curtis@qt.io>2021-02-02 10:03:47 +0100
commit7e819a5777a0632175347688312da9cee0702177 (patch)
tree4e5be41000d252152253fda0495b03e96e22887d
parent180dbd050173d20c99f730eeacf2b0376fcb895e (diff)
Fix popups with exit transitions blocking mouse events when destroyed
If a popup had an exit transition set and was destroyed upon e.g. being rejected, it would not destroy its modal dimmer, and so events would not go through to popups that were beneath it even after it was destroyed. QQuickPopup's destructor does indirectly attempt to call finalizeExitTransition() through a setParentItem(nullptr) call, but prepareExitTransition() returns false if it sees that the exit transition is already running, and so transitionExit() never calls finished(). This patch fixes the problem by explicitly calling finalizeExitTransition() in QQuickPopup's destructor if the exit transition is running. Fixes: QTBUG-89673 Change-Id: I468fae52f6a83ac314877c67d062028634bb7e17 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 51d416cdfd909aacd5047632a7cc1661a158731a)
-rw-r--r--src/quicktemplates2/qquickpopup.cpp23
-rw-r--r--tests/auto/qquickpopup/data/destroyDuringExitTransition.qml114
-rw-r--r--tests/auto/qquickpopup/tst_qquickpopup.cpp30
3 files changed, 163 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index ff0d3be1..ab9740ba 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -51,6 +51,8 @@
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcDimmer, "qt.quick.controls.popup.dimmer")
+
/*!
\qmltype Popup
\inherits QtObject
@@ -499,8 +501,10 @@ void QQuickPopupPrivate::finalizeExitTransition()
{
Q_Q(QQuickPopup);
getPositioner()->setParentItem(nullptr);
- popupItem->setParentItem(nullptr);
- popupItem->setVisible(false);
+ if (popupItem) {
+ popupItem->setParentItem(nullptr);
+ popupItem->setVisible(false);
+ }
destroyOverlay();
if (hadActiveFocusBeforeExitTransition && window) {
@@ -531,8 +535,10 @@ void QQuickPopupPrivate::finalizeExitTransition()
hadActiveFocusBeforeExitTransition = false;
emit q->visibleChanged();
emit q->closed();
- popupItem->setScale(prevScale);
- popupItem->setOpacity(prevOpacity);
+ if (popupItem) {
+ popupItem->setScale(prevScale);
+ popupItem->setOpacity(prevOpacity);
+ }
}
QMarginsF QQuickPopupPrivate::getMargins() const
@@ -722,6 +728,8 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ
if (component)
component->completeCreate();
}
+ qCDebug(lcDimmer) << "finished creating dimmer from component" << component
+ << "for popup" << popup << "with parent" << parent << "- item is:" << item;
return item;
}
@@ -748,6 +756,7 @@ void QQuickPopupPrivate::createOverlay()
void QQuickPopupPrivate::destroyOverlay()
{
if (dimmer) {
+ qCDebug(lcDimmer) << "destroying dimmer" << dimmer;
dimmer->setParentItem(nullptr);
dimmer->deleteLater();
dimmer = nullptr;
@@ -846,6 +855,12 @@ QQuickPopup::~QQuickPopup()
d->popupItem = nullptr;
delete d->positioner;
d->positioner = nullptr;
+
+ // If the popup is destroyed before the exit transition finishes,
+ // the necessary cleanup (removing modal dimmers that block mouse events,
+ // emitting closed signal, etc.) won't happen. That's why we do it manually here.
+ if (d->transitionState == QQuickPopupPrivate::ExitTransition && d->transitionManager.isRunning())
+ d->finalizeExitTransition();
}
/*!
diff --git a/tests/auto/qquickpopup/data/destroyDuringExitTransition.qml b/tests/auto/qquickpopup/data/destroyDuringExitTransition.qml
new file mode 100644
index 00000000..ae72669f
--- /dev/null
+++ b/tests/auto/qquickpopup/data/destroyDuringExitTransition.qml
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+
+ApplicationWindow {
+ id: window
+ width: 400
+ height: 400
+ title: "destroyDuringExitTransition"
+
+ property Dialog dialog1
+ property Dialog dialog2
+
+ Component {
+ id: dlg
+
+ Dialog {
+ dim: true
+ modal: true
+ closePolicy: Popup.CloseOnEscape
+ visible: true
+
+ property alias button: button
+
+ Column {
+ Text {
+ text: "button is " + (button.down ? "down" : "up")
+ }
+
+ Button {
+ id: button
+ text: "Try to press this button"
+ }
+ }
+ }
+ }
+
+ Component {
+ id: brokenDlg
+ Dialog {
+ dim: true
+ modal: true
+ closePolicy: Popup.CloseOnEscape
+ visible: true
+
+ Text {
+ text: "Press Esc key to reject this dialog"
+ }
+
+ exit: Transition {
+ NumberAnimation { property: "opacity"; from: 1.0; to: 0.0; duration: 100 }
+ }
+ }
+ }
+
+
+ Component.onCompleted: {
+ dialog1 = dlg.createObject(window)
+ dialog2 = brokenDlg.createObject(window)
+
+ dialog2.onRejected.connect(function(){
+ dialog2.destroy()
+ })
+ }
+}
diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp
index 41955d7d..ede3640c 100644
--- a/tests/auto/qquickpopup/tst_qquickpopup.cpp
+++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp
@@ -96,6 +96,7 @@ private slots:
void tabFence();
void invisibleToolTipOpen();
void centerInOverlayWithinStackViewItem();
+ void destroyDuringExitTransition();
};
void tst_QQuickPopup::initTestCase()
@@ -1429,6 +1430,35 @@ void tst_QQuickPopup::centerInOverlayWithinStackViewItem()
// Shouldn't crash on exit.
}
+void tst_QQuickPopup::destroyDuringExitTransition()
+{
+ QQuickApplicationHelper helper(this, "destroyDuringExitTransition.qml");
+ QVERIFY2(helper.ready, helper.failureMessage());
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QPointer<QQuickPopup> dialog2 = window->property("dialog2").value<QQuickPopup*>();
+ QVERIFY(dialog2);
+ QTRY_COMPARE(dialog2->isVisible(), true);
+
+ // Close the second dialog, destroying it before its exit transition can finish.
+ QTest::keyClick(window, Qt::Key_Escape);
+ QTRY_VERIFY(!dialog2);
+
+ // Events should go through to the dialog underneath.
+ QQuickPopup *dialog1 = window->property("dialog1").value<QQuickPopup*>();
+ QVERIFY(dialog1);
+ QQuickButton *button = dialog1->property("button").value<QQuickButton*>();
+ QVERIFY(button);
+ const auto buttonClickPos = button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint();
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, buttonClickPos);
+ QVERIFY(button->isDown());
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, buttonClickPos);
+ QVERIFY(!button->isDown());
+}
+
QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup)
#include "tst_qquickpopup.moc"