diff options
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 95 |
1 files changed, 41 insertions, 54 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index e20e820f12..aa2ac25c25 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -65,6 +65,7 @@ #include <QtGui/qstylehints.h> #include <QtGui/qinputmethod.h> #include <QtGui/private/qwindow_p.h> +#include <QtGui/qtouchdevice.h> #include <qpa/qplatformtheme.h> #ifndef QT_NO_WHATSTHIS #include <QtWidgets/QWhatsThis> @@ -1124,9 +1125,9 @@ QStyle *QApplication::style() QStyle *&app_style = QApplicationPrivate::app_style; app_style = QStyleFactory::create(style); if (!app_style) { - QStringList styles = QStyleFactory::keys(); - for (int i = 0; i < styles.size(); ++i) { - if ((app_style = QStyleFactory::create(styles.at(i)))) + const QStringList styles = QStyleFactory::keys(); + for (const auto &style : styles) { + if ((app_style = QStyleFactory::create(style))) break; } } @@ -1367,7 +1368,7 @@ int QApplication::colorSpec() void QApplication::setColorSpec(int spec) { - if (qApp) + if (Q_UNLIKELY(qApp)) qWarning("QApplication::setColorSpec: This function must be " "called before the QApplication object is created"); QApplicationPrivate::app_cspec = spec; @@ -1741,8 +1742,7 @@ void QApplicationPrivate::notifyWindowIconChanged() QWindowList windowList = QGuiApplication::topLevelWindows(); // send to all top-level QWidgets - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + for (auto *w : list) { windowList.removeOne(w->windowHandle()); QCoreApplication::sendEvent(w, &ev); } @@ -1904,9 +1904,9 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows processedWindows->append(window); } - QWidgetList list = QApplication::topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); +retry: + const QWidgetList list = QApplication::topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_DontShowOnScreen) && !w->data->is_closing) { QWindow *window = w->windowHandle(); @@ -1914,8 +1914,7 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows return false; if (window) processedWindows->append(window); - list = QApplication::topLevelWidgets(); - i = -1; + goto retry; } } return true; @@ -1994,9 +1993,8 @@ bool QApplication::event(QEvent *e) ce->accept(); closeAllWindows(); - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) && (!(w->windowType() == Qt::Dialog) || !w->parentWidget())) { ce->ignore(); @@ -2010,9 +2008,8 @@ bool QApplication::event(QEvent *e) } else if (e->type() == QEvent::LocaleChange) { // on Windows the event propagation is taken care by the // WM_SETTINGCHANGE event handler. - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (!(w->windowType() == Qt::Desktop)) { if (!w->testAttribute(Qt::WA_SetLocale)) w->d_func()->setLocale_helper(QLocale(), true); @@ -2056,9 +2053,8 @@ bool QApplication::event(QEvent *e) } if(e->type() == QEvent::LanguageChange) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (!(w->windowType() == Qt::Desktop)) postEvent(w, new QEvent(QEvent::LanguageChange)); } @@ -2084,8 +2080,7 @@ void QApplicationPrivate::notifyLayoutDirectionChange() QWindowList windowList = QGuiApplication::topLevelWindows(); // send to all top-level QWidgets - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + for (auto *w : list) { windowList.removeAll(w->windowHandle()); QEvent ev(QEvent::ApplicationLayoutDirectionChange); QCoreApplication::sendEvent(w, &ev); @@ -2136,9 +2131,8 @@ void QApplication::setActiveWindow(QWidget* act) if (QApplicationPrivate::active_window) { if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->isActiveWindow()) toBeDeactivated.append(w); } @@ -2159,9 +2153,8 @@ void QApplication::setActiveWindow(QWidget* act) if (QApplicationPrivate::active_window) { if (style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, QApplicationPrivate::active_window)) { - QWidgetList list = topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); + const QWidgetList list = topLevelWidgets(); + for (auto *w : list) { if (w->isVisible() && w->isActiveWindow()) toBeActivated.append(w); } @@ -2319,7 +2312,6 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con return; #endif - QWidget* w ; if ((!enter && !leave) || (enter == leave)) return; #ifdef ALIEN_DEBUG @@ -2330,25 +2322,25 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con bool sameWindow = leave && enter && leave->window() == enter->window(); if (leave && !sameWindow) { - w = leave; + auto *w = leave; do { leaveList.append(w); } while (!w->isWindow() && (w = w->parentWidget())); } if (enter && !sameWindow) { - w = enter; + auto *w = enter; do { - enterList.prepend(w); + enterList.append(w); } while (!w->isWindow() && (w = w->parentWidget())); } if (sameWindow) { int enterDepth = 0; int leaveDepth = 0; - w = enter; - while (!w->isWindow() && (w = w->parentWidget())) + auto *e = enter; + while (!e->isWindow() && (e = e->parentWidget())) enterDepth++; - w = leave; - while (!w->isWindow() && (w = w->parentWidget())) + auto *l = leave; + while (!l->isWindow() && (l = l->parentWidget())) leaveDepth++; QWidget* wenter = enter; QWidget* wleave = leave; @@ -2365,21 +2357,16 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con wleave = wleave->parentWidget(); } - w = leave; - while (w != wleave) { + for (auto *w = leave; w != wleave; w = w->parentWidget()) leaveList.append(w); - w = w->parentWidget(); - } - w = enter; - while (w != wenter) { - enterList.prepend(w); - w = w->parentWidget(); - } + + for (auto *w = enter; w != wenter; w = w->parentWidget()) + enterList.append(w); } QEvent leaveEvent(QEvent::Leave); for (int i = 0; i < leaveList.size(); ++i) { - w = leaveList.at(i); + auto *w = leaveList.at(i); if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { QApplication::sendEvent(w, &leaveEvent); if (w->testAttribute(Qt::WA_Hover) && @@ -2396,9 +2383,9 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con const QPoint globalPos = qIsInf(globalPosF.x()) ? QPoint(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) : globalPosF.toPoint(); - const QPoint windowPos = enterList.front()->window()->mapFromGlobal(globalPos); - for (int i = 0; i < enterList.size(); ++i) { - w = enterList.at(i); + const QPoint windowPos = enterList.back()->window()->mapFromGlobal(globalPos); + for (auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) { + auto *w = *it; if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { const QPointF localPos = w->mapFromGlobal(globalPos); QEnterEvent enterEvent(localPos, windowPos, globalPosF); @@ -2421,7 +2408,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con // This is not required on Windows as the cursor is reset on every single mouse move. QWidget *parentOfLeavingCursor = 0; for (int i = 0; i < leaveList.size(); ++i) { - w = leaveList.at(i); + auto *w = leaveList.at(i); if (!isAlien(w)) break; if (w->testAttribute(Qt::WA_SetCursor)) { @@ -2486,7 +2473,7 @@ bool QApplicationPrivate::isBlockedByModal(QWidget *widget) bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const { QWindow *unused = 0; - if (!window) { + if (Q_UNLIKELY(!window)) { qWarning().nospace() << "window == 0 passed."; return false; } @@ -3008,7 +2995,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) if (QApplicationPrivate::is_app_closing) return true; - if (receiver == 0) { // serious error + if (Q_UNLIKELY(!receiver)) { // serious error qWarning("QApplication::notify: Unexpected null receiver"); return true; } @@ -3257,7 +3244,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QObject *obj = d->extraData->eventFilters.at(i); if (!obj) continue; - if (obj->d_func()->threadData != w->d_func()->threadData) { + if (Q_UNLIKELY(obj->d_func()->threadData != w->d_func()->threadData)) { qWarning("QApplication: Object event filter cannot be in a different thread."); continue; } @@ -4129,7 +4116,7 @@ bool QApplication::isEffectEnabled(Qt::UIEffect effect) */ void QApplication::beep() { - QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), "beep"); + QGuiApplicationPrivate::platformIntegration()->beep(); } /*! |