qmleditor: Remove foreach / Q_FOREACH usage

Task-number: QTCREATORBUG-27464
Change-Id: Ic6d667d97a9708963f7c3e21aa9598ffe0f9c7b7
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-12-19 13:23:53 +01:00
parent a7d8c4889e
commit 5cc77c4bf1
9 changed files with 30 additions and 23 deletions

View File

@@ -352,7 +352,8 @@ bool Semantic::visit(FunctionCallExpressionAST *ast)
_expr.type = funTy->returnType(); _expr.type = funTy->returnType();
} else if (const OverloadSet *overloads = id.type->asOverloadSetType()) { } else if (const OverloadSet *overloads = id.type->asOverloadSetType()) {
QVector<Function *> candidates; QVector<Function *> candidates;
foreach (Function *f, overloads->functions()) { const QVector<Function *> functions = overloads->functions();
for (Function *f : functions) {
if (f->argumentCount() == actuals.size()) { if (f->argumentCount() == actuals.size()) {
int argc = 0; int argc = 0;
for (; argc < actuals.size(); ++argc) { for (; argc < actuals.size(); ++argc) {

View File

@@ -308,7 +308,7 @@ bool ArrayType::isLessThan(const Type *other) const
QList<Symbol *> Struct::members() const QList<Symbol *> Struct::members() const
{ {
QList<Symbol *> m; QList<Symbol *> m;
foreach (Symbol *s, _members) { for (Symbol *s : std::as_const(_members)) {
if (! s->name().isEmpty()) if (! s->name().isEmpty())
m.append(s); m.append(s);
} }
@@ -322,7 +322,7 @@ void Struct::add(Symbol *member)
Symbol *Struct::find(const QString &name) const Symbol *Struct::find(const QString &name) const
{ {
foreach (Symbol *s, _members) { for (Symbol *s : std::as_const(_members)) {
if (s->name() == name) if (s->name() == name)
return s; return s;
} }
@@ -411,7 +411,7 @@ bool Function::isLessThan(const Type *other) const
QList<Symbol *> Function::members() const QList<Symbol *> Function::members() const
{ {
QList<Symbol *> m; QList<Symbol *> m;
foreach (Argument *arg, _arguments) { for (Argument *arg : std::as_const(_arguments)) {
if (! arg->name().isEmpty()) if (! arg->name().isEmpty())
m.append(arg); m.append(arg);
} }
@@ -420,7 +420,7 @@ QList<Symbol *> Function::members() const
Symbol *Function::find(const QString &name) const Symbol *Function::find(const QString &name) const
{ {
foreach (Argument *arg, _arguments) { for (Argument *arg : std::as_const(_arguments)) {
if (arg->name() == name) if (arg->name() == name)
return arg; return arg;
} }

View File

@@ -44,7 +44,7 @@ void FakeMetaEnum::addToHash(QCryptographicHash &hash) const
hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar));
len = m_keys.size(); len = m_keys.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QString &key, m_keys) { for (const QString &key : std::as_const(m_keys)) {
len = key.size(); len = key.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
@@ -129,14 +129,14 @@ void FakeMetaMethod::addToHash(QCryptographicHash &hash) const
hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision)); hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision));
len = m_paramNames.size(); len = m_paramNames.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QString &pName, m_paramNames) { for (const QString &pName : std::as_const(m_paramNames)) {
len = pName.size(); len = pName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(pName.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(pName.constData()), len * sizeof(QChar));
} }
len = m_paramTypes.size(); len = m_paramTypes.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QString &pType, m_paramTypes) { for (const QString &pType : std::as_const(m_paramTypes)) {
len = pType.size(); len = pType.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(pType.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(pType.constData()), len * sizeof(QChar));
@@ -158,7 +158,7 @@ QString FakeMetaMethod::describe(int baseIndent) const
res += QString::number(methodType()); res += QString::number(methodType());
res += newLine; res += newLine;
res += QLatin1String(" parameterNames:["); res += QLatin1String(" parameterNames:[");
foreach (const QString &pName, parameterNames()) { for (const QString &pName : parameterNames()) {
res += newLine; res += newLine;
res += QLatin1String(" "); res += QLatin1String(" ");
res += pName; res += pName;
@@ -166,7 +166,7 @@ QString FakeMetaMethod::describe(int baseIndent) const
res += QLatin1Char(']'); res += QLatin1Char(']');
res += newLine; res += newLine;
res += QLatin1String(" parameterTypes:["); res += QLatin1String(" parameterTypes:[");
foreach (const QString &pType, parameterTypes()) { for (const QString &pType : parameterTypes()) {
res += newLine; res += newLine;
res += QLatin1String(" "); res += QLatin1String(" ");
res += pType; res += pType;
@@ -287,7 +287,7 @@ QList<FakeMetaObject::Export> FakeMetaObject::exports() const
{ return m_exports; } { return m_exports; }
FakeMetaObject::Export FakeMetaObject::exportInPackage(const QString &package) const FakeMetaObject::Export FakeMetaObject::exportInPackage(const QString &package) const
{ {
foreach (const Export &exp, m_exports) { for (const Export &exp : std::as_const(m_exports)) {
if (exp.package == package) if (exp.package == package)
return exp; return exp;
} }
@@ -369,7 +369,7 @@ QByteArray FakeMetaObject::calculateFingerprint() const
{ {
QStringList keys(m_enumNameToIndex.keys()); QStringList keys(m_enumNameToIndex.keys());
keys.sort(); keys.sort();
foreach (const QString &key, keys) { for (const QString &key : std::as_const(keys)) {
len = key.size(); len = key.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
@@ -380,16 +380,16 @@ QByteArray FakeMetaObject::calculateFingerprint() const
} }
len = m_exports.size(); len = m_exports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const Export &e, m_exports) for (const Export &e : std::as_const(m_exports))
e.addToHash(hash); // normalize order? e.addToHash(hash); // normalize order?
len = m_exports.size(); len = m_exports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const FakeMetaMethod &m, m_methods) for (const FakeMetaMethod &m : std::as_const(m_methods))
m.addToHash(hash); // normalize order? m.addToHash(hash); // normalize order?
{ {
QStringList keys(m_propNameToIdx.keys()); QStringList keys(m_propNameToIdx.keys());
keys.sort(); keys.sort();
foreach (const QString &key, keys) { for (const QString &key : std::as_const(keys)) {
len = key.size(); len = key.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar)); hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
@@ -488,7 +488,7 @@ QString FakeMetaObject::describe(bool printDetails, int baseIndent) const
res += newLine; res += newLine;
res += QLatin1String("exports:["); res += QLatin1String("exports:[");
foreach (const Export &e, exports()) { for (const Export &e : exports()) {
res += newLine; res += newLine;
res += QLatin1String(" "); res += QLatin1String(" ");
res += e.describe(baseIndent + 2); res += e.describe(baseIndent + 2);

View File

@@ -21,7 +21,8 @@ void BaseToolsClient::recurseObjectIdList(const ObjectReference &ref,
{ {
debugIds << ref.debugId(); debugIds << ref.debugId();
objectIds << ref.idString(); objectIds << ref.idString();
foreach (const ObjectReference &child, ref.children()) const QList<ObjectReference> children = ref.children();
for (const ObjectReference &child : children)
recurseObjectIdList(child, debugIds, objectIds); recurseObjectIdList(child, debugIds, objectIds);
} }

View File

@@ -56,7 +56,7 @@ void QmlToolsClient::messageReceived(const QByteArray &message)
debugIds.removeAll(-1); debugIds.removeAll(-1);
QStringList debugIdStrings; QStringList debugIdStrings;
foreach (int debugId, debugIds) { for (int debugId : std::as_const(debugIds)) {
debugIdStrings << QString::number(debugId); debugIdStrings << QString::number(debugId);
} }
log(LogReceive, type + ':' + event, log(LogReceive, type + ':' + event,

View File

@@ -189,8 +189,9 @@ ContextPaneWidget::~ContextPaneWidget()
void ContextPaneWidget::activate(const QPoint &pos, const QPoint &alternative, const QPoint &alternative2, bool pinned) void ContextPaneWidget::activate(const QPoint &pos, const QPoint &alternative, const QPoint &alternative2, bool pinned)
{ {
//uncheck all color buttons //uncheck all color buttons
foreach (ColorButton *colorButton, findChildren<ColorButton*>()) { const QList<ColorButton *> children = findChildren<ColorButton*>();
colorButton->setChecked(false); for (ColorButton *colorButton : children) {
colorButton->setChecked(false);
} }
show(); show();
update(); update();

View File

@@ -896,7 +896,9 @@ PreviewDialog::PreviewDialog(QWidget *parent) : DragWidget(parent)
connect(m_slider, &QSlider::valueChanged, this, &PreviewDialog::onSliderMoved); connect(m_slider, &QSlider::valueChanged, this, &PreviewDialog::onSliderMoved);
foreach (QWidget *childWidget, findChildren<QWidget*>()) {
const QList<QWidget *> children = findChildren<QWidget*>();
for (QWidget *childWidget : children) {
childWidget->installEventFilter(wheelFilter); childWidget->installEventFilter(wheelFilter);
} }
} }

View File

@@ -241,7 +241,8 @@ void ContextPaneWidgetRectangle::timerEvent(QTimerEvent *event)
QLinearGradient gradient = ui->gradientLine->gradient(); QLinearGradient gradient = ui->gradientLine->gradient();
QString str = QLatin1String("Gradient {\n"); QString str = QLatin1String("Gradient {\n");
foreach (const QGradientStop &stop, gradient.stops()) { const QGradientStops stops = gradient.stops();
for (const QGradientStop &stop : stops) {
str += QLatin1String("GradientStop {\n"); str += QLatin1String("GradientStop {\n");
str += QLatin1String("position: ") + QString::number(stop.first, 'f', 2) + QLatin1String(";\n"); str += QLatin1String("position: ") + QString::number(stop.first, 'f', 2) + QLatin1String(";\n");
str += QLatin1String("color: ") + QLatin1String("\"") + stop.second.name() + QLatin1String("\";\n"); str += QLatin1String("color: ") + QLatin1String("\"") + stop.second.name() + QLatin1String("\";\n");

View File

@@ -77,7 +77,8 @@ void GradientLine::readGradient()
if (m_useGradient) { if (m_useGradient) {
m_colorList.clear(); m_colorList.clear();
m_stops.clear(); m_stops.clear();
foreach (const QGradientStop &stop, m_gradient.stops()) { const QGradientStops stops = m_gradient.stops();
for (const QGradientStop &stop : stops) {
m_stops << stop.first; m_stops << stop.first;
m_colorList << stop.second; m_colorList << stop.second;
} }