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 <lars.knoll@theqtcompany.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
This commit is contained in:
parent
d09cfe04b8
commit
37a933c2b1
@ -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);
|
pixmaps += QPixmapIconEngineEntry(abs, i, mode, state);
|
||||||
if (icoImages.isEmpty() && !ignoreSize) // Add placeholder with the filename and empty pixmap for the size.
|
if (icoImages.isEmpty() && !ignoreSize) // Add placeholder with the filename and empty pixmap for the size.
|
||||||
pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
|
pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
|
||||||
|
@ -3032,9 +3032,8 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
stack.reserve(itemsSet.count());
|
stack.reserve(itemsSet.count());
|
||||||
foreach (QStandardItem *item, itemsSet) {
|
for (QStandardItem *item : qAsConst(itemsSet))
|
||||||
stack.push(item);
|
stack.push(item);
|
||||||
}
|
|
||||||
|
|
||||||
//stream everything recursively
|
//stream everything recursively
|
||||||
while (!stack.isEmpty()) {
|
while (!stack.isEmpty()) {
|
||||||
|
@ -990,9 +990,8 @@ qreal QGuiApplication::devicePixelRatio() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
topDevicePixelRatio = 1.0; // make sure we never return 0.
|
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());
|
topDevicePixelRatio = qMax(topDevicePixelRatio, screen->devicePixelRatio());
|
||||||
}
|
|
||||||
|
|
||||||
return topDevicePixelRatio;
|
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
|
// 2) Ask the platform integration for a list of theme names
|
||||||
themeNames += QGuiApplicationPrivate::platform_integration->themeNames();
|
themeNames += QGuiApplicationPrivate::platform_integration->themeNames();
|
||||||
// 3) Look for a theme plugin.
|
// 3) Look for a theme plugin.
|
||||||
foreach (const QString &themeName, themeNames) {
|
for (const QString &themeName : qAsConst(themeNames)) {
|
||||||
QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
|
QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
|
||||||
if (QGuiApplicationPrivate::platform_theme)
|
if (QGuiApplicationPrivate::platform_theme)
|
||||||
break;
|
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
|
// 4) If no theme plugin was found ask the platform integration to
|
||||||
// create a theme
|
// create a theme
|
||||||
if (!QGuiApplicationPrivate::platform_theme) {
|
if (!QGuiApplicationPrivate::platform_theme) {
|
||||||
foreach (const QString &themeName, themeNames) {
|
for (const QString &themeName : qAsConst(themeNames)) {
|
||||||
QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
|
QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
|
||||||
if (QGuiApplicationPrivate::platform_theme)
|
if (QGuiApplicationPrivate::platform_theme)
|
||||||
break;
|
break;
|
||||||
@ -1153,7 +1152,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform
|
|||||||
// boolean 'foo' or strings: 'foo=bar'
|
// boolean 'foo' or strings: 'foo=bar'
|
||||||
if (!arguments.isEmpty()) {
|
if (!arguments.isEmpty()) {
|
||||||
if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
|
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 int equalsPos = argument.indexOf(QLatin1Char('='));
|
||||||
const QByteArray name =
|
const QByteArray name =
|
||||||
equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
|
equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
|
||||||
|
@ -653,7 +653,7 @@ void QOpenGLContext::destroy()
|
|||||||
delete d->functions;
|
delete d->functions;
|
||||||
d->functions = 0;
|
d->functions = 0;
|
||||||
|
|
||||||
foreach (QAbstractOpenGLFunctions *func, d->externalVersionFunctions) {
|
for (QAbstractOpenGLFunctions *func : qAsConst(d->externalVersionFunctions)) {
|
||||||
QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func);
|
QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func);
|
||||||
func_d->owningContext = 0;
|
func_d->owningContext = 0;
|
||||||
func_d->initialized = false;
|
func_d->initialized = false;
|
||||||
|
@ -52,9 +52,10 @@ QT_BEGIN_NAMESPACE
|
|||||||
QList<QPlatformCursor *> QPlatformCursorPrivate::getInstances()
|
QList<QPlatformCursor *> QPlatformCursorPrivate::getInstances()
|
||||||
{
|
{
|
||||||
QList<QPlatformCursor *> result;
|
QList<QPlatformCursor *> result;
|
||||||
foreach (const QScreen *screen, QGuiApplicationPrivate::screen_list)
|
for (const QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list)) {
|
||||||
if (QPlatformCursor *cursor = screen->handle()->cursor())
|
if (QPlatformCursor *cursor = screen->handle()->cursor())
|
||||||
result.push_back(cursor);
|
result.push_back(cursor);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,7 +943,7 @@ QOpenGLFramebufferObject::~QOpenGLFramebufferObject()
|
|||||||
if (isBound())
|
if (isBound())
|
||||||
release();
|
release();
|
||||||
|
|
||||||
foreach (const QOpenGLFramebufferObjectPrivate::ColorAttachment &color, d->colorAttachments) {
|
for (const auto &color : qAsConst(d->colorAttachments)) {
|
||||||
if (color.guard)
|
if (color.guard)
|
||||||
color.guard->free();
|
color.guard->free();
|
||||||
}
|
}
|
||||||
|
@ -986,7 +986,7 @@ void QOpenGLShaderProgram::removeAllShaders()
|
|||||||
{
|
{
|
||||||
Q_D(QOpenGLShaderProgram);
|
Q_D(QOpenGLShaderProgram);
|
||||||
d->removingShaders = true;
|
d->removingShaders = true;
|
||||||
foreach (QOpenGLShader *shader, d->shaders) {
|
for (QOpenGLShader *shader : qAsConst(d->shaders)) {
|
||||||
if (d->programGuard && d->programGuard->id()
|
if (d->programGuard && d->programGuard->id()
|
||||||
&& shader && shader->d_func()->shaderGuard)
|
&& shader && shader->d_func()->shaderGuard)
|
||||||
{
|
{
|
||||||
|
@ -235,7 +235,7 @@ void QTextDocumentPrivate::clear()
|
|||||||
{
|
{
|
||||||
Q_Q(QTextDocument);
|
Q_Q(QTextDocument);
|
||||||
|
|
||||||
foreach (QTextCursorPrivate *curs, cursors) {
|
for (QTextCursorPrivate *curs : qAsConst(cursors)) {
|
||||||
curs->setPosition(0);
|
curs->setPosition(0);
|
||||||
curs->currentCharFormat = -1;
|
curs->currentCharFormat = -1;
|
||||||
curs->anchor = 0;
|
curs->anchor = 0;
|
||||||
@ -287,7 +287,7 @@ void QTextDocumentPrivate::clear()
|
|||||||
|
|
||||||
QTextDocumentPrivate::~QTextDocumentPrivate()
|
QTextDocumentPrivate::~QTextDocumentPrivate()
|
||||||
{
|
{
|
||||||
foreach (QTextCursorPrivate *curs, cursors)
|
for (QTextCursorPrivate *curs : qAsConst(cursors))
|
||||||
curs->priv = 0;
|
curs->priv = 0;
|
||||||
cursors.clear();
|
cursors.clear();
|
||||||
undoState = 0;
|
undoState = 0;
|
||||||
@ -674,7 +674,7 @@ void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operati
|
|||||||
blockCursorAdjustment = true;
|
blockCursorAdjustment = true;
|
||||||
move(pos, -1, length, op);
|
move(pos, -1, length, op);
|
||||||
blockCursorAdjustment = false;
|
blockCursorAdjustment = false;
|
||||||
foreach (QTextCursorPrivate *curs, cursors) {
|
for (QTextCursorPrivate *curs : qAsConst(cursors)) {
|
||||||
if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) {
|
if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) {
|
||||||
curs->changed = true;
|
curs->changed = true;
|
||||||
}
|
}
|
||||||
@ -1232,13 +1232,13 @@ void QTextDocumentPrivate::finishEdit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<QTextCursor> changedCursors;
|
QList<QTextCursor> changedCursors;
|
||||||
foreach (QTextCursorPrivate *curs, cursors) {
|
for (QTextCursorPrivate *curs : qAsConst(cursors)) {
|
||||||
if (curs->changed) {
|
if (curs->changed) {
|
||||||
curs->changed = false;
|
curs->changed = false;
|
||||||
changedCursors.append(QTextCursor(curs));
|
changedCursors.append(QTextCursor(curs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (const QTextCursor &cursor, changedCursors)
|
for (const QTextCursor &cursor : qAsConst(changedCursors))
|
||||||
emit q->cursorPositionChanged(cursor);
|
emit q->cursorPositionChanged(cursor);
|
||||||
|
|
||||||
contentsChanged();
|
contentsChanged();
|
||||||
@ -1284,7 +1284,7 @@ void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOr
|
|||||||
if (blockCursorAdjustment) {
|
if (blockCursorAdjustment) {
|
||||||
; // postpone, will be called again from QTextDocumentPrivate::remove()
|
; // postpone, will be called again from QTextDocumentPrivate::remove()
|
||||||
} else {
|
} else {
|
||||||
foreach (QTextCursorPrivate *curs, cursors) {
|
for (QTextCursorPrivate *curs : qAsConst(cursors)) {
|
||||||
if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
|
if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
|
||||||
curs->changed = true;
|
curs->changed = true;
|
||||||
}
|
}
|
||||||
@ -1731,7 +1731,7 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount()
|
|||||||
void QTextDocumentPrivate::aboutToRemoveCell(int from, int to)
|
void QTextDocumentPrivate::aboutToRemoveCell(int from, int to)
|
||||||
{
|
{
|
||||||
Q_ASSERT(from <= to);
|
Q_ASSERT(from <= to);
|
||||||
foreach (QTextCursorPrivate *curs, cursors)
|
for (QTextCursorPrivate *curs : qAsConst(cursors))
|
||||||
curs->aboutToRemoveCell(from, to);
|
curs->aboutToRemoveCell(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,7 +873,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx)
|
|||||||
QVector<RowColSpanInfo> rowColSpanForColumn;
|
QVector<RowColSpanInfo> rowColSpanForColumn;
|
||||||
|
|
||||||
int effectiveRow = 0;
|
int effectiveRow = 0;
|
||||||
foreach (int row, rowNodes) {
|
for (int row : qAsConst(rowNodes)) {
|
||||||
int colsInRow = 0;
|
int colsInRow = 0;
|
||||||
|
|
||||||
foreach (int cell, at(row).children)
|
foreach (int cell, at(row).children)
|
||||||
|
Loading…
Reference in New Issue
Block a user