diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2011-10-26 13:29:51 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-31 23:22:15 +0100 |
commit | a512e210ac5b032c5fc2edf1ddf72e5a414485fd (patch) | |
tree | 0e9615f317fe5c24bd002155b205a01d5716a1d3 /src/widgets | |
parent | 36a590c90ddab6fa438b7b54b05d89e8f9698a52 (diff) |
Add the event loop quitlock feature to QtCore.
A feature of a ref-counted quit (managed by a quit-lock class)
is added to both QEventLoop and QCoreApplication.
This allows, for example, an event loop to quit() when there is
no more work for it to do.
quitOnLastWindowClosed is implemented in terms of the refcount in
QCoreApplication so that jobs can be completed before the
application quits.
Change-Id: I14c8f4e7ee12bbf81a6e5849290d4c8ff37fa110
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 20 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication_p.h | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 19 |
3 files changed, 6 insertions, 35 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index f4d2856dbe..b0781c2064 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -143,8 +143,6 @@ QApplicationPrivate *QApplicationPrivate::self = 0; QInputContext *QApplicationPrivate::inputContext = 0; -bool QApplicationPrivate::quitOnLastWindowClosed = true; - #ifdef Q_WS_WINCE int QApplicationPrivate::autoMaximizeThreshold = -1; bool QApplicationPrivate::autoSipEnabled = false; @@ -161,8 +159,6 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T is_session_restored = false; #endif - quitOnLastWindowClosed = true; - #if defined(Q_WS_QWS) && !defined(QT_NO_DIRECTPAINTER) directPainters = 0; #endif @@ -4621,24 +4617,12 @@ bool QApplicationPrivate::inPopupMode() const void QApplication::setQuitOnLastWindowClosed(bool quit) { - QApplicationPrivate::quitOnLastWindowClosed = quit; + QCoreApplication::setQuitLockEnabled(quit); } bool QApplication::quitOnLastWindowClosed() { - return QApplicationPrivate::quitOnLastWindowClosed; -} - -void QApplicationPrivate::emitLastWindowClosed() -{ - if (qApp && qApp->d_func()->in_exec) { - if (QApplicationPrivate::quitOnLastWindowClosed) { - // get ready to quit, this event might be removed if the - // event loop is re-entered, however - QApplication::postEvent(qApp, new QEvent(QEvent::Quit)); - } - emit qApp->lastWindowClosed(); - } + return QCoreApplication::isQuitLockEnabled(); } /*! \variable QApplication::NormalColors diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index eccc1b8442..b6fbfa1684 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -188,8 +188,6 @@ public: static bool qws_apply_settings(); static QWidget *findWidget(const QObjectList&, const QPoint &, bool rec); #endif - static bool quitOnLastWindowClosed; - static void emitLastWindowClosed(); #ifdef Q_WS_WINCE static int autoMaximizeThreshold; #endif diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index a8f3808dce..e004e15252 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -92,6 +92,7 @@ #include <private/qpaintengine_raster_p.h> #include "qwidget_p.h" +#include <QtGui/private/qwindow_p.h> #include "qaction_p.h" #include "qlayout_p.h" #include "QtWidgets/qgraphicsproxywidget.h" @@ -7434,23 +7435,11 @@ bool QWidgetPrivate::close_helper(CloseMode mode) // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible()); - if (quitOnClose) { - /* if there is no non-withdrawn primary window left (except - the ones without QuitOnClose), we emit the lastWindowClosed - signal */ - QWidgetList list = QApplication::topLevelWidgets(); - bool lastWindowClosed = true; - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); - if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose)) - continue; - lastWindowClosed = false; - break; - } - if (lastWindowClosed) - QApplicationPrivate::emitLastWindowClosed(); + if (quitOnClose && q->windowHandle()) { + static_cast<QWindowPrivate*>(QObjectPrivate::get(q->windowHandle()))->maybeQuitOnLastWindowClosed(); } + if (!that.isNull()) { data.is_closing = 0; if (q->testAttribute(Qt::WA_DeleteOnClose)) { |