tests: port assorted trivial uses of Q_FOREACH to ranged for loops
All of these fall into the trivial category: loops over (readily made) const local containers. As such, they cannot possibly depend on the safety copy that Q_FOREACH performs, so are safe to port as-is to ranged for loops. There may be more where these came from, but these were the ones that stood out as immediately obvious when scanning the 100s of uses in qtbase, so I preferred to directly fix them over white-listing their files with QT_NO_FOREACH (which still may be necessary for some files, as this patch may not port all uses in that file). Task-nubmber: QTBUG-115839 Change-Id: I7b7893bec8254f902660dac24167113aca855029 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit f2f8820073488c89fb71e3eb2d2e87bb582c3995) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
55e5ab8d57
commit
0603c8be97
@ -856,8 +856,8 @@ void tst_QPluginLoader::loadMachO_data()
|
|||||||
QTest::newRow("machtest/good.fat.stub-i386.dylib") << false;
|
QTest::newRow("machtest/good.fat.stub-i386.dylib") << false;
|
||||||
|
|
||||||
QDir d(QFINDTESTDATA("machtest"));
|
QDir d(QFINDTESTDATA("machtest"));
|
||||||
QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
|
const QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
|
||||||
foreach (const QString &bad, badlist)
|
for (const QString &bad : badlist)
|
||||||
QTest::newRow(qPrintable("machtest/" + bad)) << false;
|
QTest::newRow(qPrintable("machtest/" + bad)) << false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1028,11 +1028,12 @@ void tst_QFileSystemModel::drives()
|
|||||||
QFileSystemModel model;
|
QFileSystemModel model;
|
||||||
model.setRootPath(path);
|
model.setRootPath(path);
|
||||||
model.fetchMore(QModelIndex());
|
model.fetchMore(QModelIndex());
|
||||||
QFileInfoList drives = QDir::drives();
|
const QFileInfoList drives = QDir::drives();
|
||||||
int driveCount = 0;
|
int driveCount = 0;
|
||||||
foreach(const QFileInfo& driveRoot, drives)
|
for (const QFileInfo& driveRoot : drives) {
|
||||||
if (driveRoot.exists())
|
if (driveRoot.exists())
|
||||||
driveCount++;
|
driveCount++;
|
||||||
|
}
|
||||||
QTRY_COMPARE(model.rowCount(), driveCount);
|
QTRY_COMPARE(model.rowCount(), driveCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,8 +319,8 @@ void tst_QFontDatabase::fallbackFonts()
|
|||||||
layout.createLine();
|
layout.createLine();
|
||||||
layout.endLayout();
|
layout.endLayout();
|
||||||
|
|
||||||
QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
|
const QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
|
||||||
foreach (QGlyphRun run, runs) {
|
for (QGlyphRun run : runs) {
|
||||||
QRawFont rawFont = run.rawFont();
|
QRawFont rawFont = run.rawFont();
|
||||||
QVERIFY(rawFont.isValid());
|
QVERIFY(rawFont.isValid());
|
||||||
|
|
||||||
|
@ -490,7 +490,7 @@ void tst_QRawFont::supportedWritingSystems_data()
|
|||||||
void tst_QRawFont::supportedWritingSystems()
|
void tst_QRawFont::supportedWritingSystems()
|
||||||
{
|
{
|
||||||
QFETCH(QString, fileName);
|
QFETCH(QString, fileName);
|
||||||
QFETCH(WritingSystemList, writingSystems);
|
QFETCH(const WritingSystemList, writingSystems);
|
||||||
QFETCH(QFont::HintingPreference, hintingPreference);
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
||||||
|
|
||||||
QRawFont font(fileName, 10, hintingPreference);
|
QRawFont font(fileName, 10, hintingPreference);
|
||||||
@ -499,7 +499,7 @@ void tst_QRawFont::supportedWritingSystems()
|
|||||||
WritingSystemList actualWritingSystems = font.supportedWritingSystems();
|
WritingSystemList actualWritingSystems = font.supportedWritingSystems();
|
||||||
QCOMPARE(actualWritingSystems.size(), writingSystems.size());
|
QCOMPARE(actualWritingSystems.size(), writingSystems.size());
|
||||||
|
|
||||||
foreach (QFontDatabase::WritingSystem writingSystem, writingSystems)
|
for (QFontDatabase::WritingSystem writingSystem : writingSystems)
|
||||||
QVERIFY(actualWritingSystems.contains(writingSystem));
|
QVERIFY(actualWritingSystems.contains(writingSystem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,11 +166,11 @@ void tst_QNetworkRequest::rawHeaderList_data()
|
|||||||
|
|
||||||
void tst_QNetworkRequest::rawHeaderList()
|
void tst_QNetworkRequest::rawHeaderList()
|
||||||
{
|
{
|
||||||
QFETCH(QList<QByteArray>, set);
|
QFETCH(const QList<QByteArray>, set);
|
||||||
QFETCH(QList<QByteArray>, expected);
|
QFETCH(QList<QByteArray>, expected);
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
foreach (QByteArray header, set)
|
for (const QByteArray &header : set)
|
||||||
request.setRawHeader(header, "a value");
|
request.setRawHeader(header, "a value");
|
||||||
|
|
||||||
QList<QByteArray> got = request.rawHeaderList();
|
QList<QByteArray> got = request.rawHeaderList();
|
||||||
|
@ -190,9 +190,9 @@ QString tst_QDnsLookup::domainName(const QString &input)
|
|||||||
|
|
||||||
QString tst_QDnsLookup::domainNameList(const QString &input)
|
QString tst_QDnsLookup::domainNameList(const QString &input)
|
||||||
{
|
{
|
||||||
QStringList list = input.split(QLatin1Char(';'));
|
const QStringList list = input.split(QLatin1Char(';'));
|
||||||
QString result;
|
QString result;
|
||||||
foreach (const QString &s, list) {
|
for (const QString &s : list) {
|
||||||
if (!result.isEmpty())
|
if (!result.isEmpty())
|
||||||
result += ';';
|
result += ';';
|
||||||
result += domainName(s);
|
result += domainName(s);
|
||||||
|
@ -71,8 +71,8 @@ void tst_QNetworkInterface::initTestCase()
|
|||||||
void tst_QNetworkInterface::dump()
|
void tst_QNetworkInterface::dump()
|
||||||
{
|
{
|
||||||
// This is for manual testing:
|
// This is for manual testing:
|
||||||
QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
|
const QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
|
||||||
foreach (const QNetworkInterface &i, allInterfaces) {
|
for (const QNetworkInterface &i : allInterfaces) {
|
||||||
QString flags;
|
QString flags;
|
||||||
if (i.flags() & QNetworkInterface::IsUp) flags += "Up,";
|
if (i.flags() & QNetworkInterface::IsUp) flags += "Up,";
|
||||||
if (i.flags() & QNetworkInterface::IsRunning) flags += "Running,";
|
if (i.flags() & QNetworkInterface::IsRunning) flags += "Running,";
|
||||||
|
@ -487,8 +487,8 @@ void tst_QTcpSocket::bind_data()
|
|||||||
bool testIpv6 = false;
|
bool testIpv6 = false;
|
||||||
|
|
||||||
// iterate all interfaces, add all addresses on them as test data
|
// iterate all interfaces, add all addresses on them as test data
|
||||||
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
||||||
foreach (const QNetworkInterface &netinterface, interfaces) {
|
for (const QNetworkInterface &netinterface : interfaces) {
|
||||||
if (!netinterface.isValid())
|
if (!netinterface.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -138,13 +138,13 @@ void tst_QSslCertificate::initTestCase()
|
|||||||
testDataDir += QLatin1String("/");
|
testDataDir += QLatin1String("/");
|
||||||
|
|
||||||
QDir dir(testDataDir + "certificates");
|
QDir dir(testDataDir + "certificates");
|
||||||
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
|
const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
|
||||||
QRegularExpression rxCert(QLatin1String("^.+\\.(pem|der)$"));
|
QRegularExpression rxCert(QLatin1String("^.+\\.(pem|der)$"));
|
||||||
QRegularExpression rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
|
QRegularExpression rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
|
||||||
QRegularExpression rxPubKey(QLatin1String("^(.+\\.(?:pem|der))\\.pubkey$"));
|
QRegularExpression rxPubKey(QLatin1String("^(.+\\.(?:pem|der))\\.pubkey$"));
|
||||||
QRegularExpression rxDigest(QLatin1String("^(.+\\.(?:pem|der))\\.digest-(md5|sha1)$"));
|
QRegularExpression rxDigest(QLatin1String("^(.+\\.(?:pem|der))\\.digest-(md5|sha1)$"));
|
||||||
QRegularExpressionMatch match;
|
QRegularExpressionMatch match;
|
||||||
foreach (QFileInfo fileInfo, fileInfoList) {
|
for (const QFileInfo &fileInfo : fileInfoList) {
|
||||||
if ((match = rxCert.match(fileInfo.fileName())).hasMatch())
|
if ((match = rxCert.match(fileInfo.fileName())).hasMatch())
|
||||||
certInfoList <<
|
certInfoList <<
|
||||||
CertInfo(fileInfo,
|
CertInfo(fileInfo,
|
||||||
|
@ -336,11 +336,11 @@ void tst_QPrinterInfo::testAssignment()
|
|||||||
|
|
||||||
void tst_QPrinterInfo::namedPrinter()
|
void tst_QPrinterInfo::namedPrinter()
|
||||||
{
|
{
|
||||||
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
|
const QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
|
||||||
|
|
||||||
QStringList printerNames;
|
QStringList printerNames;
|
||||||
|
|
||||||
foreach (const QPrinterInfo &pi, printers) {
|
for (const QPrinterInfo &pi : printers) {
|
||||||
QPrinterInfo pi2 = QPrinterInfo::printerInfo(pi.printerName());
|
QPrinterInfo pi2 = QPrinterInfo::printerInfo(pi.printerName());
|
||||||
QCOMPARE(pi2.printerName(), pi.printerName());
|
QCOMPARE(pi2.printerName(), pi.printerName());
|
||||||
QCOMPARE(pi2.description(), pi.description());
|
QCOMPARE(pi2.description(), pi.description());
|
||||||
|
@ -199,7 +199,7 @@ void runVerifyDeployment(const QString &name)
|
|||||||
const QList<QString> parts = QString::fromLocal8Bit(libraries).split("dyld: loaded:");
|
const QList<QString> parts = QString::fromLocal8Bit(libraries).split("dyld: loaded:");
|
||||||
const QString qtPath = QLibraryInfo::path(QLibraryInfo::PrefixPath);
|
const QString qtPath = QLibraryInfo::path(QLibraryInfo::PrefixPath);
|
||||||
// Let assume Qt is not installed in system
|
// Let assume Qt is not installed in system
|
||||||
foreach (QString part, parts) {
|
for (const QString &part : parts) {
|
||||||
part = part.trimmed();
|
part = part.trimmed();
|
||||||
if (part.isEmpty())
|
if (part.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
@ -745,8 +745,8 @@ void PaintCommands::runCommand(const QString &scriptLine)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString firstWord = scriptLine.section(separators, 0, 0);
|
QString firstWord = scriptLine.section(separators, 0, 0);
|
||||||
QList<int> indices = s_commandHash.values(firstWord);
|
const QList<int> indices = s_commandHash.values(firstWord);
|
||||||
foreach(int idx, indices) {
|
for (int idx : indices) {
|
||||||
PaintCommandInfos command = s_commandInfoTable.at(idx);
|
PaintCommandInfos command = s_commandInfoTable.at(idx);
|
||||||
Q_ASSERT(command.regExp.isValid());
|
Q_ASSERT(command.regExp.isValid());
|
||||||
QRegularExpressionMatch match = command.regExp.match(scriptLine);
|
QRegularExpressionMatch match = command.regExp.match(scriptLine);
|
||||||
|
@ -143,8 +143,8 @@ MainWindow::MainWindow()
|
|||||||
void MainWindow::setDirectory(const QString &path)
|
void MainWindow::setDirectory(const QString &path)
|
||||||
{
|
{
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
QStringList files = dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot);
|
const QStringList files = dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot);
|
||||||
foreach(const QString &file, files) {
|
for (const QString &file : files) {
|
||||||
QImageReader img(path + QLatin1Char('/') +file);
|
QImageReader img(path + QLatin1Char('/') +file);
|
||||||
QImage image = img.read();
|
QImage image = img.read();
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
|
@ -84,8 +84,8 @@ void DragWidget::dropEvent(QDropEvent *event)
|
|||||||
{
|
{
|
||||||
if (event->mimeData()->hasText()) {
|
if (event->mimeData()->hasText()) {
|
||||||
const QMimeData *mime = event->mimeData();
|
const QMimeData *mime = event->mimeData();
|
||||||
QStringList pieces = mime->text().split(QRegularExpression("\\s+"),
|
const QStringList pieces = mime->text().split(QRegularExpression("\\s+"),
|
||||||
Qt::SkipEmptyParts);
|
Qt::SkipEmptyParts);
|
||||||
QPoint position = event->pos();
|
QPoint position = event->pos();
|
||||||
QPoint hotSpot;
|
QPoint hotSpot;
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ void DragWidget::dropEvent(QDropEvent *event)
|
|||||||
dropTimer.start(500, this);
|
dropTimer.start(500, this);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
foreach (QString piece, pieces) {
|
for (const QString &piece : pieces) {
|
||||||
FramedLabel *newLabel = new FramedLabel(piece, this);
|
FramedLabel *newLabel = new FramedLabel(piece, this);
|
||||||
newLabel->move(position - hotSpot);
|
newLabel->move(position - hotSpot);
|
||||||
newLabel->show();
|
newLabel->show();
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
QList<CustomGroup*> CustomScene::selectedCustomGroups() const
|
QList<CustomGroup*> CustomScene::selectedCustomGroups() const
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem*> all = selectedItems();
|
const QList<QGraphicsItem*> all = selectedItems();
|
||||||
QList<CustomGroup*> groups;
|
QList<CustomGroup*> groups;
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, all) {
|
for (QGraphicsItem *item : all) {
|
||||||
CustomGroup* group = qgraphicsitem_cast<CustomGroup*>(item);
|
CustomGroup* group = qgraphicsitem_cast<CustomGroup*>(item);
|
||||||
if (group)
|
if (group)
|
||||||
groups.append(group);
|
groups.append(group);
|
||||||
@ -23,10 +23,10 @@ QList<CustomGroup*> CustomScene::selectedCustomGroups() const
|
|||||||
|
|
||||||
QList<CustomItem*> CustomScene::selectedCustomItems() const
|
QList<CustomItem*> CustomScene::selectedCustomItems() const
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem*> all = selectedItems();
|
const QList<QGraphicsItem*> all = selectedItems();
|
||||||
QList<CustomItem*> items;
|
QList<CustomItem*> items;
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, all) {
|
for (QGraphicsItem *item : all) {
|
||||||
CustomItem* citem = qgraphicsitem_cast<CustomItem*>(item);
|
CustomItem* citem = qgraphicsitem_cast<CustomItem*>(item);
|
||||||
if (citem)
|
if (citem)
|
||||||
items.append(citem);
|
items.append(citem);
|
||||||
|
@ -95,15 +95,15 @@ void Widget::on_scaleItem_valueChanged(int value)
|
|||||||
|
|
||||||
void Widget::on_group_clicked()
|
void Widget::on_group_clicked()
|
||||||
{
|
{
|
||||||
QList<QGraphicsItem*> all = scene->selectedItems();
|
const QList<QGraphicsItem*> all = scene->selectedItems();
|
||||||
if (all.size() < 2)
|
if (all.size() < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList<CustomItem*> items = scene->selectedCustomItems();
|
const QList<CustomItem*> items = scene->selectedCustomItems();
|
||||||
QList<CustomGroup*> groups = scene->selectedCustomGroups();
|
QList<CustomGroup*> groups = scene->selectedCustomGroups();
|
||||||
|
|
||||||
if (groups.size() == 1) {
|
if (groups.size() == 1) {
|
||||||
foreach (CustomItem *item, items) {
|
for (CustomItem *item : items) {
|
||||||
item->setSelected(false);
|
item->setSelected(false);
|
||||||
groups[0]->addToGroup(item);
|
groups[0]->addToGroup(item);
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ void Widget::on_group_clicked()
|
|||||||
|
|
||||||
CustomGroup* group = new CustomGroup;
|
CustomGroup* group = new CustomGroup;
|
||||||
scene->addItem(group);
|
scene->addItem(group);
|
||||||
foreach (QGraphicsItem *item, all) {
|
for (QGraphicsItem *item : all) {
|
||||||
item->setSelected(false);
|
item->setSelected(false);
|
||||||
group->addToGroup(item);
|
group->addToGroup(item);
|
||||||
}
|
}
|
||||||
@ -124,9 +124,9 @@ void Widget::on_group_clicked()
|
|||||||
|
|
||||||
void Widget::on_dismantle_clicked()
|
void Widget::on_dismantle_clicked()
|
||||||
{
|
{
|
||||||
QList<CustomGroup*> groups = scene->selectedCustomGroups();
|
const QList<CustomGroup*> groups = scene->selectedCustomGroups();
|
||||||
|
|
||||||
foreach (CustomGroup *group, groups) {
|
for (CustomGroup *group : groups) {
|
||||||
foreach (QGraphicsItem *item, group->childItems())
|
foreach (QGraphicsItem *item, group->childItems())
|
||||||
group->removeFromGroup(item);
|
group->removeFromGroup(item);
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ Window::Window()
|
|||||||
|
|
||||||
localeCombo->addItem("System", QLocale::system());
|
localeCombo->addItem("System", QLocale::system());
|
||||||
|
|
||||||
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyTerritory);
|
const QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyTerritory);
|
||||||
foreach (const QLocale &locale, locales) {
|
for (const QLocale &locale : locales) {
|
||||||
QString label = QLocale::languageToString(locale.language());
|
QString label = QLocale::languageToString(locale.language());
|
||||||
label += QLatin1Char('/');
|
label += QLatin1Char('/');
|
||||||
if (locale.script() != QLocale::AnyScript) {
|
if (locale.script() != QLocale::AnyScript) {
|
||||||
|
@ -85,8 +85,8 @@ void PropertyWatcher::setSubject(QObject *s, const QString &annotation)
|
|||||||
|
|
||||||
void PropertyWatcher::updateAllFields()
|
void PropertyWatcher::updateAllFields()
|
||||||
{
|
{
|
||||||
QList<PropertyField *> fields = findChildren<PropertyField*>();
|
const QList<PropertyField *> fields = findChildren<PropertyField*>();
|
||||||
foreach (PropertyField *field, fields)
|
for (PropertyField *field : fields)
|
||||||
field->propertyChanged();
|
field->propertyChanged();
|
||||||
emit updatedAllFields(this);
|
emit updatedAllFields(this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user