summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-30 11:28:25 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-30 14:10:29 +0000
commitf9ba58a13baad7982600a84563b488f65581bfd9 (patch)
tree448b43618938219c35dfb0742bdcf96ff48479a6 /src/widgets
parent22639e65d2168e4d45c5a5ffe42ad85f5ef26d7d (diff)
Fix scoping of loop variables in QApplicationPrivate::dispatchEnterLeave()
Don't reuse 'w' as the loop variable for every loop in the (very long) function. Scope the variable closer, or, where there are no natural scopes, define a new variable. Required turning some while loops into (more natural) for loops. Change-Id: I7d1a52503aeb19cd76be22153ba3d0961bd44cae Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qapplication.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index e5d8960cf8..3c48f29ef1 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2318,7 +2318,6 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
return;
#endif
- QWidget* w ;
if ((!enter && !leave) || (enter == leave))
return;
#ifdef ALIEN_DEBUG
@@ -2329,13 +2328,13 @@ 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);
} while (!w->isWindow() && (w = w->parentWidget()));
@@ -2343,11 +2342,11 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
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;
@@ -2364,21 +2363,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) {
+
+ for (auto *w = enter; w != wenter; w = w->parentWidget())
enterList.prepend(w);
- w = w->parentWidget();
- }
}
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) &&
@@ -2397,7 +2391,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
: globalPosF.toPoint();
const QPoint windowPos = enterList.front()->window()->mapFromGlobal(globalPos);
for (int i = 0; i < enterList.size(); ++i) {
- w = enterList.at(i);
+ auto *w = enterList.at(i);
if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
const QPointF localPos = w->mapFromGlobal(globalPos);
QEnterEvent enterEvent(localPos, windowPos, globalPosF);
@@ -2420,7 +2414,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)) {