tools: replace 'foreach' with 'range for'
Mark some local variables or parameters as const to prevent detach()'ing. Use qAsConst where is not possible mark as const. Change-Id: I0a777c3bd855abd3bb1ad0907152360cf4a1050e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
c754b71eb4
commit
3ef4fac9ff
|
@ -192,7 +192,7 @@ public Q_SLOTS:
|
|||
checkForWindow(o);
|
||||
haveOne = true;
|
||||
if (conf && qae)
|
||||
foreach (PartialScene *ps, conf->completers)
|
||||
for (PartialScene *ps : qAsConst(conf->completers))
|
||||
if (o->inherits(ps->itemType().toUtf8().constData()))
|
||||
contain(o, ps->container());
|
||||
}
|
||||
|
@ -413,8 +413,8 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory)
|
|||
QObject *dummyData = comp.create();
|
||||
|
||||
if (comp.isError()) {
|
||||
QList<QQmlError> errors = comp.errors();
|
||||
foreach (const QQmlError &error, errors)
|
||||
const QList<QQmlError> errors = comp.errors();
|
||||
for (const QQmlError &error : errors)
|
||||
qWarning() << error;
|
||||
}
|
||||
|
||||
|
@ -566,7 +566,7 @@ int main(int argc, char *argv[])
|
|||
if (!dummyDir.isEmpty() && QFileInfo (dummyDir).isDir())
|
||||
loadDummyDataFiles(e, dummyDir);
|
||||
|
||||
foreach (const QString &path, files) {
|
||||
for (const QString &path : qAsConst(files)) {
|
||||
//QUrl::fromUserInput doesn't treat no scheme as relative file paths
|
||||
#ifndef QT_NO_REGULAREXPRESSION
|
||||
QRegularExpression urlRe("[[:word:]]+://.*");
|
||||
|
|
|
@ -288,7 +288,7 @@ QHash<QString, QEasingCurve> SplineEditor::presets() const
|
|||
QString SplineEditor::generateCode()
|
||||
{
|
||||
QString s = QLatin1String("[");
|
||||
foreach (const QPointF &point, m_controlPoints) {
|
||||
for (const QPointF &point : qAsConst(m_controlPoints)) {
|
||||
s += QString::number(point.x(), 'g', 2) + QLatin1Char(',')
|
||||
+ QString::number(point.y(), 'g', 3) + QLatin1Char(',');
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ QString resolveImportPath(const QString &uri, const QString &version)
|
|||
|
||||
QString ver = version;
|
||||
while (true) {
|
||||
foreach (const QString &qmlImportPath, g_qmlImportPaths) {
|
||||
for (const QString &qmlImportPath : qAsConst(g_qmlImportPaths)) {
|
||||
// Search for the most specific version first, and search
|
||||
// also for the version in parent modules. For example:
|
||||
// - qml/QtQml/Models.2.0
|
||||
|
@ -230,8 +230,8 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
|
|||
if (!classnames.isEmpty())
|
||||
import.insert(QStringLiteral("classname"), classnames);
|
||||
if (plugininfo.contains(dependenciesLiteral())) {
|
||||
QStringList dependencies = plugininfo.value(dependenciesLiteral()).toStringList();
|
||||
foreach (const QString &line, dependencies) {
|
||||
const QStringList dependencies = plugininfo.value(dependenciesLiteral()).toStringList();
|
||||
for (const QString &line : dependencies) {
|
||||
const auto dep = line.splitRef(QLatin1Char(' '));
|
||||
QVariantMap depImport;
|
||||
depImport[typeLiteral()] = QStringLiteral("module");
|
||||
|
@ -362,7 +362,7 @@ QVariantList findQmlImportsInFile(const QString &filePath)
|
|||
QVariantList mergeImports(const QVariantList &a, const QVariantList &b)
|
||||
{
|
||||
QVariantList merged = a;
|
||||
foreach (const QVariant &variant, b) {
|
||||
for (const QVariant &variant : b) {
|
||||
if (!merged.contains(variant))
|
||||
merged.append(variant);
|
||||
}
|
||||
|
@ -421,16 +421,16 @@ QVariantList findQmlImportsInDirectory(const QString &qmlDir)
|
|||
continue;
|
||||
}
|
||||
|
||||
foreach (const QFileInfo &x, entries)
|
||||
for (const QFileInfo &x : entries)
|
||||
if (x.isFile())
|
||||
ret = mergeImports(ret, findQmlImportsInFile(x.absoluteFilePath()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QSet<QString> importModulePaths(QVariantList imports) {
|
||||
QSet<QString> importModulePaths(const QVariantList &imports) {
|
||||
QSet<QString> ret;
|
||||
foreach (const QVariant &importVariant, imports) {
|
||||
for (const QVariant &importVariant : imports) {
|
||||
QVariantMap import = qvariant_cast<QVariantMap>(importVariant);
|
||||
QString path = import.value(pathLiteral()).toString();
|
||||
QString type = import.value(typeLiteral()).toString();
|
||||
|
@ -448,13 +448,13 @@ QVariantList findQmlImportsRecursively(const QStringList &qmlDirs, const QString
|
|||
QVariantList ret;
|
||||
|
||||
// scan all app root qml directories for imports
|
||||
foreach (const QString &qmlDir, qmlDirs) {
|
||||
for (const QString &qmlDir : qmlDirs) {
|
||||
QVariantList imports = findQmlImportsInDirectory(qmlDir);
|
||||
ret = mergeImports(ret, imports);
|
||||
}
|
||||
|
||||
// scan app qml files for imports
|
||||
foreach (const QString &file, scanFiles) {
|
||||
for (const QString &file : scanFiles) {
|
||||
QVariantList imports = findQmlImportsInFile(file);
|
||||
ret = mergeImports(ret, imports);
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exceptio
|
|||
std::cerr << "Uncaught exception: " << qPrintable(message->toQStringNoThrow()) << std::endl;
|
||||
}
|
||||
|
||||
foreach (const QV4::StackFrame &frame, trace) {
|
||||
for (const QV4::StackFrame &frame : trace) {
|
||||
std::cerr << " at " << qPrintable(frame.function) << " (" << qPrintable(frame.source);
|
||||
if (frame.line >= 0)
|
||||
std::cerr << ':' << frame.line;
|
||||
|
@ -188,7 +188,7 @@ int main(int argc, char *argv[])
|
|||
QV4::ScopedObject gc(scope, vm.memoryManager->allocObject<builtins::GC>(ctx));
|
||||
vm.globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("gc"))).getPointer(), gc);
|
||||
|
||||
foreach (const QString &fn, args) {
|
||||
for (const QString &fn : qAsConst(args)) {
|
||||
QFile file(fn);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
const QString code = QString::fromUtf8(file.readAll());
|
||||
|
|
|
@ -120,7 +120,7 @@ protected:
|
|||
static QString quote(const QString &string)
|
||||
{
|
||||
QString quotedString;
|
||||
foreach (const QChar &ch, string) {
|
||||
for (const QChar &ch : string) {
|
||||
if (ch == QLatin1Char('"'))
|
||||
quotedString += QLatin1String("\\\"");
|
||||
else {
|
||||
|
|
|
@ -248,15 +248,15 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine,
|
|||
QSet<const QQmlType *> baseExports = qmlTypesByCppName.value(it.key());
|
||||
|
||||
const QSet<QByteArray> extensionCppNames = it.value();
|
||||
foreach (const QByteArray &extensionCppName, extensionCppNames) {
|
||||
for (const QByteArray &extensionCppName : extensionCppNames) {
|
||||
const QSet<const QQmlType *> extensionExports = qmlTypesByCppName.value(extensionCppName);
|
||||
|
||||
// remove extension exports from base imports
|
||||
// unfortunately the QQmlType pointers don't match, so can't use QSet::subtract
|
||||
QSet<const QQmlType *> newBaseExports;
|
||||
foreach (const QQmlType *baseExport, baseExports) {
|
||||
for (const QQmlType *baseExport : qAsConst(baseExports)) {
|
||||
bool match = false;
|
||||
foreach (const QQmlType *extensionExport, extensionExports) {
|
||||
for (const QQmlType *extensionExport : extensionExports) {
|
||||
if (baseExport->qmlTypeName() == extensionExport->qmlTypeName()
|
||||
&& baseExport->majorVersion() == extensionExport->majorVersion()
|
||||
&& baseExport->minorVersion() == extensionExport->minorVersion()) {
|
||||
|
@ -469,7 +469,7 @@ public:
|
|||
|
||||
void dumpComposite(QQmlEngine *engine, const QSet<const QQmlType *> &compositeType, QSet<QByteArray> &defaultReachableNames)
|
||||
{
|
||||
foreach (const QQmlType *type, compositeType)
|
||||
for (const QQmlType *type : compositeType)
|
||||
dumpCompositeItem(engine, type, defaultReachableNames);
|
||||
}
|
||||
|
||||
|
@ -518,7 +518,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
foreach (const QMetaObject *meta, objectsToMerge)
|
||||
for (const QMetaObject *meta : qAsConst(objectsToMerge))
|
||||
writeMetaContent(meta, &knownAttributes);
|
||||
|
||||
qml->writeEndObject();
|
||||
|
@ -542,11 +542,11 @@ public:
|
|||
if (meta->superClass())
|
||||
qml->writeScriptBinding(QLatin1String("prototype"), enquote(convertToId(meta->superClass())));
|
||||
|
||||
QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className());
|
||||
const QSet<const QQmlType *> qmlTypes = qmlTypesByCppName.value(meta->className());
|
||||
if (!qmlTypes.isEmpty()) {
|
||||
QHash<QString, const QQmlType *> exports;
|
||||
|
||||
foreach (const QQmlType *qmlTy, qmlTypes) {
|
||||
for (const QQmlType *qmlTy : qmlTypes) {
|
||||
const QString exportString = getExportString(qmlTy->qmlTypeName(), qmlTy->majorVersion(), qmlTy->minorVersion());
|
||||
exports.insert(exportString, qmlTy);
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ public:
|
|||
|
||||
// write meta object revisions
|
||||
QStringList metaObjectRevisions;
|
||||
foreach (const QString &exportString, exportStrings) {
|
||||
for (const QString &exportString : qAsConst(exportStrings)) {
|
||||
int metaObjectRevision = exports[exportString]->metaObjectRevision();
|
||||
metaObjectRevisions += QString::number(metaObjectRevision);
|
||||
}
|
||||
|
@ -749,7 +749,7 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
|
|||
if (verbose) {
|
||||
std::cerr << "parsing "
|
||||
<< qPrintable( dependenciesFile ) << " skipping";
|
||||
foreach (const QString &uriToSkip, urisToSkip)
|
||||
for (const QString &uriToSkip : urisToSkip)
|
||||
std::cerr << ' ' << qPrintable(uriToSkip);
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
@ -763,13 +763,13 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
|
|||
return false;
|
||||
}
|
||||
if (doc.isArray()) {
|
||||
QStringList requiredKeys = QStringList() << QStringLiteral("name")
|
||||
<< QStringLiteral("type")
|
||||
<< QStringLiteral("version");
|
||||
const QStringList requiredKeys = QStringList() << QStringLiteral("name")
|
||||
<< QStringLiteral("type")
|
||||
<< QStringLiteral("version");
|
||||
foreach (const QJsonValue &dep, doc.array()) {
|
||||
if (dep.isObject()) {
|
||||
QJsonObject obj = dep.toObject();
|
||||
foreach (const QString &requiredKey, requiredKeys)
|
||||
for (const QString &requiredKey : requiredKeys)
|
||||
if (!obj.contains(requiredKey) || obj.value(requiredKey).isString())
|
||||
continue;
|
||||
if (obj.value(QStringLiteral("type")).toString() != QLatin1String("module"))
|
||||
|
@ -850,7 +850,7 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor
|
|||
|
||||
if (!importScanner.waitForFinished()) {
|
||||
std::cerr << "failure to start " << qPrintable(command);
|
||||
foreach (const QString &arg, commandArgs)
|
||||
for (const QString &arg : qAsConst(commandArgs))
|
||||
std::cerr << ' ' << qPrintable(arg);
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
|
@ -863,7 +863,7 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor
|
|||
}
|
||||
|
||||
QStringList aux;
|
||||
foreach (const QString &str, *dependencies) {
|
||||
for (const QString &str : qAsConst(*dependencies)) {
|
||||
if (!str.startsWith("Qt.test.qtestroot"))
|
||||
aux += str;
|
||||
}
|
||||
|
@ -1124,7 +1124,7 @@ int main(int argc, char *argv[])
|
|||
// load the QtQml builtins and the dependencies
|
||||
{
|
||||
QByteArray code(qtQmlImportString.toUtf8());
|
||||
foreach (const QString &moduleToImport, dependencies) {
|
||||
for (const QString &moduleToImport : qAsConst(dependencies)) {
|
||||
code.append("\nimport ");
|
||||
code.append(moduleToImport.toUtf8());
|
||||
}
|
||||
|
@ -1154,7 +1154,7 @@ int main(int argc, char *argv[])
|
|||
QSet<const QMetaObject *> metas;
|
||||
|
||||
if (action == Builtins) {
|
||||
foreach (const QMetaObject *m, defaultReachable) {
|
||||
for (const QMetaObject *m : qAsConst(defaultReachable)) {
|
||||
if (m->className() == QLatin1String("Qt")) {
|
||||
metas.insert(m);
|
||||
break;
|
||||
|
@ -1175,7 +1175,7 @@ int main(int argc, char *argv[])
|
|||
return EXIT_INVALIDARGUMENTS;
|
||||
}
|
||||
metas = defaultReachable;
|
||||
foreach (const QMetaObject *m, defaultReachable) {
|
||||
for (const QMetaObject *m : qAsConst(defaultReachable)) {
|
||||
if (m->className() == QLatin1String("Qt")) {
|
||||
metas.remove(m);
|
||||
break;
|
||||
|
@ -1196,7 +1196,7 @@ int main(int argc, char *argv[])
|
|||
QString::number(qtObjectType->minorVersion())).toUtf8();
|
||||
}
|
||||
// avoid importing dependencies?
|
||||
foreach (const QString &moduleToImport, dependencies) {
|
||||
for (const QString &moduleToImport : qAsConst(dependencies)) {
|
||||
importCode.append("\nimport ");
|
||||
importCode.append(moduleToImport.toUtf8());
|
||||
}
|
||||
|
@ -1231,9 +1231,9 @@ int main(int argc, char *argv[])
|
|||
// Also eliminate meta objects with the same classname.
|
||||
// This is required because extended objects seem not to share
|
||||
// a single meta object instance.
|
||||
foreach (const QMetaObject *mo, defaultReachable)
|
||||
for (const QMetaObject *mo : qAsConst(defaultReachable))
|
||||
defaultReachableNames.insert(QByteArray(mo->className()));
|
||||
foreach (const QMetaObject *mo, candidates) {
|
||||
for (const QMetaObject *mo : qAsConst(candidates)) {
|
||||
if (!defaultReachableNames.contains(mo->className()))
|
||||
metas.insert(mo);
|
||||
}
|
||||
|
@ -1265,19 +1265,19 @@ int main(int argc, char *argv[])
|
|||
compactDependencies(&dependencies);
|
||||
|
||||
QStringList quotedDependencies;
|
||||
foreach (const QString &dep, dependencies)
|
||||
for (const QString &dep : qAsConst(dependencies))
|
||||
quotedDependencies << enquote(dep);
|
||||
qml.writeArrayBinding("dependencies", quotedDependencies);
|
||||
|
||||
// put the metaobjects into a map so they are always dumped in the same order
|
||||
QMap<QString, const QMetaObject *> nameToMeta;
|
||||
foreach (const QMetaObject *meta, metas)
|
||||
for (const QMetaObject *meta : qAsConst(metas))
|
||||
nameToMeta.insert(convertToId(meta), meta);
|
||||
|
||||
Dumper dumper(&qml);
|
||||
if (relocatable)
|
||||
dumper.setRelocatableModuleUri(pluginImportUri);
|
||||
foreach (const QMetaObject *meta, nameToMeta) {
|
||||
for (const QMetaObject *meta : qAsConst(nameToMeta)) {
|
||||
dumper.dump(QQmlEnginePrivate::get(&engine), meta, uncreatableMetas.contains(meta), singletonMetas.contains(meta));
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ void QmlStreamWriter::flushPotentialLinesWithNewlines()
|
|||
{
|
||||
if (m_maybeOneline)
|
||||
m_stream->write("\n");
|
||||
foreach (const QByteArray &line, m_pendingLines) {
|
||||
for (const QByteArray &line : qAsConst(m_pendingLines)) {
|
||||
writeIndent();
|
||||
m_stream->write(line);
|
||||
m_stream->write("\n");
|
||||
|
|
|
@ -274,8 +274,8 @@ quint64 QmlProfilerApplication::parseFeatures(const QStringList &featureList, co
|
|||
bool exclude)
|
||||
{
|
||||
quint64 features = exclude ? std::numeric_limits<quint64>::max() : 0;
|
||||
QStringList givenFeatures = values.split(QLatin1Char(','));
|
||||
foreach (const QString &f, givenFeatures) {
|
||||
const QStringList givenFeatures = values.split(QLatin1Char(','));
|
||||
for (const QString &f : givenFeatures) {
|
||||
int index = featureList.indexOf(f);
|
||||
if (index < 0) {
|
||||
logError(tr("Unknown feature '%1'").arg(f));
|
||||
|
|
|
@ -572,7 +572,7 @@ bool QmlProfilerData::save(const QString &filename)
|
|||
stream.writeEndElement(); // eventData
|
||||
|
||||
stream.writeStartElement(QStringLiteral("profilerDataModel"));
|
||||
foreach (const QmlRangeEventStartInstance &event, d->startInstanceList) {
|
||||
for (const QmlRangeEventStartInstance &event : qAsConst(d->startInstanceList)) {
|
||||
stream.writeStartElement(QStringLiteral("range"));
|
||||
stream.writeAttribute(QStringLiteral("startTime"), QString::number(event.startTime));
|
||||
if (event.duration >= 0)
|
||||
|
|
|
@ -175,10 +175,10 @@ QFileInfoList findQmlFiles(const QString &dirName)
|
|||
|
||||
QFileInfoList ret;
|
||||
if (dir.exists()) {
|
||||
QFileInfoList fileInfos = dir.entryInfoList(QStringList() << "*.qml",
|
||||
QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
const QFileInfoList fileInfos = dir.entryInfoList(QStringList() << "*.qml",
|
||||
QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
|
||||
foreach (QFileInfo fileInfo, fileInfos) {
|
||||
for (const QFileInfo &fileInfo : fileInfos) {
|
||||
if (fileInfo.isDir())
|
||||
ret += findQmlFiles(fileInfo.filePath());
|
||||
else if (fileInfo.fileName().length() > 0 && fileInfo.fileName().at(0).isLower())
|
||||
|
@ -196,9 +196,9 @@ static int displayOptionsDialog(Options *options)
|
|||
QFormLayout *layout = new QFormLayout(&dialog);
|
||||
|
||||
QComboBox *qmlFileComboBox = new QComboBox(&dialog);
|
||||
QFileInfoList fileInfos = findQmlFiles(":/bundle") + findQmlFiles("./qmlscene-resources");
|
||||
const QFileInfoList fileInfos = findQmlFiles(":/bundle") + findQmlFiles("./qmlscene-resources");
|
||||
|
||||
foreach (QFileInfo fileInfo, fileInfos)
|
||||
for (const QFileInfo &fileInfo : fileInfos)
|
||||
qmlFileComboBox->addItem(fileInfo.dir().dirName() + QLatin1Char('/') + fileInfo.fileName(), QVariant::fromValue(fileInfo));
|
||||
|
||||
QCheckBox *originalCheckBox = new QCheckBox(&dialog);
|
||||
|
@ -319,8 +319,8 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory)
|
|||
QObject *dummyData = comp.create();
|
||||
|
||||
if(comp.isError()) {
|
||||
QList<QQmlError> errors = comp.errors();
|
||||
foreach (const QQmlError &error, errors)
|
||||
const QList<QQmlError> errors = comp.errors();
|
||||
for (const QQmlError &error : errors)
|
||||
fprintf(stderr, "%s\n", qPrintable(error.toString()));
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ int main(int argc, char ** argv)
|
|||
options.applicationAttributes.append(Qt::AA_DisableHighDpiScaling);
|
||||
}
|
||||
|
||||
foreach (Qt::ApplicationAttribute a, options.applicationAttributes)
|
||||
for (Qt::ApplicationAttribute a : qAsConst(options.applicationAttributes))
|
||||
QCoreApplication::setAttribute(a);
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QApplication app(argc, argv);
|
||||
|
|
Loading…
Reference in New Issue