diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-09-03 15:06:59 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-09-17 14:56:19 +0200 |
commit | 28b14b966fe8535d7a81914b70759546b694e31b (patch) | |
tree | 707f4b0702242cf4a7e01e5003d9772e8bb1a703 /src/gui/kernel/qguiapplication.cpp | |
parent | 1b0cb842129616d67ddf279e7e900fcdf433e390 (diff) |
Deduplicate maybeQuitOnLastWindowClosed handling
The functionality now lives in QGuiApplication, and is triggered
by QGuiApplication and QApplication after dispatching the close
event to the window.
The slight difference between how a Qt GUI and Qt Widget app
determines if a window should contribute to the close-on-quit
behavior has been abstracted into a QWindowPrivate helper.
The additional checks that were in place for skipping out of
the whole maybeQuitOnLastWindowClosed machinery have been kept.
Task-number: QTBUG-53286
Change-Id: I81bd474755f9adb3a2b082621e5ecaa1c4726808
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 98b5ea03e6..294684584b 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1918,6 +1918,8 @@ void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e) */ bool QGuiApplication::notify(QObject *object, QEvent *event) { + Q_D(QGuiApplication); + if (object->isWindowType()) { if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(object), event)) return true; // Platform plugin ate the event @@ -1925,7 +1927,12 @@ bool QGuiApplication::notify(QObject *object, QEvent *event) QGuiApplicationPrivate::captureGlobalModifierState(event); - return QCoreApplication::notify(object, event); + bool accepted = QCoreApplication::notify(object, event); + + if (event->type() == QEvent::Close && object->isWindowType() && accepted) + d->maybeQuitOnLastWindowClosed(static_cast<QWindow*>(object)); + + return accepted; } /*! \reimp @@ -3533,13 +3540,30 @@ void QGuiApplication::setQuitOnLastWindowClosed(bool quit) QCoreApplication::setQuitLockEnabled(quit); } - - bool QGuiApplication::quitOnLastWindowClosed() { return QCoreApplication::isQuitLockEnabled(); } +void QGuiApplicationPrivate::maybeQuitOnLastWindowClosed(QWindow *closedWindow) +{ + Q_ASSERT(closedWindow); + + if (!qt_window_private(closedWindow)->shouldTriggerQuitOnClose()) + return; + + // Check if there are any remaining windows that should prevent us from quitting + for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) { + auto *windowPrivate = qt_window_private(topLevelWindow); + if (windowPrivate->shouldCancelQuitOnClose()) + return; + } + + emitLastWindowClosed(); + + if (QGuiApplication::quitOnLastWindowClosed()) + maybeQuit(); +} /*! \fn void QGuiApplication::lastWindowClosed() |