More core changes

This commit is contained in:
Matthias Kuhn 2019-04-05 14:23:16 +02:00
parent a6665d42f6
commit 8cdfaa395f
No known key found for this signature in database
GPG Key ID: 7A7F1A1C90C3E6A7
43 changed files with 137 additions and 77 deletions

View File

@ -1406,6 +1406,8 @@ IF (Qt5Positioning_FOUND)
)
ENDIF (Qt5Positioning_FOUND)
TARGET_COMPILE_DEFINITIONS(qgis_core PRIVATE "-DQT_NO_FOREACH")
# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(

View File

@ -745,7 +745,8 @@ void QgsLayerTreeModel::nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom
endInsertRows();
Q_FOREACH ( QgsLayerTreeLayer *newLayerNode, _layerNodesInSubtree( node, indexFrom, indexTo ) )
const auto subNodes = _layerNodesInSubtree( node, indexFrom, indexTo );
for ( QgsLayerTreeLayer *newLayerNode : subNodes )
connectToLayer( newLayerNode );
}
@ -756,7 +757,8 @@ void QgsLayerTreeModel::nodeWillRemoveChildren( QgsLayerTreeNode *node, int inde
beginRemoveRows( node2index( node ), indexFrom, indexTo );
// disconnect from layers and remove their legend
Q_FOREACH ( QgsLayerTreeLayer *nodeLayer, _layerNodesInSubtree( node, indexFrom, indexTo ) )
const auto subNodes = _layerNodesInSubtree( node, indexFrom, indexTo );
for ( QgsLayerTreeLayer *nodeLayer : subNodes )
disconnectFromLayer( nodeLayer );
}
@ -1522,7 +1524,8 @@ QgsLayerTreeModelLegendNode *QgsLayerTreeModel::findLegendNode( const QString &l
QgsLayerTreeLayer *layer = it.key();
if ( layer->layerId() == layerId )
{
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, mLegend.value( layer ).activeNodes )
const auto activeNodes = mLegend.value( layer ).activeNodes;
for ( QgsLayerTreeModelLegendNode *legendNode : activeNodes )
{
if ( legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() == ruleKey )
{
@ -1561,7 +1564,7 @@ void QgsLayerTreeModel::invalidateLegendMapBasedData()
{
QList<QgsSymbolLegendNode *> symbolNodes;
QMap<QString, int> widthMax;
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, data.originalNodes )
for ( QgsLayerTreeModelLegendNode *legendNode : qgis::as_const( data.originalNodes ) )
{
QgsSymbolLegendNode *n = qobject_cast<QgsSymbolLegendNode *>( legendNode );
if ( n )
@ -1581,7 +1584,7 @@ void QgsLayerTreeModel::invalidateLegendMapBasedData()
const int twiceMarginWidth = 2; // a one pixel margin avoids hugly rendering of icon
n->setIconSize( QSize( widthMax[parentKey] + twiceMarginWidth, n->iconSize().rheight() + twiceMarginWidth ) );
}
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, data.originalNodes )
for ( QgsLayerTreeModelLegendNode *legendNode : qgis::as_const( data.originalNodes ) )
legendNode->invalidateMapBasedData();
}

View File

@ -37,7 +37,8 @@ QgsLayerTreeNode::QgsLayerTreeNode( const QgsLayerTreeNode &other )
, mProperties( other.mProperties )
{
QList<QgsLayerTreeNode *> clonedChildren;
Q_FOREACH ( QgsLayerTreeNode *child, other.mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( other.mChildren ) )
clonedChildren << child->clone();
insertChildrenPrivate( -1, clonedChildren );
}

View File

@ -518,7 +518,8 @@ void QgsLayoutGuideCollection::setVisible( bool visible )
void QgsLayoutGuideCollection::pageAboutToBeRemoved( int pageNumber )
{
mBlockUndoCommands = true;
Q_FOREACH ( QgsLayoutGuide *guide, guidesOnPage( pageNumber ) )
const auto constGuidesOnPage = guidesOnPage( pageNumber );
for ( QgsLayoutGuide *guide : constGuidesOnPage )
{
removeGuide( guide );
}

View File

@ -282,7 +282,8 @@ double QgsLayoutSnapper::snapPointsToGuides( const QList<double> &points, Qt::Or
for ( double p : points )
{
Q_FOREACH ( QgsLayoutGuide *guide, mLayout->guides().guides( orientation ) )
const auto constGuides = mLayout->guides().guides( orientation );
for ( QgsLayoutGuide *guide : constGuides )
{
double guidePos = guide->layoutPosition();
double diff = std::fabs( p - guidePos );

View File

@ -67,7 +67,7 @@ FeaturePart::FeaturePart( const FeaturePart &other )
: PointSet( other )
, mLF( other.mLF )
{
Q_FOREACH ( const FeaturePart *hole, other.mHoles )
for ( const FeaturePart *hole : qgis::as_const( other.mHoles ) )
{
mHoles << new FeaturePart( *hole );
mHoles.last()->holeOf = this;

View File

@ -333,7 +333,8 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
if ( isCanceled() )
{
Q_FOREACH ( Feats *feat, *fFeats )
const auto constFFeats = *fFeats;
for ( Feats *feat : constFFeats )
{
qDeleteAll( feat->lPos );
feat->lPos.clear();
@ -397,7 +398,8 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
if ( isCanceled() )
{
Q_FOREACH ( Feats *feat, *fFeats )
const auto constFFeats = *fFeats;
for ( Feats *feat : constFFeats )
{
qDeleteAll( feat->lPos );
feat->lPos.clear();

View File

@ -268,7 +268,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
continue;
bool canExecute = true;
Q_FOREACH ( const QString &dependency, dependsOnChildAlgorithms( childId ) )
const auto constDependsOnChildAlgorithms = dependsOnChildAlgorithms( childId );
for ( const QString &dependency : constDependsOnChildAlgorithms )
{
if ( !executed.contains( dependency ) )
{
@ -510,7 +511,8 @@ QStringList QgsProcessingModelAlgorithm::asPythonCode( const QgsProcessing::Pyth
continue;
bool canExecute = true;
Q_FOREACH ( const QString &dependency, dependsOnChildAlgorithms( childId ) )
const auto constDependsOnChildAlgorithms = dependsOnChildAlgorithms( childId );
for ( const QString &dependency : constDependsOnChildAlgorithms )
{
if ( !executed.contains( dependency ) )
{
@ -1239,7 +1241,8 @@ bool QgsProcessingModelAlgorithm::removeChildAlgorithm( const QString &id )
void QgsProcessingModelAlgorithm::deactivateChildAlgorithm( const QString &id )
{
Q_FOREACH ( const QString &child, dependentChildAlgorithms( id ) )
const auto constDependentChildAlgorithms = dependentChildAlgorithms( id );
for ( const QString &child : constDependentChildAlgorithms )
{
childAlgorithm( child ).setActive( false );
}
@ -1249,7 +1252,8 @@ void QgsProcessingModelAlgorithm::deactivateChildAlgorithm( const QString &id )
bool QgsProcessingModelAlgorithm::activateChildAlgorithm( const QString &id )
{
Q_FOREACH ( const QString &child, dependsOnChildAlgorithms( id ) )
const auto constDependsOnChildAlgorithms = dependsOnChildAlgorithms( id );
for ( const QString &child : constDependsOnChildAlgorithms )
{
if ( !childAlgorithm( child ).isActive() )
return false;

View File

@ -293,7 +293,8 @@ QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParamet
}
else if ( val.type() == QVariant::String )
{
Q_FOREACH ( const QString &var, val.toString().split( ',' ) )
const auto constSplit = val.toString().split( ',' );
for ( const QString &var : constSplit )
resultList << var;
}
else
@ -314,7 +315,8 @@ QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParamet
}
else if ( definition->defaultValue().type() == QVariant::String )
{
Q_FOREACH ( const QString &var, definition->defaultValue().toString().split( ',' ) )
const auto constSplit = definition->defaultValue().toString().split( ',' );
for ( const QString &var : constSplit )
resultList << var;
}
else
@ -1283,7 +1285,8 @@ QVariantList QgsProcessingParameters::parameterAsMatrix( const QgsProcessingPara
}
QVariantList result;
Q_FOREACH ( const QString &s, resultString.split( ',' ) )
const auto constSplit = resultString.split( ',' );
for ( const QString &s : constSplit )
result << s;
return result;

View File

@ -659,7 +659,8 @@ QString QgsApplication::resolvePkgPath()
// check if QGIS is run from build directory (not the install directory)
QFile f;
// "/../../.." is for Mac bundled app in build directory
Q_FOREACH ( const QString &path, QStringList() << "" << "/.." << "/bin" << "/../../.." )
static const QStringList paths { QStringList() << QString() << QStringLiteral( "/.." ) << QStringLiteral( "/bin" ) << QStringLiteral( "/../../.." ) };
for ( const QString &path : paths )
{
f.setFileName( prefix + path + "/qgisbuildpath.txt" );
if ( f.exists() )
@ -951,7 +952,7 @@ QStringList QgsApplication::svgPaths()
if ( !paths.contains( path ) )
paths.append( path );
}
Q_FOREACH ( const QString &path, ABISYM( mDefaultSvgPaths ) )
for ( const QString &path : qgis::as_const( ABISYM( mDefaultSvgPaths ) ) )
{
if ( !paths.contains( path ) )
paths.append( path );
@ -1512,14 +1513,16 @@ void QgsApplication::copyPath( const QString &src, const QString &dst )
if ( ! dir.exists() )
return;
Q_FOREACH ( const QString &d, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
const auto subDirectories = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
for ( const QString &d : subDirectories )
{
QString dst_path = dst + QDir::separator() + d;
dir.mkpath( dst_path );
copyPath( src + QDir::separator() + d, dst_path );
}
Q_FOREACH ( const QString &f, dir.entryList( QDir::Files ) )
const auto files = dir.entryList( QDir::Files );
for ( const QString &f : files )
{
QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
}

View File

@ -102,7 +102,8 @@ void QgsBrowserModel::addRootItems()
}
// add drives
Q_FOREACH ( const QFileInfo &drive, QDir::drives() )
const auto drives { QDir::drives() };
for ( const QFileInfo &drive : drives )
{
const QString path = drive.absolutePath();

View File

@ -64,7 +64,8 @@ QgsColorRamp *QgsGradientColorRamp::create( const QgsStringMap &props )
QgsGradientStopsList stops;
if ( props.contains( QStringLiteral( "stops" ) ) )
{
Q_FOREACH ( const QString &stop, props["stops"].split( ':' ) )
const auto constSplit = props["stops"].split( ':' );
for ( const QString &stop : constSplit )
{
int i = stop.indexOf( ';' );
if ( i == -1 )

View File

@ -789,7 +789,8 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
// also with parameters containing spaces (e.g. +nadgrids)
// make sure result is trimmed (#5598)
QStringList myParams;
Q_FOREACH ( const QString &param, myProj4String.split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts ) )
const auto constSplit = myProj4String.split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts );
for ( const QString &param : constSplit )
{
QString arg = QStringLiteral( "' '||parameters||' ' LIKE %1" ).arg( QgsSqliteUtils::quotedString( QStringLiteral( "% %1 %" ).arg( param.trimmed() ) ) );
if ( param.startsWith( QLatin1String( "+datum=" ) ) )
@ -819,7 +820,8 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
{
// Bugfix 8487 : test param lists are equal, except for +datum
QStringList foundParams;
Q_FOREACH ( const QString &param, myRecord["parameters"].split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts ) )
const auto constSplit = myRecord["parameters"].split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts );
for ( const QString &param : constSplit )
{
if ( !param.startsWith( QLatin1String( "+datum=" ) ) )
foundParams << param.trimmed();
@ -1772,7 +1774,8 @@ bool QgsCoordinateReferenceSystem::loadIds( QHash<int, QString> &wkts )
{
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );
Q_FOREACH ( const QString &csv, QStringList() << "gcs.csv" << "pcs.csv" << "vertcs.csv" << "compdcs.csv" << "geoccs.csv" )
static const QStringList csvs { QStringList() << QStringLiteral( "gcs.csv" ) << QStringLiteral( "pcs.csv" ) << QStringLiteral( "vertcs.csv" ) << QStringLiteral( "compdcs.csv" ) << QStringLiteral( "geoccs.csv" ) };
for ( const QString &csv : csvs )
{
QString filename = CPLFindFile( "gdal", csv.toUtf8() );

View File

@ -87,7 +87,8 @@ void QgsDataDefinedSizeLegend::updateFromSymbolAndProperty( const QgsMarkerSymbo
if ( sizeTransformer && mSizeClasses.isEmpty() )
{
mSizeClasses.clear();
Q_FOREACH ( double v, QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) )
const auto prettyBreaks { QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) };
for ( double v : prettyBreaks )
{
mSizeClasses << SizeClass( v, QString::number( v ) );
}

View File

@ -780,7 +780,8 @@ QList< QgsLayerTreeModelLegendNode * > QgsLinearlyInterpolatedDiagramRenderer::l
if ( ddSizeLegend.classes().isEmpty() )
{
// automatic class creation if the classes are not defined manually
Q_FOREACH ( double v, QgsSymbolLayerUtils::prettyBreaks( mInterpolationSettings.lowerValue, mInterpolationSettings.upperValue, 4 ) )
const auto prettyBreaks { QgsSymbolLayerUtils::prettyBreaks( mInterpolationSettings.lowerValue, mInterpolationSettings.upperValue, 4 ) };
for ( double v : prettyBreaks )
{
double size = mDiagram->legendSize( v, mSettings, mInterpolationSettings );
sizeClasses << QgsDataDefinedSizeLegend::SizeClass( size, QString::number( v ) );

View File

@ -239,7 +239,7 @@ QgsExpressionContext::QgsExpressionContext( const QList<QgsExpressionContextScop
QgsExpressionContext::QgsExpressionContext( const QgsExpressionContext &other )
{
Q_FOREACH ( const QgsExpressionContextScope *scope, other.mStack )
for ( const QgsExpressionContextScope *scope : qgis::as_const( other.mStack ) )
{
mStack << new QgsExpressionContextScope( *scope );
}
@ -268,7 +268,7 @@ QgsExpressionContext &QgsExpressionContext::operator=( const QgsExpressionContex
{
qDeleteAll( mStack );
mStack.clear();
Q_FOREACH ( const QgsExpressionContextScope *scope, other.mStack )
for ( const QgsExpressionContextScope *scope : qgis::as_const( other.mStack ) )
{
mStack << new QgsExpressionContextScope( *scope );
}

View File

@ -382,7 +382,8 @@ QSet<QString> QgsFeatureFilterModel::requestedAttributes() const
if ( mDisplayExpression.isField() )
{
QString fieldName = *mDisplayExpression.referencedColumns().constBegin();
Q_FOREACH ( const QgsConditionalStyle &style, mSourceLayer->conditionalStyles()->fieldStyles( fieldName ) )
const auto constFieldStyles = mSourceLayer->conditionalStyles()->fieldStyles( fieldName );
for ( const QgsConditionalStyle &style : constFieldStyles )
{
QgsExpression exp( style.rule() );
requestedAttrs += exp.referencedColumns();

View File

@ -165,7 +165,8 @@ bool QgsFontUtils::updateFontViaStyle( QFont &f, const QString &fontstyle, bool
testFont.setPointSize( defaultSize );
// prefer a style that mostly matches the passed-in font
Q_FOREACH ( const QString &style, fontDB.styles( f.family() ) )
const auto constFamily = fontDB.styles( f.family() );
for ( const QString &style : constFamily )
{
styledfont = fontDB.font( f.family(), style, defaultSize );
styledfont = styledfont.resolve( f );
@ -179,7 +180,8 @@ bool QgsFontUtils::updateFontViaStyle( QFont &f, const QString &fontstyle, bool
// fallback to first style found that works
if ( !foundmatch )
{
Q_FOREACH ( const QString &style, fontDB.styles( f.family() ) )
const auto constFamily = fontDB.styles( f.family() );
for ( const QString &style : constFamily )
{
styledfont = fontDB.font( f.family(), style, defaultSize );
if ( QApplication::font() != styledfont )

View File

@ -385,7 +385,8 @@ void QgsLayerDefinition::DependencySorter::init( const QDomDocument &doc )
QDomNode node = it->second;
mHasCycle = true;
bool resolved = true;
Q_FOREACH ( const QString &dep, dependencies[idToSort] )
const auto deps { dependencies.value( idToSort ) };
for ( const QString &dep : deps )
{
if ( !sortedLayers.contains( dep ) )
{

View File

@ -555,7 +555,7 @@ QSizeF QgsLegendRenderer::drawAtomInternal( const Atom &atom, QgsRenderContext *
{
bool first = true;
QSizeF size = QSizeF( atom.size );
Q_FOREACH ( const Nucleon &nucleon, atom.nucleons )
for ( const Nucleon &nucleon : qgis::as_const( atom.nucleons ) )
{
if ( QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( nucleon.item ) )
{

View File

@ -173,14 +173,16 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
//make sure we store string representation of symbol, not pointer
//otherwise layer style override changes will delete original symbols and leave hanging pointers
Q_FOREACH ( const QString &legendKey, r->legendKeysForFeature( f, context ) )
const auto constLegendKeysForFeature = r->legendKeysForFeature( f, context );
for ( const QString &legendKey : constLegendKeysForFeature )
{
lUsedSymbolsRuleKey.insert( legendKey );
}
if ( moreSymbolsPerFeature )
{
Q_FOREACH ( QgsSymbol *s, r->originalSymbolsForFeature( f, context ) )
const auto constOriginalSymbolsForFeature = r->originalSymbolsForFeature( f, context );
for ( QgsSymbol *s : constOriginalSymbolsForFeature )
{
if ( s )
lUsedSymbols.insert( QgsSymbolLayerUtils::symbolProperties( s ) );

View File

@ -1848,7 +1848,8 @@ static bool _depHasCycleDFS( const QgsMapLayer *n, QHash<const QgsMapLayer *, in
if ( mark.value( n ) == 0 ) // not visited
{
mark[n] = 1; // temporary
Q_FOREACH ( const QgsMapLayer *m, _depOutEdges( n, that, layers ) )
const auto depOutEdges { _depOutEdges( n, that, layers ) };
for ( const QgsMapLayer *m : depOutEdges )
{
if ( _depHasCycleDFS( m, mark, that, layers ) )
return true;

View File

@ -112,7 +112,8 @@ QList<int> QgsMapLayerLegendUtils::legendNodeOrder( QgsLayerTreeLayer *nodeLayer
int numNodes = _originalLegendNodeCount( nodeLayer );
QList<int> lst;
Q_FOREACH ( const QString &item, orderStr.split( ',' ) )
const auto constSplit = orderStr.split( ',' );
for ( const QString &item : constSplit )
{
bool ok;
int id = item.toInt( &ok );
@ -239,7 +240,8 @@ QList<QgsLayerTreeModelLegendNode *> QgsDefaultVectorLayerLegend::createLayerTre
if ( mLayer->diagramsEnabled() )
{
Q_FOREACH ( QgsLayerTreeModelLegendNode *i, mLayer->diagramRenderer()->legendItems( nodeLayer ) )
const auto constLegendItems = mLayer->diagramRenderer()->legendItems( nodeLayer );
for ( QgsLayerTreeModelLegendNode *i : constLegendItems )
{
nodes.append( i );
}

View File

@ -71,7 +71,8 @@ QSet<QgsWeakMapLayerPointer > QgsMapRendererCache::dependentLayers() const
QMap<QString, CacheParameters>::const_iterator it = mCachedImages.constBegin();
for ( ; it != mCachedImages.constEnd(); ++it )
{
Q_FOREACH ( const QgsWeakMapLayerPointer &l, it.value().dependentLayers )
const auto dependentLayers { it.value().dependentLayers };
for ( const QgsWeakMapLayerPointer &l : dependentLayers )
{
if ( l.data() )
result << l;

View File

@ -44,7 +44,8 @@ QgsMapThemeCollection::MapThemeLayerRecord QgsMapThemeCollection::createThemeLay
bool hasCheckableItems = false;
bool someItemsUnchecked = false;
QSet<QString> checkedItems;
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, model->layerLegendNodes( nodeLayer, true ) )
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
{
if ( legendNode->flags() & Qt::ItemIsUserCheckable )
{
@ -106,7 +107,7 @@ QgsMapThemeCollection::MapThemeRecord QgsMapThemeCollection::createThemeFromCurr
bool QgsMapThemeCollection::findRecordForLayer( QgsMapLayer *layer, const QgsMapThemeCollection::MapThemeRecord &rec, QgsMapThemeCollection::MapThemeLayerRecord &layerRec )
{
Q_FOREACH ( const QgsMapThemeCollection::MapThemeLayerRecord &lr, rec.mLayerRecords )
for ( const QgsMapThemeCollection::MapThemeLayerRecord &lr : qgis::as_const( rec.mLayerRecords ) )
{
if ( lr.layer() == layer )
{
@ -140,7 +141,8 @@ void QgsMapThemeCollection::applyThemeToLayer( QgsLayerTreeLayer *nodeLayer, Qgs
if ( layerRec.usingLegendItems )
{
// some nodes are not checked
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, model->layerLegendNodes( nodeLayer, true ) )
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
{
QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
Qt::CheckState shouldHaveState = layerRec.checkedLegendItems.contains( ruleKey ) ? Qt::Checked : Qt::Unchecked;
@ -152,7 +154,8 @@ void QgsMapThemeCollection::applyThemeToLayer( QgsLayerTreeLayer *nodeLayer, Qgs
else
{
// all nodes should be checked
Q_FOREACH ( QgsLayerTreeModelLegendNode *legendNode, model->layerLegendNodes( nodeLayer, true ) )
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
{
if ( ( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
legendNode->data( Qt::CheckStateRole ).toInt() != Qt::Checked )
@ -295,7 +298,8 @@ QStringList QgsMapThemeCollection::mapThemes() const
QStringList QgsMapThemeCollection::mapThemeVisibleLayerIds( const QString &name ) const
{
QStringList layerIds;
Q_FOREACH ( QgsMapLayer *layer, mapThemeVisibleLayers( name ) )
const auto constMapThemeVisibleLayers = mapThemeVisibleLayers( name );
for ( QgsMapLayer *layer : constMapThemeVisibleLayers )
{
layerIds << layer->id();
}
@ -310,7 +314,8 @@ QList<QgsMapLayer *> QgsMapThemeCollection::mapThemeVisibleLayers( const QString
if ( layerOrder.isEmpty() )
{
// no master layer order - so we have to just use the stored theme layer order as a fallback
Q_FOREACH ( const MapThemeLayerRecord &layerRec, mMapThemes.value( name ).mLayerRecords )
const auto records {mMapThemes.value( name ).mLayerRecords};
for ( const MapThemeLayerRecord &layerRec : records )
{
if ( layerRec.layer() )
layers << layerRec.layer();
@ -363,7 +368,8 @@ QMap<QString, QString> QgsMapThemeCollection::mapThemeStyleOverrides( const QStr
if ( !mMapThemes.contains( presetName ) )
return styleOverrides;
Q_FOREACH ( const MapThemeLayerRecord &layerRec, mMapThemes.value( presetName ).mLayerRecords )
const auto records {mMapThemes.value( presetName ).mLayerRecords};
for ( const MapThemeLayerRecord &layerRec : records )
{
if ( !layerRec.layer() )
continue;
@ -394,7 +400,7 @@ void QgsMapThemeCollection::reconnectToLayersStyleManager()
const auto constMMapThemes = mMapThemes;
for ( const MapThemeRecord &rec : constMMapThemes )
{
Q_FOREACH ( const MapThemeLayerRecord &layerRec, rec.mLayerRecords )
for ( const MapThemeLayerRecord &layerRec : qgis::as_const( rec.mLayerRecords ) )
{
if ( layerRec.layer() )
layers << layerRec.layer();
@ -530,7 +536,7 @@ void QgsMapThemeCollection::writeXml( QDomDocument &doc )
visPresetElem.setAttribute( QStringLiteral( "name" ), grpName );
if ( rec.hasExpandedStateInfo() )
visPresetElem.setAttribute( QStringLiteral( "has-expanded-info" ), QStringLiteral( "1" ) );
Q_FOREACH ( const MapThemeLayerRecord &layerRec, rec.mLayerRecords )
for ( const MapThemeLayerRecord &layerRec : qgis::as_const( rec.mLayerRecords ) )
{
if ( !layerRec.layer() )
continue;
@ -545,7 +551,7 @@ void QgsMapThemeCollection::writeXml( QDomDocument &doc )
{
QDomElement checkedLegendNodesElem = doc.createElement( QStringLiteral( "checked-legend-nodes" ) );
checkedLegendNodesElem.setAttribute( QStringLiteral( "id" ), layerID );
Q_FOREACH ( const QString &checkedLegendNode, layerRec.checkedLegendItems )
for ( const QString &checkedLegendNode : qgis::as_const( layerRec.checkedLegendItems ) )
{
QDomElement checkedLegendNodeElem = doc.createElement( QStringLiteral( "checked-legend-node" ) );
checkedLegendNodeElem.setAttribute( QStringLiteral( "id" ), checkedLegendNode );

View File

@ -548,7 +548,8 @@ class QgsPointLocator_VisitorEdgesInRect : public IVisitor
QgsFeatureId id = d.getIdentifier();
QgsGeometry *geom = mLocator->mGeoms.value( id );
Q_FOREACH ( const QgsPointLocator::Match &m, _geometrySegmentsInRect( geom, mSrcRect, mLocator->mLayer, id ) )
const auto segmentsInRect {_geometrySegmentsInRect( geom, mSrcRect, mLocator->mLayer, id )};
for ( const QgsPointLocator::Match &m : segmentsInRect )
{
// in range queries the filter may reject some matches
if ( mFilter && !mFilter->acceptMatch( m ) )

View File

@ -366,7 +366,7 @@ QgsPropertyCollectionStack::QgsPropertyCollectionStack( const QgsPropertyCollect
{
clear();
Q_FOREACH ( QgsPropertyCollection *collection, other.mStack )
for ( QgsPropertyCollection *collection : qgis::as_const( other.mStack ) )
{
mStack << new QgsPropertyCollection( *collection );
}
@ -377,7 +377,7 @@ QgsPropertyCollectionStack &QgsPropertyCollectionStack::operator=( const QgsProp
setName( other.name() );
clear();
Q_FOREACH ( QgsPropertyCollection *collection, other.mStack )
for ( QgsPropertyCollection *collection : qgis::as_const( other.mStack ) )
{
mStack << new QgsPropertyCollection( *collection );
}

View File

@ -255,7 +255,8 @@ QList<QgsRelation> QgsRelationManager::discoverRelations( const QList<QgsRelatio
const auto constLayers = layers;
for ( const QgsVectorLayer *layer : constLayers )
{
Q_FOREACH ( const QgsRelation &relation, layer->dataProvider()->discoverRelations( layer, layers ) )
const auto constDiscoverRelations = layer->dataProvider()->discoverRelations( layer, layers );
for ( const QgsRelation &relation : constDiscoverRelations )
{
if ( !hasRelationWithEqualDefinition( existingRelations, relation ) )
{

View File

@ -15,6 +15,7 @@
***************************************************************************/
#include "qgssqlstatement.h"
#include "qgis.h"
#include <cmath>
#include <limits>
@ -239,7 +240,7 @@ bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
QgsSQLStatementCollectTableNames v;
mRootNode->accept( v );
Q_FOREACH ( const QgsSQLStatementCollectTableNames::TableColumnPair &pair, v.tableNamesReferenced )
for ( const QgsSQLStatementCollectTableNames::TableColumnPair &pair : qgis::as_const( v.tableNamesReferenced ) )
{
if ( !v.tableNamesDeclared.contains( pair.first ) )
{

View File

@ -436,7 +436,7 @@ long QgsTaskManager::addTaskPrivate( QgsTask *task, QgsTaskList dependencies, bo
}
// add all subtasks, must be done before dependency resolution
Q_FOREACH ( const QgsTask::SubTask &subTask, task->mSubTasks )
for ( const QgsTask::SubTask &subTask : qgis::as_const( task->mSubTasks ) )
{
switch ( subTask.dependency )
{
@ -533,7 +533,8 @@ bool QgsTaskManager::dependenciesSatisfied( long taskId ) const
if ( !dependencies.contains( taskId ) )
return true;
Q_FOREACH ( QgsTask *task, dependencies.value( taskId ) )
const auto constValue = dependencies.value( taskId );
for ( QgsTask *task : constValue )
{
if ( task->status() != QgsTask::Complete )
return false;
@ -561,7 +562,8 @@ bool QgsTaskManager::resolveDependencies( long firstTaskId, long currentTaskId,
if ( !dependencies.contains( currentTaskId ) )
return true;
Q_FOREACH ( QgsTask *task, dependencies.value( currentTaskId ) )
const auto constValue = dependencies.value( currentTaskId );
for ( QgsTask *task : constValue )
{
long dependentTaskId = taskId( task );
if ( dependentTaskId >= 0 )

View File

@ -387,7 +387,7 @@ void resetGraph( QgsTracerGraph &g )
g.joinedVertices = 0;
// fix vertices of deactivated edges
Q_FOREACH ( int eIdx, g.inactiveEdges )
for ( int eIdx : qgis::as_const( g.inactiveEdges ) )
{
if ( eIdx >= g.e.count() )
continue;

View File

@ -610,7 +610,8 @@ QStringList QgsVectorDataProvider::availableEncodings()
static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
Q_FOREACH ( const QString &codec, QTextCodec::availableCodecs() )
const auto codecs { QTextCodec::availableCodecs() };
for ( const QString &codec : codecs )
{
sEncodings << codec;
}

View File

@ -2889,7 +2889,8 @@ bool QgsVectorFileWriter::deleteShapeFile( const QString &fileName )
}
bool ok = true;
Q_FOREACH ( const QString &file, dir.entryList( filter ) )
const auto constEntryList = dir.entryList( filter );
for ( const QString &file : constEntryList )
{
QFile f( dir.canonicalPath() + '/' + file );
if ( !f.remove() )

View File

@ -49,7 +49,8 @@ static bool _hasCycleDFS( QgsVectorLayer *n, QHash<QgsVectorLayer *, int> &mark
if ( mark.value( n ) == 0 ) // not visited
{
mark[n] = 1; // temporary
Q_FOREACH ( QgsVectorLayer *m, _outEdges( n ) )
const auto outEdges { _outEdges( n ) };
for ( QgsVectorLayer *m : outEdges )
{
if ( _hasCycleDFS( m, mark ) )
return true;

View File

@ -71,7 +71,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinitionUtils::fromJoinedLayer( QgsVe
leftJoins << QStringLiteral( "LEFT JOIN \"%1\" AS %2 ON t.\"%5\"=%2.\"%3\"" ).arg( joinedLayer->id(), joinName, join.joinFieldName(), join.targetFieldName() );
if ( join.joinFieldNamesSubset() )
{
Q_FOREACH ( const QString &f, *join.joinFieldNamesSubset() )
const QStringList joinFieldNamesSubset { *join.joinFieldNamesSubset() };
for ( const QString &f : joinFieldNamesSubset )
{
columns << joinName + ".\"" + f + "\" AS \"" + prefix + f + "\"";
}

View File

@ -1901,7 +1901,8 @@ bool QgsRasterLayer::writeXml( QDomNode &layer_node,
noDataRangeList.setAttribute( QStringLiteral( "bandNo" ), bandNo );
noDataRangeList.setAttribute( QStringLiteral( "useSrcNoData" ), mDataProvider->useSourceNoDataValue( bandNo ) );
Q_FOREACH ( QgsRasterRange range, mDataProvider->userNoDataValues( bandNo ) )
const auto constUserNoDataValues = mDataProvider->userNoDataValues( bandNo );
for ( QgsRasterRange range : constUserNoDataValues )
{
QDomElement noDataRange = document.createElement( QStringLiteral( "noDataRange" ) );

View File

@ -51,7 +51,8 @@ QgsCptCityArchive::QgsCptCityArchive( const QString &archiveName, const QString
// make Author items
QgsCptCityDirectoryItem *dirItem = nullptr;
Q_FOREACH ( const QString &path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
const auto constEntryList = QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
for ( const QString &path : constEntryList )
{
if ( path == QLatin1String( "selections" ) )
continue;

View File

@ -1121,7 +1121,7 @@ QgsFeatureRenderer *QgsGraduatedSymbolRenderer::create( QDomElement &element, co
QDomElement rotationElem = element.firstChildElement( QStringLiteral( "rotation" ) );
if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral( "field" ) ).isEmpty() )
{
Q_FOREACH ( const QgsRendererRange &range, r->mRanges )
for ( const QgsRendererRange &range : qgis::as_const( r->mRanges ) )
{
convertSymbolRotation( range.symbol(), rotationElem.attribute( QStringLiteral( "field" ) ) );
}
@ -1133,7 +1133,7 @@ QgsFeatureRenderer *QgsGraduatedSymbolRenderer::create( QDomElement &element, co
QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral( "sizescale" ) );
if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral( "field" ) ).isEmpty() )
{
Q_FOREACH ( const QgsRendererRange &range, r->mRanges )
for ( const QgsRendererRange &range : qgis:: as_const( r->mRanges ) )
{
convertSymbolSizeScale( range.symbol(),
QgsSymbolLayerUtils::decodeScaleMethod( sizeScaleElem.attribute( QStringLiteral( "scalemethod" ) ) ),

View File

@ -288,7 +288,7 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext &context )
// operations do not need geometries to be valid
finalMulti.append( mExtentPolygon );
Q_FOREACH ( const QgsGeometry &geom, cit.geometries )
for ( const QgsGeometry &geom : qgis::as_const( cit.geometries ) )
{
QgsMultiPolygonXY multi;
QgsWkbTypes::Type type = QgsWkbTypes::flatType( geom.constGet()->wkbType() );

View File

@ -364,7 +364,8 @@ void QgsPointDistanceRenderer::printGroupInfo() const
for ( int i = 0; i < nGroups; ++i )
{
QgsDebugMsg( "***************displacement group " + QString::number( i ) );
Q_FOREACH ( const GroupedFeature &feature, mClusteredGroups.at( i ) )
const auto constAt = mClusteredGroups.at( i );
for ( const GroupedFeature &feature : constAt )
{
QgsDebugMsg( FID_TO_STRING( feature.feature.id() ) );
}

View File

@ -371,7 +371,8 @@ void QgsFeatureRenderer::renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolyg
if ( rings )
{
Q_FOREACH ( const QPolygonF &ring, *rings )
const auto constRings = *rings;
for ( const QPolygonF &ring : constRings )
{
const auto constRing = ring;
for ( QPointF pt : constRing )

View File

@ -954,7 +954,7 @@ void QgsRuleBasedRenderer::stopRender( QgsRenderContext &context )
{
//QgsDebugMsg(QString("level %1").arg(level.zIndex));
// go through all jobs at the level
Q_FOREACH ( const RenderJob *job, level.jobs )
for ( const RenderJob *job : qgis::as_const( level.jobs ) )
{
context.expressionContext().setFeature( job->ftr.feat );
//QgsDebugMsg(QString("job fid %1").arg(job->f->id()));

View File

@ -3714,12 +3714,14 @@ QStringList QgsSymbolLayerUtils::listSvgFiles()
for ( int i = 0; i < svgPaths.size(); i++ )
{
QDir dir( svgPaths[i] );
Q_FOREACH ( const QString &item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
const auto svgSubPaths = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
for ( const QString &item : svgSubPaths )
{
svgPaths.insert( i + 1, dir.path() + '/' + item );
}
Q_FOREACH ( const QString &item, dir.entryList( QStringList( "*.svg" ), QDir::Files ) )
const auto svgFiles = dir.entryList( QStringList( "*.svg" ), QDir::Files );
for ( const QString &item : svgFiles )
{
// TODO test if it is correct SVG
list.append( dir.path() + '/' + item );
@ -3740,12 +3742,14 @@ QStringList QgsSymbolLayerUtils::listSvgFilesAt( const QString &directory )
for ( int i = 0; i < svgPaths.size(); i++ )
{
QDir dir( svgPaths[i] );
Q_FOREACH ( const QString &item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
const auto svgSubPaths = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
for ( const QString &item : svgSubPaths )
{
svgPaths.insert( i + 1, dir.path() + '/' + item );
}
Q_FOREACH ( const QString &item, dir.entryList( QStringList( "*.svg" ), QDir::Files ) )
const auto svgFiles = dir.entryList( QStringList( "*.svg" ), QDir::Files );
for ( const QString &item : svgFiles )
{
list.append( dir.path() + '/' + item );
}