Skip to content
Permalink
Browse files

Kill them Q_FOREACH

  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent a063363 commit a6665d42f6b4939e39302ec9aa01d90918a3a378
Showing with 488 additions and 256 deletions.
  1. +12 −6 src/providers/db2/qgsdb2dataitems.cpp
  2. +6 −3 src/providers/db2/qgsdb2featureiterator.cpp
  3. +2 −1 src/providers/delimitedtext/qgsdelimitedtextfile.cpp
  4. +6 −3 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  5. +2 −1 src/providers/gdal/qgsgdaldataitems.cpp
  6. +12 −6 src/providers/gdal/qgsgdalprovider.cpp
  7. +16 −8 src/providers/grass/qgis.v.in.cpp
  8. +8 −4 src/providers/grass/qgsgrass.cpp
  9. +2 −1 src/providers/grass/qgsgrassfeatureiterator.cpp
  10. +10 −5 src/providers/grass/qgsgrassprovider.cpp
  11. +22 −11 src/providers/grass/qgsgrassprovidermodule.cpp
  12. +4 −2 src/providers/grass/qgsgrassrasterprovider.cpp
  13. +4 −2 src/providers/grass/qgsgrassvector.cpp
  14. +10 −5 src/providers/grass/qgsgrassvectormap.cpp
  15. +14 −7 src/providers/grass/qgsgrassvectormaplayer.cpp
  16. +24 −12 src/providers/mssql/qgsmssqldataitems.cpp
  17. +4 −2 src/providers/mssql/qgsmssqlfeatureiterator.cpp
  18. +2 −1 src/providers/mssql/qgsmssqlprovider.cpp
  19. +4 −2 src/providers/mssql/qgsmssqltablemodel.cpp
  20. +4 −2 src/providers/ogr/qgsogrdataitems.cpp
  21. +14 −7 src/providers/ogr/qgsogrprovider.cpp
  22. +4 −2 src/providers/oracle/qgsoracleconn.h
  23. +8 −4 src/providers/oracle/qgsoracledataitems.cpp
  24. +6 −3 src/providers/oracle/qgsoraclefeatureiterator.cpp
  25. +18 −9 src/providers/oracle/qgsoracleprovider.cpp
  26. +4 −2 src/providers/oracle/qgsoraclesourceselect.cpp
  27. +6 −3 src/providers/oracle/qgsoracletablecache.cpp
  28. +2 −1 src/providers/oracle/qgsoracletablemodel.cpp
  29. +6 −3 src/providers/ows/qgsowsdataitems.cpp
  30. +6 −3 src/providers/postgres/qgspgsourceselect.cpp
  31. +4 −2 src/providers/postgres/qgspgtablemodel.cpp
  32. +4 −2 src/providers/postgres/qgspostgresconn.cpp
  33. +4 −2 src/providers/postgres/qgspostgresconn.h
  34. +8 −4 src/providers/postgres/qgspostgresdataitems.cpp
  35. +6 −3 src/providers/postgres/qgspostgresfeatureiterator.cpp
  36. +25 −14 src/providers/postgres/qgspostgresprovider.cpp
  37. +4 −2 src/providers/spatialite/qgsspatialitedataitems.cpp
  38. +4 −2 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  39. +2 −1 src/providers/spatialite/qgsspatialitesourceselect.cpp
  40. +2 −1 src/providers/virtual/qgsembeddedlayerselectdialog.cpp
  41. +8 −4 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
  42. +10 −5 src/providers/virtual/qgsvirtuallayerprovider.cpp
  43. +10 −5 src/providers/virtual/qgsvirtuallayersourceselect.cpp
  44. +2 −1 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  45. +16 −8 src/providers/wcs/qgswcscapabilities.cpp
  46. +2 −1 src/providers/wcs/qgswcsdataitems.cpp
  47. +2 −1 src/providers/wcs/qgswcsprovider.cpp
  48. +4 −2 src/providers/wfs/qgswfsdatasourceuri.cpp
  49. +4 −2 src/providers/wfs/qgswfsfeatureiterator.cpp
  50. +18 −10 src/providers/wfs/qgswfsprovider.cpp
  51. +2 −1 src/providers/wfs/qgswfsrequest.cpp
  52. +8 −4 src/providers/wfs/qgswfsshareddata.cpp
  53. +4 −2 src/providers/wfs/qgswfssourceselect.cpp
  54. +4 −2 src/providers/wfs/qgswfsutils.cpp
  55. +2 −1 src/providers/wms/qgstilescalewidget.cpp
  56. +10 −6 src/providers/wms/qgswmscapabilities.cpp
  57. +14 −10 src/providers/wms/qgswmsdataitems.cpp
  58. +48 −27 src/providers/wms/qgswmsprovider.cpp
  59. +15 −10 src/providers/wms/qgswmssourceselect.cpp
@@ -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 );
@@ -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 )
{
@@ -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" ) )
{
@@ -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 );
}
@@ -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() );
}
@@ -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 )
@@ -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 )
@@ -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 = ',';
@@ -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() ) );

@@ -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;
@@ -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;
@@ -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 );
}
@@ -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 );
}
@@ -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() ) )
@@ -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 )
{
@@ -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 )
@@ -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
@@ -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 ) )
{
@@ -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() );
}
@@ -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];
@@ -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 );
}
@@ -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 );
}
@@ -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 );
}
@@ -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() ) )
@@ -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() );
}
@@ -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 );
@@ -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() )
@@ -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;

@@ -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 );
}
@@ -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 ) );
}
@@ -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 )
{
@@ -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;
@@ -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 );
}
@@ -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 )
{

0 comments on commit a6665d4

Please sign in to comment.
You can’t perform that action at this time.