diff options
author | Tor Arne Vestbø <[email protected]> | 2021-10-12 15:25:26 +0200 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2021-10-16 14:33:28 +0200 |
commit | 1dfc74970c8ab0bfc210b7038aad401189eae542 (patch) | |
tree | a85b88588e11a181ae97ee2e3aedef4bd452f8c7 /src/widgets/kernel/qwidgetwindow.cpp | |
parent | 30404b49d8cc9ad8c4d9f128952844c20da0ad0d (diff) |
Deduplicate lastWindowClosed handling
Whenever a window was closed, we had logic to check if it was the last
window, and if so emitted lastWindowClosed and then tried to quit the
application. But the automatic quit process also checked if there were
any remaining windows, as this process could be triggered as a result
of a QEventLoopLocker going out of scope. The two paths now share the
same logic for determining if there are any remaining windows.
The docs have been updated to reflect the original intent of the logic,
dealing only with primary windows (top levels without a transient parent).
This was how both the original code paths implemented their logic.
For historical reasons the Qt::WA_QuitOnClose attribute is closely
tied to the lastWindowClosed signal, and isn't merely limited to
controlling whether we try an automatic quit when the last window
closes. For now this behavior has been kept, but the docs have been
updated to clarify how the attribute is handled in practice.
Change-Id: If3d06b065236aad2e59e9091cac3146bc4cf79f6
Reviewed-by: Doris Verria <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'src/widgets/kernel/qwidgetwindow.cpp')
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 846300100ba..ba1230301e1 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -119,8 +119,7 @@ public: QWidgetPrivate::get(widget)->updateContentsRect(); } - bool shouldTriggerQuitOnClose() const override; - bool shouldCancelQuitOnClose() const override; + bool participatesInLastWindowClosed() const override; }; QRectF QWidgetWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const @@ -847,35 +846,18 @@ void QWidgetWindow::handleCloseEvent(QCloseEvent *event) event->setAccepted(accepted); } -bool QWidgetWindowPrivate::shouldTriggerQuitOnClose() const +bool QWidgetWindowPrivate::participatesInLastWindowClosed() const { Q_Q(const QWidgetWindow); - QWidget *widget = q->widget(); - // Closing a window without WA_QuitOnClose should stop us from even - // looking at the other windows. Otherwise we might find that all the - // other windows miss WA_QuitOnClose as well, and end up quitting, - // but that's not what the user intended. - if (!widget->testAttribute(Qt::WA_QuitOnClose)) + // For historical reasons WA_QuitOnClose has been closely tied + // to the lastWindowClosed signal, since the default behavior + // is to quit the application after emitting lastWindowClosed. + // ### Qt 7: Rename this attribute, or decouple behavior. + if (!q->widget()->testAttribute(Qt::WA_QuitOnClose)) return false; - // Qt::Tool windows do not have WA_QuitOnClose set by default, which - // means that if you open a dialog from one, and the tool window is - // the only remaining window, then closing the dialog would result - // in quitting the application. To prevent this we check if the - // closed widget has a visible parent (the Qt:Tool window in this - // case), and if so bail out. - if (widget->parentWidget() && widget->parentWidget()->isVisible()) - return false; - - return true; -} - -bool QWidgetWindowPrivate::shouldCancelQuitOnClose() const -{ - Q_Q(const QWidgetWindow); - QWidget *w = q->widget(); - return w->isVisible() && !w->parentWidget() & w->testAttribute(Qt::WA_QuitOnClose); + return QWindowPrivate::participatesInLastWindowClosed(); } #if QT_CONFIG(wheelevent) |