Skip to content

Commit a6665d4

Browse files
committed
Kill them Q_FOREACH
1 parent a063363 commit a6665d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+488
-256
lines changed

src/providers/db2/qgsdb2dataitems.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void QgsDb2ConnectionItem::refresh()
137137
QVector<QgsDataItem *> items = createChildren();
138138

139139
// Add new items
140-
Q_FOREACH ( QgsDataItem *item, items )
140+
const auto constItems = items;
141+
for ( QgsDataItem *item : constItems )
141142
{
142143
// Is it present in children?
143144
int index = findItem( mChildren, item );
@@ -202,7 +203,8 @@ QVector<QgsDataItem *> QgsDb2ConnectionItem::createChildren()
202203
while ( db2GC.populateLayerProperty( layer ) )
203204
{
204205
QgsDb2SchemaItem *schemaItem = nullptr;
205-
Q_FOREACH ( QgsDataItem *child, children )
206+
const auto constChildren = children;
207+
for ( QgsDataItem *child : constChildren )
206208
{
207209
if ( child->name() == layer.schemaName )
208210
{
@@ -325,7 +327,8 @@ bool QgsDb2ConnectionItem::handleDrop( const QMimeData *data, const QString &toS
325327
bool hasError = false;
326328

327329
QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data );
328-
Q_FOREACH ( const QgsMimeDataUtils::Uri &u, lst )
330+
const auto constLst = lst;
331+
for ( const QgsMimeDataUtils::Uri &u : constLst )
329332
{
330333
if ( u.layerType != QLatin1String( "vector" ) )
331334
{
@@ -415,7 +418,8 @@ QVector<QgsDataItem *> QgsDb2RootItem::createChildren()
415418
QVector<QgsDataItem *> connections;
416419
QgsSettings settings;
417420
settings.beginGroup( QStringLiteral( "/DB2/connections" ) );
418-
Q_FOREACH ( const QString &connName, settings.childGroups() )
421+
const auto constChildGroups = settings.childGroups();
422+
for ( const QString &connName : constChildGroups )
419423
{
420424
connections << new QgsDb2ConnectionItem( this, connName, mPath + "/" + connName );
421425
}
@@ -498,7 +502,8 @@ QVector<QgsDataItem *> QgsDb2SchemaItem::createChildren()
498502

499503
QVector<QgsDataItem *>items;
500504

501-
Q_FOREACH ( QgsDataItem *child, this->children() )
505+
const auto constChildren = this->children();
506+
for ( QgsDataItem *child : constChildren )
502507
{
503508
items.append( ( ( QgsDb2LayerItem * )child )->createClone() );
504509
}
@@ -508,7 +513,8 @@ QVector<QgsDataItem *> QgsDb2SchemaItem::createChildren()
508513
void QgsDb2SchemaItem::addLayers( QgsDataItem *newLayers )
509514
{
510515
// Add new items
511-
Q_FOREACH ( QgsDataItem *child, newLayers->children() )
516+
const auto constChildren = newLayers->children();
517+
for ( QgsDataItem *child : constChildren )
512518
{
513519
// Is it present in children?
514520
if ( findItem( mChildren, child ) >= 0 )

src/providers/db2/qgsdb2featureiterator.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
9393
attrs = attributeIndexes.toList();
9494
}
9595

96-
Q_FOREACH ( int i, attrs )
96+
const auto constAttrs = attrs;
97+
for ( int i : constAttrs )
9798
{
9899
QString fieldname = mSource->mFields.at( i ).name();
99100
if ( mSource->mFidColName == fieldname )
@@ -161,7 +162,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
161162
{
162163
QString delim;
163164
QString inClause = QStringLiteral( "%1 IN (" ).arg( mSource->mFidColName );
164-
Q_FOREACH ( QgsFeatureId featureId, mRequest.filterFids() )
165+
const auto constFilterFids = mRequest.filterFids();
166+
for ( QgsFeatureId featureId : constFilterFids )
165167
{
166168
inClause += delim + FID_TO_STRING( featureId );
167169
delim = ',';
@@ -225,7 +227,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
225227
QgsDebugMsg( QStringLiteral( "compileExpressions: %1" ).arg( QgsSettings().value( "qgis/compileExpressions", true ).toString() ) );
226228
if ( QgsSettings().value( QStringLiteral( "qgis/compileExpressions" ), true ).toBool() && limitAtProvider )
227229
{
228-
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &clause, request.orderBy() )
230+
const auto constOrderBy = request.orderBy();
231+
for ( const QgsFeatureRequest::OrderByClause &clause : constOrderBy )
229232
{
230233
QgsDebugMsg( QStringLiteral( "processing a clause; ascending: %1; nullsFirst: %2" ).arg( clause.ascending() ).arg( clause.nullsFirst() ) );
231234

src/providers/delimitedtext/qgsdelimitedtextfile.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ void QgsDelimitedTextFile::setDiscardEmptyFields( bool discardEmptyFields )
402402
void QgsDelimitedTextFile::setFieldNames( const QStringList &names )
403403
{
404404
mFieldNames.clear();
405-
Q_FOREACH ( QString name, names )
405+
const auto constNames = names;
406+
for ( QString name : constNames )
406407
{
407408
bool nameOk = true;
408409
int fieldNo = mFieldNames.size() + 1;

src/providers/delimitedtext/qgsdelimitedtextprovider.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ void QgsDelimitedTextProvider::clearInvalidLines() const
901901

902902
bool QgsDelimitedTextProvider::recordIsEmpty( QStringList &record )
903903
{
904-
Q_FOREACH ( const QString &s, record )
904+
const auto constRecord = record;
905+
for ( const QString &s : constRecord )
905906
{
906907
if ( ! s.isEmpty() )
907908
return false;
@@ -927,7 +928,8 @@ void QgsDelimitedTextProvider::reportErrors( const QStringList &messages, bool s
927928
{
928929
QString tag( QStringLiteral( "DelimitedText" ) );
929930
QgsMessageLog::logMessage( tr( "Errors in file %1" ).arg( mFile->fileName() ), tag );
930-
Q_FOREACH ( const QString &message, messages )
931+
const auto constMessages = messages;
932+
for ( const QString &message : constMessages )
931933
{
932934
QgsMessageLog::logMessage( message, tag );
933935
}
@@ -946,7 +948,8 @@ void QgsDelimitedTextProvider::reportErrors( const QStringList &messages, bool s
946948
QgsMessageOutput *output = QgsMessageOutput::createMessageOutput();
947949
output->setTitle( tr( "Delimited text file errors" ) );
948950
output->setMessage( tr( "Errors in file %1" ).arg( mFile->fileName() ), QgsMessageOutput::MessageText );
949-
Q_FOREACH ( const QString &message, messages )
951+
const auto constMessages = messages;
952+
for ( const QString &message : constMessages )
950953
{
951954
output->appendMessage( message );
952955
}

src/providers/gdal/qgsgdaldataitems.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ QgsDataItem *QgsGdalDataItemProvider::createDataItem( const QString &pathIn, Qgs
276276
if ( !sExtensions.contains( suffix ) )
277277
{
278278
bool matches = false;
279-
Q_FOREACH ( const QString &wildcard, sWildcards )
279+
const auto constSWildcards = sWildcards;
280+
for ( const QString &wildcard : constSWildcards )
280281
{
281282
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
282283
if ( rx.exactMatch( info.fileName() ) )

src/providers/gdal/qgsgdalprovider.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,8 @@ QgsRasterHistogram QgsGdalProvider::histogram( int bandNo,
14911491
initHistogram( myHistogram, bandNo, binCount, minimum, maximum, boundingBox, sampleSize, includeOutOfRange );
14921492

14931493
// Find cached
1494-
Q_FOREACH ( const QgsRasterHistogram &histogram, mHistograms )
1494+
const auto constMHistograms = mHistograms;
1495+
for ( const QgsRasterHistogram &histogram : constMHistograms )
14951496
{
14961497
if ( histogram == myHistogram )
14971498
{
@@ -1709,7 +1710,8 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
17091710
// add any driver-specific configuration options, save values to be restored later
17101711
if ( format != QgsRaster::PyramidsErdas && ! configOptions.isEmpty() )
17111712
{
1712-
Q_FOREACH ( const QString &option, configOptions )
1713+
const auto constConfigOptions = configOptions;
1714+
for ( const QString &option : constConfigOptions )
17131715
{
17141716
QStringList opt = option.split( '=' );
17151717
if ( opt.size() == 2 )
@@ -1956,7 +1958,8 @@ QList<QgsRasterPyramid> QgsGdalProvider::buildPyramidList( QList<int> overviewLi
19561958
}
19571959

19581960
// loop over pyramid list
1959-
Q_FOREACH ( int myDivisor, overviewList )
1961+
const auto constOverviewList = overviewList;
1962+
for ( int myDivisor : constOverviewList )
19601963
{
19611964
//
19621965
// First we build up a list of potential pyramid layers
@@ -2439,7 +2442,8 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int bandNo, int stats, const
24392442
QgsRasterBandStats myRasterBandStats;
24402443
initStatistics( myRasterBandStats, bandNo, stats, boundingBox, sampleSize );
24412444

2442-
Q_FOREACH ( const QgsRasterBandStats &stats, mStatistics )
2445+
const auto constMStatistics = mStatistics;
2446+
for ( const QgsRasterBandStats &stats : constMStatistics )
24432447
{
24442448
if ( stats.contains( myRasterBandStats ) )
24452449
{
@@ -2891,7 +2895,8 @@ void QgsGdalProvider::initBaseDataset()
28912895
char **papszFromStringList( const QStringList &list )
28922896
{
28932897
char **papszRetList = nullptr;
2894-
Q_FOREACH ( const QString &elem, list )
2898+
const auto constList = list;
2899+
for ( const QString &elem : constList )
28952900
{
28962901
papszRetList = CSLAddString( papszRetList, elem.toLocal8Bit().constData() );
28972902
}
@@ -3102,7 +3107,8 @@ QString QgsGdalProvider::validateCreationOptions( const QStringList &createOptio
31023107

31033108
// prepare a map for easier lookup
31043109
QMap< QString, QString > optionsMap;
3105-
Q_FOREACH ( const QString &option, createOptions )
3110+
const auto constCreateOptions = createOptions;
3111+
for ( const QString &option : constCreateOptions )
31063112
{
31073113
QStringList opt = option.split( '=' );
31083114
optionsMap[ opt[0].toUpper()] = opt[1];

src/providers/grass/qgis.v.in.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void writePoint( struct Map_info *map, int type, const QgsPointXY &point, struct
5555
void writePolyline( struct Map_info *map, int type, const QgsPolylineXY &polyline, struct line_cats *cats )
5656
{
5757
Vect_reset_line( gLine );
58-
Q_FOREACH ( const QgsPointXY &point, polyline )
58+
const auto constPolyline = polyline;
59+
for ( const QgsPointXY &point : constPolyline )
5960
{
6061
Vect_append_point( gLine, point.x(), point.y(), 0 );
6162
}
@@ -259,7 +260,8 @@ int main( int argc, char **argv )
259260
else if ( geometryType == QgsWkbTypes::MultiPoint )
260261
{
261262
QgsMultiPointXY multiPoint = geometry.asMultiPoint();
262-
Q_FOREACH ( const QgsPointXY &point, multiPoint )
263+
const auto constMultiPoint = multiPoint;
264+
for ( const QgsPointXY &point : constMultiPoint )
263265
{
264266
writePoint( map, GV_POINT, point, cats );
265267
}
@@ -272,25 +274,29 @@ int main( int argc, char **argv )
272274
else if ( geometryType == QgsWkbTypes::MultiLineString )
273275
{
274276
QgsMultiPolylineXY multiPolyline = geometry.asMultiPolyline();
275-
Q_FOREACH ( const QgsPolylineXY &polyline, multiPolyline )
277+
const auto constMultiPolyline = multiPolyline;
278+
for ( const QgsPolylineXY &polyline : constMultiPolyline )
276279
{
277280
writePolyline( map, GV_LINE, polyline, cats );
278281
}
279282
}
280283
else if ( geometryType == QgsWkbTypes::Polygon )
281284
{
282285
QgsPolygonXY polygon = geometry.asPolygon();
283-
Q_FOREACH ( const QgsPolylineXY &polyline, polygon )
286+
const auto constPolygon = polygon;
287+
for ( const QgsPolylineXY &polyline : constPolygon )
284288
{
285289
writePolyline( map, GV_BOUNDARY, polyline, cats );
286290
}
287291
}
288292
else if ( geometryType == QgsWkbTypes::MultiPolygon )
289293
{
290294
QgsMultiPolygonXY multiPolygon = geometry.asMultiPolygon();
291-
Q_FOREACH ( const QgsPolygonXY &polygon, multiPolygon )
295+
const auto constMultiPolygon = multiPolygon;
296+
for ( const QgsPolygonXY &polygon : constMultiPolygon )
292297
{
293-
Q_FOREACH ( const QgsPolylineXY &polyline, polygon )
298+
const auto constPolygon = polygon;
299+
for ( const QgsPolylineXY &polyline : constPolygon )
294300
{
295301
writePolyline( map, GV_BOUNDARY, polyline, cats );
296302
}
@@ -423,7 +429,8 @@ int main( int argc, char **argv )
423429
}
424430

425431
QList<QgsFeatureId> idList = spatialIndex.intersects( feature.geometry().boundingBox() );
426-
Q_FOREACH ( QgsFeatureId id, idList )
432+
const auto constIdList = idList;
433+
for ( QgsFeatureId id : constIdList )
427434
{
428435
QgsFeature &centroid = centroids[id];
429436
if ( feature.geometry().contains( centroid.geometry() ) )
@@ -451,7 +458,8 @@ int main( int argc, char **argv )
451458
if ( it.value().attributes().size() > 0 )
452459
{
453460
Vect_reset_cats( cats );
454-
Q_FOREACH ( const QVariant &attribute, it.value().attributes() )
461+
const auto constAttributes = it.value().attributes();
462+
for ( const QVariant &attribute : constAttributes )
455463
{
456464
Vect_cat_set( cats, 1, attribute.toInt() );
457465
}

src/providers/grass/qgsgrass.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,8 @@ QStringList QgsGrass::vectorLayers( const QString &gisdbase, const QString &loca
12931293
QgsDebugMsg( "GRASS vector successfully opened" );
12941294

12951295
// Get layers
1296-
Q_FOREACH ( QgsGrassVectorLayer *layer, vector.layers() )
1296+
const auto constLayers = vector.layers();
1297+
for ( QgsGrassVectorLayer *layer : constLayers )
12971298
{
12981299
QString fs = QString::number( layer->number() );
12991300
QgsDebugMsg( "layer number = " + fs );
@@ -1898,9 +1899,11 @@ QString QgsGrass::findModule( QString module )
18981899
paths << QgsGrass::grassModulesPaths();
18991900

19001901
// Extensions first to prefer .bat over .exe on Windows
1901-
Q_FOREACH ( const QString &ext, extensions )
1902+
const auto constExtensions = extensions;
1903+
for ( const QString &ext : constExtensions )
19021904
{
1903-
Q_FOREACH ( const QString &path, paths )
1905+
const auto constPaths = paths;
1906+
for ( const QString &path : constPaths )
19041907
{
19051908
QString full = module + ext;;
19061909
if ( !path.isEmpty() )
@@ -2426,7 +2429,8 @@ void QgsGrass::insertRow( dbDriver *driver, const QString &tableName,
24262429
}
24272430

24282431
QStringList valuesStringList;
2429-
Q_FOREACH ( const QVariant &attribute, attributes )
2432+
const auto constAttributes = attributes;
2433+
for ( const QVariant &attribute : constAttributes )
24302434
{
24312435
QString valueString;
24322436

src/providers/grass/qgsgrassfeatureiterator.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ bool QgsGrassFeatureIterator::fetchFeature( QgsFeature &feature )
246246
if ( mSource->mEditing )
247247
{
248248
QgsDebugMsgLevel( "newLids:", 3 );
249-
Q_FOREACH ( int oldLid, mSource->mLayer->map()->newLids().keys() )
249+
const auto constKeys = mSource->mLayer->map()->newLids().keys();
250+
for ( int oldLid : constKeys )
250251
{
251252
QgsDebugMsgLevel( QString( "%1 -> %2" ).arg( oldLid ).arg( mSource->mLayer->map()->newLids().value( oldLid ) ), 3 );
252253
}

src/providers/grass/qgsgrassprovider.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
11971197
#ifdef QGISDEBUG
11981198
QgsDebugMsg( "the feature is missing in buffer addedFeatures :" );
11991199

1200-
Q_FOREACH ( QgsFeatureId id, mEditBuffer->addedFeatures().keys() )
1200+
const auto constKeys = mEditBuffer->addedFeatures().keys();
1201+
for ( QgsFeatureId id : constKeys )
12011202
{
12021203
QgsDebugMsg( QString( "addedFeatures : id = %1" ).arg( id ) );
12031204
}
@@ -1272,7 +1273,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
12721273
// Currently neither entering new cat nor changing existing cat is allowed
12731274
#if 0
12741275
// There may be other new features with the same cat which we have to update
1275-
Q_FOREACH ( QgsFeatureId addedFid, addedFeatures.keys() )
1276+
const auto constKeys = addedFeatures.keys();
1277+
for ( QgsFeatureId addedFid : constKeys )
12761278
{
12771279
if ( addedFid == fid )
12781280
{
@@ -1302,7 +1304,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
13021304

13031305
// Update all changed attributes
13041306
QgsChangedAttributesMap &changedAttributes = const_cast<QgsChangedAttributesMap &>( mEditBuffer->changedAttributeValues() );
1305-
Q_FOREACH ( QgsFeatureId changedFid, changedAttributes.keys() )
1307+
const auto constKeys = changedAttributes.keys();
1308+
for ( QgsFeatureId changedFid : constKeys )
13061309
{
13071310
int changedCat = QgsGrassFeatureIterator::catFromFid( changedFid );
13081311
int realChangedCat = changedCat;
@@ -1315,7 +1318,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
13151318
if ( realChangedCat == newCat )
13161319
{
13171320
QgsAttributeMap attributeMap = changedAttributes[changedFid];
1318-
Q_FOREACH ( int index, attributeMap.keys() )
1321+
const auto constKeys = attributeMap.keys();
1322+
for ( int index : constKeys )
13191323
{
13201324
attributeMap[index] = feature.attributes().value( index );
13211325
}
@@ -2047,7 +2051,8 @@ void QgsGrassProvider::setMapset()
20472051

20482052
QgsGrassVectorMapLayer *QgsGrassProvider::otherEditLayer( int layerField )
20492053
{
2050-
Q_FOREACH ( QgsGrassVectorMapLayer *layer, mOtherEditLayers )
2054+
const auto constMOtherEditLayers = mOtherEditLayers;
2055+
for ( QgsGrassVectorMapLayer *layer : constMOtherEditLayers )
20512056
{
20522057
if ( layer->field() == layerField )
20532058
{

0 commit comments

Comments
 (0)