diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-10-12 16:33:00 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-10-18 15:29:09 +0200 |
commit | df359bcb703db5a8adbf14e88ba4ae0d54f0cfcd (patch) | |
tree | 54c71f280fa4b5056f6ae3ad7f0aa61cabfcd82e /src/gui/kernel | |
parent | 55f8f916ce18047cb38e3512c7c5c87f7eb991d4 (diff) |
Decouple quitOnLastWindowClosed from quitLockEnabled
In a512e210ac5b032c5fc2edf1ddf72e5a414485fda512e21 quitOnLastWindowClosed
was changed to be implemented in terms of quitLockEnabled, but without
any documentation to that end.
Although the two features are similar (automatic quit under certain
conditions), and interact, it doesn't make sense to overlap them until
we actually expose them as a single property (automaticQuit e.g.)
The logic for determining whether we can can quit automatically has
been refactored to take both properties into account, on both a Core
and Gui level. The call sites still need to check the individual
properties to determine whether to activate automatic quit for
that particular code path.
Change-Id: I38c3e8cb30db373ea73dd45f150e5048c0db2f4d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 17 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 3 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2ca1ff0a44..8f9c2bd996 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -210,6 +210,8 @@ qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0; static qreal fontSmoothingGamma = 1.7; +bool QGuiApplicationPrivate::quitOnLastWindowClosed = true; + extern void qRegisterGuiVariant(); #if QT_CONFIG(animation) extern void qRegisterGuiGetInterpolator(); @@ -3538,12 +3540,12 @@ void QGuiApplicationPrivate::notifyWindowIconChanged() void QGuiApplication::setQuitOnLastWindowClosed(bool quit) { - QCoreApplication::setQuitLockEnabled(quit); + QGuiApplicationPrivate::quitOnLastWindowClosed = quit; } bool QGuiApplication::quitOnLastWindowClosed() { - return QCoreApplication::isQuitLockEnabled(); + return QGuiApplicationPrivate::quitOnLastWindowClosed; } void QGuiApplicationPrivate::maybeLastWindowClosed(QWindow *closedWindow) @@ -3561,8 +3563,8 @@ void QGuiApplicationPrivate::maybeLastWindowClosed(QWindow *closedWindow) if (in_exec) emit q_func()->lastWindowClosed(); - if (QGuiApplication::quitOnLastWindowClosed()) - maybeQuit(); + if (quitOnLastWindowClosed && canQuitAutomatically()) + quitAutomatically(); } /*! @@ -3591,9 +3593,12 @@ bool QGuiApplicationPrivate::lastWindowClosed() const return true; } -bool QGuiApplicationPrivate::shouldQuit() +bool QGuiApplicationPrivate::canQuitAutomatically() { - return lastWindowClosed(); + if (quitOnLastWindowClosed && !lastWindowClosed()) + return false; + + return QCoreApplicationPrivate::canQuitAutomatically(); } void QGuiApplicationPrivate::quit() diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index d43bfd755e..92d69f4a76 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -105,11 +105,12 @@ public: #if QT_CONFIG(commandlineparser) void addQtOptions(QList<QCommandLineOption> *options) override; #endif - virtual bool shouldQuit() override; + bool canQuitAutomatically() override; void quit() override; void maybeLastWindowClosed(QWindow *closedWindow); bool lastWindowClosed() const; + static bool quitOnLastWindowClosed; static void captureGlobalModifierState(QEvent *e); static Qt::KeyboardModifiers modifier_buttons; |