Refactor QApplication::event from if/else to switch statement

And it wasn't even 'else if' in all the places where it should have been.

Change-Id: I5a48bfe27cc01fa1fbea1995e8c9cb1be427511a
Reviewed-by: Doris Verria <doris.verria@qt.io>
(cherry picked from commit 74397b4924ea23670952ece384c8b6daf71e7f9c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2022-08-25 11:33:24 +02:00 committed by Qt Cherry-pick Bot
parent 25d949c4f2
commit f94e4e3787

View File

@ -1631,7 +1631,8 @@ void QApplication::aboutQt()
bool QApplication::event(QEvent *e) bool QApplication::event(QEvent *e)
{ {
Q_D(QApplication); Q_D(QApplication);
if (e->type() == QEvent::Quit) { switch (e->type()) {
case QEvent::Quit:
// FIXME: This logic first tries to close all windows, and then // FIXME: This logic first tries to close all windows, and then
// checks whether it was successful, but the conditions used in // checks whether it was successful, but the conditions used in
// closeAllWindows() differ from the verification logic below. // closeAllWindows() differ from the verification logic below.
@ -1651,7 +1652,7 @@ bool QApplication::event(QEvent *e)
// closeAllWindows(). FIXME: Unify all this close magic through closeAllWindows. // closeAllWindows(). FIXME: Unify all this close magic through closeAllWindows.
return QCoreApplication::event(e); return QCoreApplication::event(e);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
} else if (e->type() == QEvent::LocaleChange) { case QEvent::LocaleChange: {
// on Windows the event propagation is taken care by the // on Windows the event propagation is taken care by the
// WM_SETTINGCHANGE event handler. // WM_SETTINGCHANGE event handler.
const QWidgetList list = topLevelWidgets(); const QWidgetList list = topLevelWidgets();
@ -1661,8 +1662,10 @@ bool QApplication::event(QEvent *e)
w->d_func()->setLocale_helper(QLocale(), true); w->d_func()->setLocale_helper(QLocale(), true);
} }
} }
break;
}
#endif #endif
} else if (e->type() == QEvent::Timer) { case QEvent::Timer: {
QTimerEvent *te = static_cast<QTimerEvent*>(e); QTimerEvent *te = static_cast<QTimerEvent*>(e);
Q_ASSERT(te != nullptr); Q_ASSERT(te != nullptr);
if (te->timerId() == d->toolTipWakeUp.timerId()) { if (te->timerId() == d->toolTipWakeUp.timerId()) {
@ -1691,15 +1694,16 @@ bool QApplication::event(QEvent *e)
} else if (te->timerId() == d->toolTipFallAsleep.timerId()) { } else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
d->toolTipFallAsleep.stop(); d->toolTipFallAsleep.stop();
} }
break;
}
#if QT_CONFIG(whatsthis) #if QT_CONFIG(whatsthis)
} else if (e->type() == QEvent::EnterWhatsThisMode) { case QEvent::EnterWhatsThisMode:
QWhatsThis::enterWhatsThisMode(); QWhatsThis::enterWhatsThisMode();
return true; return true;
#endif #endif
} case QEvent::LanguageChange:
case QEvent::ApplicationFontChange:
if (e->type() == QEvent::LanguageChange || e->type() == QEvent::ApplicationFontChange || case QEvent::ApplicationPaletteChange: {
e->type() == QEvent::ApplicationPaletteChange) {
// QGuiApplication::event does not account for the cases where // QGuiApplication::event does not account for the cases where
// there is a top level widget without a window handle. So they // there is a top level widget without a window handle. So they
// need to have the event posted here // need to have the event posted here
@ -1708,6 +1712,10 @@ bool QApplication::event(QEvent *e)
if (!w->windowHandle() && (w->windowType() != Qt::Desktop)) if (!w->windowHandle() && (w->windowType() != Qt::Desktop))
postEvent(w, new QEvent(e->type())); postEvent(w, new QEvent(e->type()));
} }
break;
}
default:
break;
} }
return QGuiApplication::event(e); return QGuiApplication::event(e);