summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-26 14:38:54 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-02-11 19:25:47 +0000
commitbcd7d223f066f2830501c2be79f1e7e4f6dd8f50 (patch)
tree2731bb0009263cb2c8d6365a0fedaf2ae63ab8db
parent276d6cf239bdb0a39ae589e13f60b2a31a2efb60 (diff)
QtGui: eradicate Q_FOREACH loops [rvalues]
... by replacing them with C++11 range-for loops. This is the simplest of the patch series: Q_FOREACH took a copy, so we do, too. Except we don't, since we're just catching the return value that comes out of the function (RVO). We can't feed the rvalues into range-for, because they are non-const and would thus detach. Change-Id: I457942159015ff153bdfc6d5f031a3f0a0f6e9ac Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp6
-rw-r--r--src/gui/kernel/qguiapplication.cpp3
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp12
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h6
-rw-r--r--src/gui/kernel/qplatformscreen.cpp3
-rw-r--r--src/gui/kernel/qplatformwindow.cpp3
-rw-r--r--src/gui/kernel/qscreen.cpp9
-rw-r--r--src/gui/kernel/qwindow.cpp3
-rw-r--r--src/gui/opengl/qopengldebug.cpp4
9 files changed, 32 insertions, 17 deletions
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
index 8177927a8b..cbe476bc5a 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
@@ -89,7 +89,8 @@ QSize MyWidget::sizeHint() const
//! [4]
void showAllHiddenTopLevelWidgets()
{
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevelWidgets = QApplication::topLevelWidgets();
+ for (QWidget *widget : topLevelWidgets) {
if (widget->isHidden())
widget->show();
}
@@ -100,7 +101,8 @@ void showAllHiddenTopLevelWidgets()
//! [5]
void updateAllWidgets()
{
- foreach (QWidget *widget, QApplication::allWidgets())
+ const auto topLevelWidgets = QApplication::topLevelWidgets();
+ for (QWidget *widget : topLevelWidgets)
widget->update();
}
//! [5]
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 53599a3a37..e75de9a77d 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2714,7 +2714,8 @@ void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate:
emit s->availableGeometryChanged(s->availableGeometry());
if (geometryChanged || availableGeometryChanged) {
- foreach (QScreen* sibling, s->virtualSiblings())
+ const auto siblings = s->virtualSiblings();
+ for (QScreen* sibling : siblings)
emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
}
}
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index eed4c301ef..4cc9e95e81 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -267,7 +267,8 @@ void QHighDpiScaling::updateHighDpiScaling()
return;
if (m_usePixelDensity && !m_pixelDensityScalingActive) {
- Q_FOREACH (QScreen *screen, QGuiApplication::screens()) {
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *screen : screens) {
if (!qFuzzyCompare(screenSubfactor(screen->handle()), qreal(1))) {
m_pixelDensityScalingActive = true;
break;
@@ -276,7 +277,8 @@ void QHighDpiScaling::updateHighDpiScaling()
}
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
int i = 0;
- Q_FOREACH (const QByteArray &spec, qgetenv(screenFactorsEnvVar).split(';')) {
+ const auto specs = qgetenv(screenFactorsEnvVar).split(';');
+ for (const QByteArray &spec : specs) {
QScreen *screen = 0;
int equalsPos = spec.lastIndexOf('=');
double factor = 0;
@@ -287,7 +289,8 @@ void QHighDpiScaling::updateHighDpiScaling()
bool ok;
factor = f.toDouble(&ok);
if (ok) {
- Q_FOREACH (QScreen *s, QGuiApplication::screens()) {
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *s : screens) {
if (s->name() == QString::fromLocal8Bit(name)) {
screen = s;
break;
@@ -327,7 +330,8 @@ void QHighDpiScaling::setGlobalFactor(qreal factor)
m_globalScalingActive = !qFuzzyCompare(factor, qreal(1));
m_factor = m_globalScalingActive ? factor : qreal(1);
m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
- Q_FOREACH (QScreen *screen, QGuiApplication::screens())
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *screen : screens)
screen->d_func()->updateHighDpi();
}
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index 9c4ced58da..8540460a54 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -381,7 +381,8 @@ inline QRegion fromNativeLocalRegion(const QRegion &pixelRegion, const QWindow *
qreal scaleFactor = QHighDpiScaling::factor(window);
QRegion pointRegion;
- foreach (const QRect &rect, pixelRegion.rects()) {
+ const auto rects = pixelRegion.rects();
+ for (const QRect &rect : rects) {
pointRegion += QRect(fromNative(rect.topLeft(), scaleFactor),
fromNative(rect.size(), scaleFactor));
}
@@ -395,7 +396,8 @@ inline QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *wi
qreal scaleFactor = QHighDpiScaling::factor(window);
QRegion pixelRegon;
- foreach (const QRect &rect, pointRegion.rects()) {
+ const auto rects = pointRegion.rects();
+ for (const QRect &rect : rects) {
pixelRegon += QRect(toNative(rect.topLeft(), scaleFactor),
toNative(rect.size(), scaleFactor));
}
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index 34a0796975..8450c6a083 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -111,7 +111,8 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
const QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) const
{
if (!geometry().contains(point)) {
- Q_FOREACH (const QPlatformScreen* screen, virtualSiblings()) {
+ const auto screens = virtualSiblings();
+ for (const QPlatformScreen *screen : screens) {
if (screen->geometry().contains(point))
return screen;
}
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index 0a0facf471..f5ddaa4bb7 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -494,7 +494,8 @@ QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) co
const QPoint center = newGeometry.isEmpty() ? newGeometry.topLeft() : newGeometry.center();
if (!parent() && currentScreen && !currentScreen->geometry().contains(center)) {
- Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) {
+ const auto screens = currentScreen->virtualSiblings();
+ for (QPlatformScreen *screen : screens) {
if (screen->geometry().contains(center))
return screen;
if (screen->geometry().intersects(newGeometry))
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 328cb57ec9..ae6879cf84 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -122,7 +122,8 @@ QScreen::~QScreen()
bool movingFromVirtualSibling = primaryScreen && primaryScreen->handle()->virtualSiblings().contains(handle());
// Move any leftover windows to the primary screen
- foreach (QWindow *window, QGuiApplication::allWindows()) {
+ const auto allWindows = QGuiApplication::allWindows();
+ for (QWindow *window : allWindows) {
if (!window->isTopLevel() || window->screen() != this)
continue;
@@ -399,7 +400,8 @@ QSize QScreen::virtualSize() const
QRect QScreen::virtualGeometry() const
{
QRect result;
- foreach (QScreen *screen, virtualSiblings())
+ const auto screens = virtualSiblings();
+ for (QScreen *screen : screens)
result |= screen->geometry();
return result;
}
@@ -432,7 +434,8 @@ QSize QScreen::availableVirtualSize() const
QRect QScreen::availableVirtualGeometry() const
{
QRect result;
- foreach (QScreen *screen, virtualSiblings())
+ const auto screens = virtualSiblings();
+ for (QScreen *screen : screens)
result |= screen->availableGeometry();
return result;
}
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index c8cf7ddb91..c1bba59140 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -1509,7 +1509,8 @@ QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry)
QScreen *fallback = currentScreen;
QPoint center = newGeometry.center();
if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
- Q_FOREACH (QScreen* screen, currentScreen->virtualSiblings()) {
+ const auto screens = currentScreen->virtualSiblings();
+ for (QScreen* screen : screens) {
if (screen->geometry().contains(center))
return screen;
if (screen->geometry().intersects(newGeometry))
diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp
index 0132dc03bb..5f0164c3e1 100644
--- a/src/gui/opengl/qopengldebug.cpp
+++ b/src/gui/opengl/qopengldebug.cpp
@@ -176,8 +176,8 @@ QT_BEGIN_NAMESPACE
\code
- QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
- foreach (const QOpenGLDebugMessage &message, messages)
+ const QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
+ for (const QOpenGLDebugMessage &message : messages)
qDebug() << message;
\endcode