Skip to content

Commit

Permalink
Merge pull request #9738 from m-kuhn/kill_analysis_qforeach
Browse files Browse the repository at this point in the history
Kill Q_FOREACH in analysis
  • Loading branch information
m-kuhn committed Apr 7, 2019
2 parents 736e8cb + 6a5d0c6 commit b618e8d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -433,6 +433,7 @@ IF(HAVE_OPENCL)
TARGET_LINK_LIBRARIES(qgis_analysis ${OpenCL_LIBRARIES})
ENDIF(HAVE_OPENCL)

TARGET_COMPILE_DEFINITIONS(qgis_analysis PRIVATE "-DQT_NO_FOREACH")

# clang-tidy
IF(CLANG_TIDY_EXE)
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/processing/qgsalgorithmclip.cpp
Expand Up @@ -144,7 +144,8 @@ QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, Q
QgsFeatureIds testedFeatureIds;

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

int current = 0;
Q_FOREACH ( const QgsFeature &inputFeature, inputFeatures )
const auto constInputFeatures = inputFeatures;
for ( const QgsFeature &inputFeature : constInputFeatures )
{
if ( feedback->isCanceled() )
{
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/processing/qgsalgorithmdissolve.cpp
Expand Up @@ -89,7 +89,8 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
else
{
QList< int > fieldIndexes;
Q_FOREACH ( const QString &field, fields )
const auto constFields = fields;
for ( const QString &field : constFields )
{
int index = source->fields().lookupField( field );
if ( index >= 0 )
Expand All @@ -107,7 +108,8 @@ QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &paramet
}

QVariantList indexAttributes;
Q_FOREACH ( int index, fieldIndexes )
const auto constFieldIndexes = fieldIndexes;
for ( int index : constFieldIndexes )
{
indexAttributes << f.attribute( index );
}
Expand Down
6 changes: 4 additions & 2 deletions src/analysis/raster/qgsalignraster.cpp
Expand Up @@ -363,7 +363,8 @@ bool QgsAlignRaster::run()

//dump();

Q_FOREACH ( const Item &r, mRasters )
const auto constMRasters = mRasters;
for ( const Item &r : constMRasters )
{
if ( !createAndWarp( r ) )
return false;
Expand Down Expand Up @@ -398,7 +399,8 @@ int QgsAlignRaster::suggestedReferenceLayer() const
QgsCoordinateReferenceSystem destCRS( QStringLiteral( "EPSG:4326" ) );
QString destWkt = destCRS.toWkt();

Q_FOREACH ( const Item &raster, mRasters )
const auto constMRasters = mRasters;
for ( const Item &raster : constMRasters )
{
if ( !suggestedWarpOutput( RasterInfo( raster.inputFilename ), destWkt, &cs ) )
return false;
Expand Down
15 changes: 9 additions & 6 deletions src/analysis/vector/qgsgeometrysnapper.cpp
Expand Up @@ -186,7 +186,8 @@ class Raytracer

QgsSnapIndex::GridRow::~GridRow()
{
Q_FOREACH ( const QgsSnapIndex::Cell &cell, mCells )
const auto constMCells = mCells;
for ( const QgsSnapIndex::Cell &cell : constMCells )
{
qDeleteAll( cell );
}
Expand Down Expand Up @@ -373,7 +374,7 @@ QgsPoint QgsSnapIndex::getClosestSnapToPoint( const QgsPoint &p, const QgsPoint
{
continue;
}
Q_FOREACH ( const SnapItem *item, *cell )
for ( const SnapItem *item : *cell )
{
if ( item->type == SnapSegment )
{
Expand Down Expand Up @@ -415,7 +416,8 @@ QgsSnapIndex::SnapItem *QgsSnapIndex::getSnapItem( const QgsPoint &pos, double t
QgsSnapIndex::SegmentSnapItem *snapSegment = nullptr;
QgsSnapIndex::PointSnapItem *snapPoint = nullptr;

Q_FOREACH ( QgsSnapIndex::SnapItem *item, items )
const auto constItems = items;
for ( QgsSnapIndex::SnapItem *item : constItems )
{
if ( ( ! endPointOnly && item->type == SnapPoint ) || item->type == SnapEndPoint )
{
Expand Down Expand Up @@ -510,7 +512,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
QgsPoint( geometry.constGet()->boundingBox().center() );

QgsSnapIndex refSnapIndex( center, 10 * snapTolerance );
Q_FOREACH ( const QgsGeometry &geom, referenceGeometries )
for ( const QgsGeometry &geom : referenceGeometries )
{
refSnapIndex.addGeometry( geom.constGet() );
}
Expand Down Expand Up @@ -624,7 +626,7 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry &geometry, doubl
origSubjSnapIndex->addGeometry( origSubjGeom.get() );

// Pass 2: add missing vertices to subject geometry
Q_FOREACH ( const QgsGeometry &refGeom, referenceGeometries )
for ( const QgsGeometry &refGeom : referenceGeometries )
{
for ( int iPart = 0, nParts = refGeom.constGet()->partCount(); iPart < nParts; ++iPart )
{
Expand Down Expand Up @@ -760,7 +762,8 @@ QgsGeometry QgsInternalGeometrySnapper::snapFeature( const QgsFeature &feature )
if ( !refFeatureIds.isEmpty() )
{
QList< QgsGeometry > refGeometries;
Q_FOREACH ( QgsFeatureId id, refFeatureIds )
const auto constRefFeatureIds = refFeatureIds;
for ( QgsFeatureId id : constRefFeatureIds )
{
refGeometries << mProcessedGeometries.value( id );
}
Expand Down

0 comments on commit b618e8d

Please sign in to comment.