From 37a933c2b14a4a1aad54af0eba0bc210ae5b549a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 26 Jan 2016 14:38:54 +0100 Subject: QtGui: eradicate Q_FOREACH loops [needing qAsConst()] ... by replacing them with C++11 range-for loops. To avoid detaches of these mutable Qt containers, wrap the container in qAsConst(). Change-Id: I90fd517ad542ef92034403c15ebb8300a56ac693 Reviewed-by: Lars Knoll Reviewed-by: Gunnar Sletta --- src/gui/image/qicon.cpp | 2 +- src/gui/itemmodels/qstandarditemmodel.cpp | 3 +-- src/gui/kernel/qguiapplication.cpp | 9 ++++----- src/gui/kernel/qopenglcontext.cpp | 2 +- src/gui/kernel/qplatformcursor.cpp | 3 ++- src/gui/opengl/qopenglframebufferobject.cpp | 2 +- src/gui/opengl/qopenglshaderprogram.cpp | 2 +- src/gui/text/qtextdocument_p.cpp | 14 +++++++------- src/gui/text/qtextdocumentfragment.cpp | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 62feaa92f9..2b148383b0 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -442,7 +442,7 @@ void QPixmapIconEngine::addFile(const QString &fileName, const QSize &size, QIco } } } - foreach (const QImage &i, icoImages) + for (const QImage &i : qAsConst(icoImages)) pixmaps += QPixmapIconEngineEntry(abs, i, mode, state); if (icoImages.isEmpty() && !ignoreSize) // Add placeholder with the filename and empty pixmap for the size. pixmaps += QPixmapIconEngineEntry(abs, size, mode, state); diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index e4442bb82f..e843351cf7 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -3032,9 +3032,8 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const } stack.reserve(itemsSet.count()); - foreach (QStandardItem *item, itemsSet) { + for (QStandardItem *item : qAsConst(itemsSet)) stack.push(item); - } //stream everything recursively while (!stack.isEmpty()) { diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 632fe874a6..9b64c32533 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -990,9 +990,8 @@ qreal QGuiApplication::devicePixelRatio() const } topDevicePixelRatio = 1.0; // make sure we never return 0. - foreach (QScreen *screen, QGuiApplicationPrivate::screen_list) { + for (QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list)) topDevicePixelRatio = qMax(topDevicePixelRatio, screen->devicePixelRatio()); - } return topDevicePixelRatio; } @@ -1127,7 +1126,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform // 2) Ask the platform integration for a list of theme names themeNames += QGuiApplicationPrivate::platform_integration->themeNames(); // 3) Look for a theme plugin. - foreach (const QString &themeName, themeNames) { + for (const QString &themeName : qAsConst(themeNames)) { QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath); if (QGuiApplicationPrivate::platform_theme) break; @@ -1136,7 +1135,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform // 4) If no theme plugin was found ask the platform integration to // create a theme if (!QGuiApplicationPrivate::platform_theme) { - foreach (const QString &themeName, themeNames) { + for (const QString &themeName : qAsConst(themeNames)) { QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName); if (QGuiApplicationPrivate::platform_theme) break; @@ -1153,7 +1152,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform // boolean 'foo' or strings: 'foo=bar' if (!arguments.isEmpty()) { if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) { - foreach (const QString &argument, arguments) { + for (const QString &argument : qAsConst(arguments)) { const int equalsPos = argument.indexOf(QLatin1Char('=')); const QByteArray name = equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8(); diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index beac072b3c..b45396ab3c 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -653,7 +653,7 @@ void QOpenGLContext::destroy() delete d->functions; d->functions = 0; - foreach (QAbstractOpenGLFunctions *func, d->externalVersionFunctions) { + for (QAbstractOpenGLFunctions *func : qAsConst(d->externalVersionFunctions)) { QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func); func_d->owningContext = 0; func_d->initialized = false; diff --git a/src/gui/kernel/qplatformcursor.cpp b/src/gui/kernel/qplatformcursor.cpp index 49881338f2..c644d4769a 100644 --- a/src/gui/kernel/qplatformcursor.cpp +++ b/src/gui/kernel/qplatformcursor.cpp @@ -52,9 +52,10 @@ QT_BEGIN_NAMESPACE QList QPlatformCursorPrivate::getInstances() { QList result; - foreach (const QScreen *screen, QGuiApplicationPrivate::screen_list) + for (const QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list)) { if (QPlatformCursor *cursor = screen->handle()->cursor()) result.push_back(cursor); + } return result; } diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index c1b2e10785..6110764094 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -943,7 +943,7 @@ QOpenGLFramebufferObject::~QOpenGLFramebufferObject() if (isBound()) release(); - foreach (const QOpenGLFramebufferObjectPrivate::ColorAttachment &color, d->colorAttachments) { + for (const auto &color : qAsConst(d->colorAttachments)) { if (color.guard) color.guard->free(); } diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index 1e0abbfab9..a32c111178 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -986,7 +986,7 @@ void QOpenGLShaderProgram::removeAllShaders() { Q_D(QOpenGLShaderProgram); d->removingShaders = true; - foreach (QOpenGLShader *shader, d->shaders) { + for (QOpenGLShader *shader : qAsConst(d->shaders)) { if (d->programGuard && d->programGuard->id() && shader && shader->d_func()->shaderGuard) { diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index cfca718f01..5cb9e1bb74 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -235,7 +235,7 @@ void QTextDocumentPrivate::clear() { Q_Q(QTextDocument); - foreach (QTextCursorPrivate *curs, cursors) { + for (QTextCursorPrivate *curs : qAsConst(cursors)) { curs->setPosition(0); curs->currentCharFormat = -1; curs->anchor = 0; @@ -287,7 +287,7 @@ void QTextDocumentPrivate::clear() QTextDocumentPrivate::~QTextDocumentPrivate() { - foreach (QTextCursorPrivate *curs, cursors) + for (QTextCursorPrivate *curs : qAsConst(cursors)) curs->priv = 0; cursors.clear(); undoState = 0; @@ -674,7 +674,7 @@ void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operati blockCursorAdjustment = true; move(pos, -1, length, op); blockCursorAdjustment = false; - foreach (QTextCursorPrivate *curs, cursors) { + for (QTextCursorPrivate *curs : qAsConst(cursors)) { if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) { curs->changed = true; } @@ -1232,13 +1232,13 @@ void QTextDocumentPrivate::finishEdit() } QList changedCursors; - foreach (QTextCursorPrivate *curs, cursors) { + for (QTextCursorPrivate *curs : qAsConst(cursors)) { if (curs->changed) { curs->changed = false; changedCursors.append(QTextCursor(curs)); } } - foreach (const QTextCursor &cursor, changedCursors) + for (const QTextCursor &cursor : qAsConst(changedCursors)) emit q->cursorPositionChanged(cursor); contentsChanged(); @@ -1284,7 +1284,7 @@ void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOr if (blockCursorAdjustment) { ; // postpone, will be called again from QTextDocumentPrivate::remove() } else { - foreach (QTextCursorPrivate *curs, cursors) { + for (QTextCursorPrivate *curs : qAsConst(cursors)) { if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { curs->changed = true; } @@ -1731,7 +1731,7 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount() void QTextDocumentPrivate::aboutToRemoveCell(int from, int to) { Q_ASSERT(from <= to); - foreach (QTextCursorPrivate *curs, cursors) + for (QTextCursorPrivate *curs : qAsConst(cursors)) curs->aboutToRemoveCell(from, to); } diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index 32d59be833..9325f78ba0 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -873,7 +873,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) QVector rowColSpanForColumn; int effectiveRow = 0; - foreach (int row, rowNodes) { + for (int row : qAsConst(rowNodes)) { int colsInRow = 0; foreach (int cell, at(row).children) -- cgit v1.2.3