Skip to content

Commit

Permalink
Kill them Q_FOREACH
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent a063363 commit a6665d4
Show file tree
Hide file tree
Showing 59 changed files with 488 additions and 256 deletions.
18 changes: 12 additions & 6 deletions src/providers/db2/qgsdb2dataitems.cpp
Expand Up @@ -137,7 +137,8 @@ void QgsDb2ConnectionItem::refresh()
QVector<QgsDataItem *> items = createChildren();

// Add new items
Q_FOREACH ( QgsDataItem *item, items )
const auto constItems = items;
for ( QgsDataItem *item : constItems )
{
// Is it present in children?
int index = findItem( mChildren, item );
Expand Down Expand Up @@ -202,7 +203,8 @@ QVector<QgsDataItem *> QgsDb2ConnectionItem::createChildren()
while ( db2GC.populateLayerProperty( layer ) )
{
QgsDb2SchemaItem *schemaItem = nullptr;
Q_FOREACH ( QgsDataItem *child, children )
const auto constChildren = children;
for ( QgsDataItem *child : constChildren )
{
if ( child->name() == layer.schemaName )
{
Expand Down Expand Up @@ -325,7 +327,8 @@ bool QgsDb2ConnectionItem::handleDrop( const QMimeData *data, const QString &toS
bool hasError = false;

QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data );
Q_FOREACH ( const QgsMimeDataUtils::Uri &u, lst )
const auto constLst = lst;
for ( const QgsMimeDataUtils::Uri &u : constLst )
{
if ( u.layerType != QLatin1String( "vector" ) )
{
Expand Down Expand Up @@ -415,7 +418,8 @@ QVector<QgsDataItem *> QgsDb2RootItem::createChildren()
QVector<QgsDataItem *> connections;
QgsSettings settings;
settings.beginGroup( QStringLiteral( "/DB2/connections" ) );
Q_FOREACH ( const QString &connName, settings.childGroups() )
const auto constChildGroups = settings.childGroups();
for ( const QString &connName : constChildGroups )
{
connections << new QgsDb2ConnectionItem( this, connName, mPath + "/" + connName );
}
Expand Down Expand Up @@ -498,7 +502,8 @@ QVector<QgsDataItem *> QgsDb2SchemaItem::createChildren()

QVector<QgsDataItem *>items;

Q_FOREACH ( QgsDataItem *child, this->children() )
const auto constChildren = this->children();
for ( QgsDataItem *child : constChildren )
{
items.append( ( ( QgsDb2LayerItem * )child )->createClone() );
}
Expand All @@ -508,7 +513,8 @@ QVector<QgsDataItem *> QgsDb2SchemaItem::createChildren()
void QgsDb2SchemaItem::addLayers( QgsDataItem *newLayers )
{
// Add new items
Q_FOREACH ( QgsDataItem *child, newLayers->children() )
const auto constChildren = newLayers->children();
for ( QgsDataItem *child : constChildren )
{
// Is it present in children?
if ( findItem( mChildren, child ) >= 0 )
Expand Down
9 changes: 6 additions & 3 deletions src/providers/db2/qgsdb2featureiterator.cpp
Expand Up @@ -93,7 +93,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
attrs = attributeIndexes.toList();
}

Q_FOREACH ( int i, attrs )
const auto constAttrs = attrs;
for ( int i : constAttrs )
{
QString fieldname = mSource->mFields.at( i ).name();
if ( mSource->mFidColName == fieldname )
Expand Down Expand Up @@ -161,7 +162,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
{
QString delim;
QString inClause = QStringLiteral( "%1 IN (" ).arg( mSource->mFidColName );
Q_FOREACH ( QgsFeatureId featureId, mRequest.filterFids() )
const auto constFilterFids = mRequest.filterFids();
for ( QgsFeatureId featureId : constFilterFids )
{
inClause += delim + FID_TO_STRING( featureId );
delim = ',';
Expand Down Expand Up @@ -225,7 +227,8 @@ void QgsDb2FeatureIterator::BuildStatement( const QgsFeatureRequest &request )
QgsDebugMsg( QStringLiteral( "compileExpressions: %1" ).arg( QgsSettings().value( "qgis/compileExpressions", true ).toString() ) );
if ( QgsSettings().value( QStringLiteral( "qgis/compileExpressions" ), true ).toBool() && limitAtProvider )
{
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &clause, request.orderBy() )
const auto constOrderBy = request.orderBy();
for ( const QgsFeatureRequest::OrderByClause &clause : constOrderBy )
{
QgsDebugMsg( QStringLiteral( "processing a clause; ascending: %1; nullsFirst: %2" ).arg( clause.ascending() ).arg( clause.nullsFirst() ) );

Expand Down
3 changes: 2 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextfile.cpp
Expand Up @@ -402,7 +402,8 @@ void QgsDelimitedTextFile::setDiscardEmptyFields( bool discardEmptyFields )
void QgsDelimitedTextFile::setFieldNames( const QStringList &names )
{
mFieldNames.clear();
Q_FOREACH ( QString name, names )
const auto constNames = names;
for ( QString name : constNames )
{
bool nameOk = true;
int fieldNo = mFieldNames.size() + 1;
Expand Down
9 changes: 6 additions & 3 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -901,7 +901,8 @@ void QgsDelimitedTextProvider::clearInvalidLines() const

bool QgsDelimitedTextProvider::recordIsEmpty( QStringList &record )
{
Q_FOREACH ( const QString &s, record )
const auto constRecord = record;
for ( const QString &s : constRecord )
{
if ( ! s.isEmpty() )
return false;
Expand All @@ -927,7 +928,8 @@ void QgsDelimitedTextProvider::reportErrors( const QStringList &messages, bool s
{
QString tag( QStringLiteral( "DelimitedText" ) );
QgsMessageLog::logMessage( tr( "Errors in file %1" ).arg( mFile->fileName() ), tag );
Q_FOREACH ( const QString &message, messages )
const auto constMessages = messages;
for ( const QString &message : constMessages )
{
QgsMessageLog::logMessage( message, tag );
}
Expand All @@ -946,7 +948,8 @@ void QgsDelimitedTextProvider::reportErrors( const QStringList &messages, bool s
QgsMessageOutput *output = QgsMessageOutput::createMessageOutput();
output->setTitle( tr( "Delimited text file errors" ) );
output->setMessage( tr( "Errors in file %1" ).arg( mFile->fileName() ), QgsMessageOutput::MessageText );
Q_FOREACH ( const QString &message, messages )
const auto constMessages = messages;
for ( const QString &message : constMessages )
{
output->appendMessage( message );
}
Expand Down
3 changes: 2 additions & 1 deletion src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -276,7 +276,8 @@ QgsDataItem *QgsGdalDataItemProvider::createDataItem( const QString &pathIn, Qgs
if ( !sExtensions.contains( suffix ) )
{
bool matches = false;
Q_FOREACH ( const QString &wildcard, sWildcards )
const auto constSWildcards = sWildcards;
for ( const QString &wildcard : constSWildcards )
{
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( rx.exactMatch( info.fileName() ) )
Expand Down
18 changes: 12 additions & 6 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -1491,7 +1491,8 @@ QgsRasterHistogram QgsGdalProvider::histogram( int bandNo,
initHistogram( myHistogram, bandNo, binCount, minimum, maximum, boundingBox, sampleSize, includeOutOfRange );

// Find cached
Q_FOREACH ( const QgsRasterHistogram &histogram, mHistograms )
const auto constMHistograms = mHistograms;
for ( const QgsRasterHistogram &histogram : constMHistograms )
{
if ( histogram == myHistogram )
{
Expand Down Expand Up @@ -1709,7 +1710,8 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
// add any driver-specific configuration options, save values to be restored later
if ( format != QgsRaster::PyramidsErdas && ! configOptions.isEmpty() )
{
Q_FOREACH ( const QString &option, configOptions )
const auto constConfigOptions = configOptions;
for ( const QString &option : constConfigOptions )
{
QStringList opt = option.split( '=' );
if ( opt.size() == 2 )
Expand Down Expand Up @@ -1956,7 +1958,8 @@ QList<QgsRasterPyramid> QgsGdalProvider::buildPyramidList( QList<int> overviewLi
}

// loop over pyramid list
Q_FOREACH ( int myDivisor, overviewList )
const auto constOverviewList = overviewList;
for ( int myDivisor : constOverviewList )
{
//
// First we build up a list of potential pyramid layers
Expand Down Expand Up @@ -2439,7 +2442,8 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int bandNo, int stats, const
QgsRasterBandStats myRasterBandStats;
initStatistics( myRasterBandStats, bandNo, stats, boundingBox, sampleSize );

Q_FOREACH ( const QgsRasterBandStats &stats, mStatistics )
const auto constMStatistics = mStatistics;
for ( const QgsRasterBandStats &stats : constMStatistics )
{
if ( stats.contains( myRasterBandStats ) )
{
Expand Down Expand Up @@ -2891,7 +2895,8 @@ void QgsGdalProvider::initBaseDataset()
char **papszFromStringList( const QStringList &list )
{
char **papszRetList = nullptr;
Q_FOREACH ( const QString &elem, list )
const auto constList = list;
for ( const QString &elem : constList )
{
papszRetList = CSLAddString( papszRetList, elem.toLocal8Bit().constData() );
}
Expand Down Expand Up @@ -3102,7 +3107,8 @@ QString QgsGdalProvider::validateCreationOptions( const QStringList &createOptio

// prepare a map for easier lookup
QMap< QString, QString > optionsMap;
Q_FOREACH ( const QString &option, createOptions )
const auto constCreateOptions = createOptions;
for ( const QString &option : constCreateOptions )
{
QStringList opt = option.split( '=' );
optionsMap[ opt[0].toUpper()] = opt[1];
Expand Down
24 changes: 16 additions & 8 deletions src/providers/grass/qgis.v.in.cpp
Expand Up @@ -55,7 +55,8 @@ void writePoint( struct Map_info *map, int type, const QgsPointXY &point, struct
void writePolyline( struct Map_info *map, int type, const QgsPolylineXY &polyline, struct line_cats *cats )
{
Vect_reset_line( gLine );
Q_FOREACH ( const QgsPointXY &point, polyline )
const auto constPolyline = polyline;
for ( const QgsPointXY &point : constPolyline )
{
Vect_append_point( gLine, point.x(), point.y(), 0 );
}
Expand Down Expand Up @@ -259,7 +260,8 @@ int main( int argc, char **argv )
else if ( geometryType == QgsWkbTypes::MultiPoint )
{
QgsMultiPointXY multiPoint = geometry.asMultiPoint();
Q_FOREACH ( const QgsPointXY &point, multiPoint )
const auto constMultiPoint = multiPoint;
for ( const QgsPointXY &point : constMultiPoint )
{
writePoint( map, GV_POINT, point, cats );
}
Expand All @@ -272,25 +274,29 @@ int main( int argc, char **argv )
else if ( geometryType == QgsWkbTypes::MultiLineString )
{
QgsMultiPolylineXY multiPolyline = geometry.asMultiPolyline();
Q_FOREACH ( const QgsPolylineXY &polyline, multiPolyline )
const auto constMultiPolyline = multiPolyline;
for ( const QgsPolylineXY &polyline : constMultiPolyline )
{
writePolyline( map, GV_LINE, polyline, cats );
}
}
else if ( geometryType == QgsWkbTypes::Polygon )
{
QgsPolygonXY polygon = geometry.asPolygon();
Q_FOREACH ( const QgsPolylineXY &polyline, polygon )
const auto constPolygon = polygon;
for ( const QgsPolylineXY &polyline : constPolygon )
{
writePolyline( map, GV_BOUNDARY, polyline, cats );
}
}
else if ( geometryType == QgsWkbTypes::MultiPolygon )
{
QgsMultiPolygonXY multiPolygon = geometry.asMultiPolygon();
Q_FOREACH ( const QgsPolygonXY &polygon, multiPolygon )
const auto constMultiPolygon = multiPolygon;
for ( const QgsPolygonXY &polygon : constMultiPolygon )
{
Q_FOREACH ( const QgsPolylineXY &polyline, polygon )
const auto constPolygon = polygon;
for ( const QgsPolylineXY &polyline : constPolygon )
{
writePolyline( map, GV_BOUNDARY, polyline, cats );
}
Expand Down Expand Up @@ -423,7 +429,8 @@ int main( int argc, char **argv )
}

QList<QgsFeatureId> idList = spatialIndex.intersects( feature.geometry().boundingBox() );
Q_FOREACH ( QgsFeatureId id, idList )
const auto constIdList = idList;
for ( QgsFeatureId id : constIdList )
{
QgsFeature &centroid = centroids[id];
if ( feature.geometry().contains( centroid.geometry() ) )
Expand Down Expand Up @@ -451,7 +458,8 @@ int main( int argc, char **argv )
if ( it.value().attributes().size() > 0 )
{
Vect_reset_cats( cats );
Q_FOREACH ( const QVariant &attribute, it.value().attributes() )
const auto constAttributes = it.value().attributes();
for ( const QVariant &attribute : constAttributes )
{
Vect_cat_set( cats, 1, attribute.toInt() );
}
Expand Down
12 changes: 8 additions & 4 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -1293,7 +1293,8 @@ QStringList QgsGrass::vectorLayers( const QString &gisdbase, const QString &loca
QgsDebugMsg( "GRASS vector successfully opened" );

// Get layers
Q_FOREACH ( QgsGrassVectorLayer *layer, vector.layers() )
const auto constLayers = vector.layers();
for ( QgsGrassVectorLayer *layer : constLayers )
{
QString fs = QString::number( layer->number() );
QgsDebugMsg( "layer number = " + fs );
Expand Down Expand Up @@ -1898,9 +1899,11 @@ QString QgsGrass::findModule( QString module )
paths << QgsGrass::grassModulesPaths();

// Extensions first to prefer .bat over .exe on Windows
Q_FOREACH ( const QString &ext, extensions )
const auto constExtensions = extensions;
for ( const QString &ext : constExtensions )
{
Q_FOREACH ( const QString &path, paths )
const auto constPaths = paths;
for ( const QString &path : constPaths )
{
QString full = module + ext;;
if ( !path.isEmpty() )
Expand Down Expand Up @@ -2426,7 +2429,8 @@ void QgsGrass::insertRow( dbDriver *driver, const QString &tableName,
}

QStringList valuesStringList;
Q_FOREACH ( const QVariant &attribute, attributes )
const auto constAttributes = attributes;
for ( const QVariant &attribute : constAttributes )
{
QString valueString;

Expand Down
3 changes: 2 additions & 1 deletion src/providers/grass/qgsgrassfeatureiterator.cpp
Expand Up @@ -246,7 +246,8 @@ bool QgsGrassFeatureIterator::fetchFeature( QgsFeature &feature )
if ( mSource->mEditing )
{
QgsDebugMsgLevel( "newLids:", 3 );
Q_FOREACH ( int oldLid, mSource->mLayer->map()->newLids().keys() )
const auto constKeys = mSource->mLayer->map()->newLids().keys();
for ( int oldLid : constKeys )
{
QgsDebugMsgLevel( QString( "%1 -> %2" ).arg( oldLid ).arg( mSource->mLayer->map()->newLids().value( oldLid ) ), 3 );
}
Expand Down
15 changes: 10 additions & 5 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -1197,7 +1197,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
#ifdef QGISDEBUG
QgsDebugMsg( "the feature is missing in buffer addedFeatures :" );

Q_FOREACH ( QgsFeatureId id, mEditBuffer->addedFeatures().keys() )
const auto constKeys = mEditBuffer->addedFeatures().keys();
for ( QgsFeatureId id : constKeys )
{
QgsDebugMsg( QString( "addedFeatures : id = %1" ).arg( id ) );
}
Expand Down Expand Up @@ -1272,7 +1273,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
// Currently neither entering new cat nor changing existing cat is allowed
#if 0
// There may be other new features with the same cat which we have to update
Q_FOREACH ( QgsFeatureId addedFid, addedFeatures.keys() )
const auto constKeys = addedFeatures.keys();
for ( QgsFeatureId addedFid : constKeys )
{
if ( addedFid == fid )
{
Expand Down Expand Up @@ -1302,7 +1304,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )

// Update all changed attributes
QgsChangedAttributesMap &changedAttributes = const_cast<QgsChangedAttributesMap &>( mEditBuffer->changedAttributeValues() );
Q_FOREACH ( QgsFeatureId changedFid, changedAttributes.keys() )
const auto constKeys = changedAttributes.keys();
for ( QgsFeatureId changedFid : constKeys )
{
int changedCat = QgsGrassFeatureIterator::catFromFid( changedFid );
int realChangedCat = changedCat;
Expand All @@ -1315,7 +1318,8 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
if ( realChangedCat == newCat )
{
QgsAttributeMap attributeMap = changedAttributes[changedFid];
Q_FOREACH ( int index, attributeMap.keys() )
const auto constKeys = attributeMap.keys();
for ( int index : constKeys )
{
attributeMap[index] = feature.attributes().value( index );
}
Expand Down Expand Up @@ -2047,7 +2051,8 @@ void QgsGrassProvider::setMapset()

QgsGrassVectorMapLayer *QgsGrassProvider::otherEditLayer( int layerField )
{
Q_FOREACH ( QgsGrassVectorMapLayer *layer, mOtherEditLayers )
const auto constMOtherEditLayers = mOtherEditLayers;
for ( QgsGrassVectorMapLayer *layer : constMOtherEditLayers )
{
if ( layer->field() == layerField )
{
Expand Down

0 comments on commit a6665d4

Please sign in to comment.