Skip to content

Commit 6a5d0c6

Browse files
committed
Kill Q_FOREACH in analysis
1 parent 4a87cc9 commit 6a5d0c6

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

src/analysis/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ IF(HAVE_OPENCL)
433433
TARGET_LINK_LIBRARIES(qgis_analysis ${OpenCL_LIBRARIES})
434434
ENDIF(HAVE_OPENCL)
435435

436+
TARGET_COMPILE_DEFINITIONS(qgis_analysis PRIVATE "-DQT_NO_FOREACH")
436437

437438
# clang-tidy
438439
IF(CLANG_TIDY_EXE)

src/analysis/processing/qgsalgorithmclip.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
144144
QgsFeatureIds testedFeatureIds;
145145

146146
int i = -1;
147-
Q_FOREACH ( const QgsGeometry &clipGeom, clipGeoms )
147+
const auto constClipGeoms = clipGeoms;
148+
for ( const QgsGeometry &clipGeom : constClipGeoms )
148149
{
149150
i++;
150151
if ( feedback->isCanceled() )
@@ -165,7 +166,8 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
165166
step = 100.0 / inputFeatures.length();
166167

167168
int current = 0;
168-
Q_FOREACH ( const QgsFeature &inputFeature, inputFeatures )
169+
const auto constInputFeatures = inputFeatures;
170+
for ( const QgsFeature &inputFeature : constInputFeatures )
169171
{
170172
if ( feedback->isCanceled() )
171173
{

src/analysis/processing/qgsalgorithmdissolve.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
8989
else
9090
{
9191
QList< int > fieldIndexes;
92-
Q_FOREACH ( const QString &field, fields )
92+
const auto constFields = fields;
93+
for ( const QString &field : constFields )
9394
{
9495
int index = source->fields().lookupField( field );
9596
if ( index >= 0 )
@@ -107,7 +108,8 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
107108
}
108109

109110
QVariantList indexAttributes;
110-
Q_FOREACH ( int index, fieldIndexes )
111+
const auto constFieldIndexes = fieldIndexes;
112+
for ( int index : constFieldIndexes )
111113
{
112114
indexAttributes << f.attribute( index );
113115
}

src/analysis/raster/qgsalignraster.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ bool QgsAlignRaster::run()
363363

364364
//dump();
365365

366-
Q_FOREACH ( const Item &r, mRasters )
366+
const auto constMRasters = mRasters;
367+
for ( const Item &r : constMRasters )
367368
{
368369
if ( !createAndWarp( r ) )
369370
return false;
@@ -398,7 +399,8 @@ int QgsAlignRaster::suggestedReferenceLayer() const
398399
QgsCoordinateReferenceSystem destCRS( QStringLiteral( "EPSG:4326" ) );
399400
QString destWkt = destCRS.toWkt();
400401

401-
Q_FOREACH ( const Item &raster, mRasters )
402+
const auto constMRasters = mRasters;
403+
for ( const Item &raster : constMRasters )
402404
{
403405
if ( !suggestedWarpOutput( RasterInfo( raster.inputFilename ), destWkt, &cs ) )
404406
return false;

src/analysis/vector/qgsgeometrysnapper.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ class Raytracer
186186

187187
QgsSnapIndex::GridRow::~GridRow()
188188
{
189-
Q_FOREACH ( const QgsSnapIndex::Cell &cell, mCells )
189+
const auto constMCells = mCells;
190+
for ( const QgsSnapIndex::Cell &cell : constMCells )
190191
{
191192
qDeleteAll( cell );
192193
}
@@ -373,7 +374,7 @@ QgsPoint QgsSnapIndex::getClosestSnapToPoint( const QgsPoint &p, const QgsPoint
373374
{
374375
continue;
375376
}
376-
Q_FOREACH ( const SnapItem *item, *cell )
377+
for ( const SnapItem *item : *cell )
377378
{
378379
if ( item->type == SnapSegment )
379380
{
@@ -415,7 +416,8 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, double t
415416
QgsSnapIndex::SegmentSnapItem *snapSegment = nullptr;
416417
QgsSnapIndex::PointSnapItem *snapPoint = nullptr;
417418

418-
Q_FOREACH ( QgsSnapIndex::SnapItem *item, items )
419+
const auto constItems = items;
420+
for ( QgsSnapIndex::SnapItem *item : constItems )
419421
{
420422
if ( ( ! endPointOnly && item->type == SnapPoint ) || item->type == SnapEndPoint )
421423
{
@@ -510,7 +512,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
510512
QgsPoint( geometry.constGet()->boundingBox().center() );
511513

512514
QgsSnapIndex refSnapIndex( center, 10 * snapTolerance );
513-
Q_FOREACH ( const QgsGeometry &geom, referenceGeometries )
515+
for ( const QgsGeometry &geom : referenceGeometries )
514516
{
515517
refSnapIndex.addGeometry( geom.constGet() );
516518
}
@@ -624,7 +626,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
624626
origSubjSnapIndex->addGeometry( origSubjGeom.get() );
625627

626628
// Pass 2: add missing vertices to subject geometry
627-
Q_FOREACH ( const QgsGeometry &refGeom, referenceGeometries )
629+
for ( const QgsGeometry &refGeom : referenceGeometries )
628630
{
629631
for ( int iPart = 0, nParts = refGeom.constGet()->partCount(); iPart < nParts; ++iPart )
630632
{
@@ -760,7 +762,8 @@ QgsGeometry QgsInternalGeometrySnapper::snapFeature( const QgsFeature &feature )
760762
if ( !refFeatureIds.isEmpty() )
761763
{
762764
QList< QgsGeometry > refGeometries;
763-
Q_FOREACH ( QgsFeatureId id, refFeatureIds )
765+
const auto constRefFeatureIds = refFeatureIds;
766+
for ( QgsFeatureId id : constRefFeatureIds )
764767
{
765768
refGeometries << mProcessedGeometries.value( id );
766769
}

0 commit comments

Comments
 (0)