Skip to content

Commit

Permalink
More Q_FOREACH to range-based for loop conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent 6958b7a commit 398f7f2
Show file tree
Hide file tree
Showing 43 changed files with 234 additions and 121 deletions.
18 changes: 12 additions & 6 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -614,7 +614,8 @@ void QgsLayerTreeModel::setLegendFilterByScale( double scale )


// this could be later done in more efficient way // this could be later done in more efficient way
// by just updating active legend nodes, without refreshing original legend nodes // by just updating active legend nodes, without refreshing original legend nodes
Q_FOREACH ( QgsLayerTreeLayer *nodeLayer, mRootNode->findLayers() ) const auto constFindLayers = mRootNode->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : constFindLayers )
refreshLayerLegend( nodeLayer ); refreshLayerLegend( nodeLayer );
} }


Expand All @@ -634,7 +635,8 @@ void QgsLayerTreeModel::setLegendFilter( const QgsMapSettings *settings, bool us
// collect expression filters // collect expression filters
if ( useExpressions ) if ( useExpressions )
{ {
Q_FOREACH ( QgsLayerTreeLayer *nodeLayer, mRootNode->findLayers() ) const auto constFindLayers = mRootNode->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : constFindLayers )
{ {
bool enabled; bool enabled;
QString expr = QgsLayerTreeUtils::legendFilterByExpression( *nodeLayer, &enabled ); QString expr = QgsLayerTreeUtils::legendFilterByExpression( *nodeLayer, &enabled );
Expand Down Expand Up @@ -670,7 +672,8 @@ void QgsLayerTreeModel::setLegendFilter( const QgsMapSettings *settings, bool us


// this could be later done in more efficient way // this could be later done in more efficient way
// by just updating active legend nodes, without refreshing original legend nodes // by just updating active legend nodes, without refreshing original legend nodes
Q_FOREACH ( QgsLayerTreeLayer *nodeLayer, mRootNode->findLayers() ) const auto constFindLayers = mRootNode->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : constFindLayers )
refreshLayerLegend( nodeLayer ); refreshLayerLegend( nodeLayer );


setAutoCollapseLegendNodes( bkAutoCollapse ); setAutoCollapseLegendNodes( bkAutoCollapse );
Expand Down Expand Up @@ -902,7 +905,8 @@ void QgsLayerTreeModel::connectToLayer( QgsLayerTreeLayer *nodeLayer )
static int _numLayerCount( QgsLayerTreeGroup *group, const QString &layerId ) static int _numLayerCount( QgsLayerTreeGroup *group, const QString &layerId )
{ {
int count = 0; int count = 0;
Q_FOREACH ( QgsLayerTreeNode *child, group->children() ) const auto constChildren = group->children();
for ( QgsLayerTreeNode *child : constChildren )
{ {
if ( QgsLayerTree::isLayer( child ) ) if ( QgsLayerTree::isLayer( child ) )
{ {
Expand Down Expand Up @@ -938,7 +942,8 @@ void QgsLayerTreeModel::disconnectFromLayer( QgsLayerTreeLayer *nodeLayer )


void QgsLayerTreeModel::connectToLayers( QgsLayerTreeGroup *parentGroup ) void QgsLayerTreeModel::connectToLayers( QgsLayerTreeGroup *parentGroup )
{ {
Q_FOREACH ( QgsLayerTreeNode *node, parentGroup->children() ) const auto constChildren = parentGroup->children();
for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
connectToLayers( QgsLayerTree::toGroup( node ) ); connectToLayers( QgsLayerTree::toGroup( node ) );
Expand All @@ -949,7 +954,8 @@ void QgsLayerTreeModel::connectToLayers( QgsLayerTreeGroup *parentGroup )


void QgsLayerTreeModel::disconnectFromLayers( QgsLayerTreeGroup *parentGroup ) void QgsLayerTreeModel::disconnectFromLayers( QgsLayerTreeGroup *parentGroup )
{ {
Q_FOREACH ( QgsLayerTreeNode *node, parentGroup->children() ) const auto constChildren = parentGroup->children();
for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
disconnectFromLayers( QgsLayerTree::toGroup( node ) ); disconnectFromLayers( QgsLayerTree::toGroup( node ) );
Expand Down
3 changes: 2 additions & 1 deletion src/core/layertree/qgslayertreenode.cpp
Expand Up @@ -142,7 +142,8 @@ void fetchCheckedLayers( const QgsLayerTreeNode *node, QList<QgsMapLayer *> &lay
layers << nodeLayer->layer(); layers << nodeLayer->layer();
} }


Q_FOREACH ( QgsLayerTreeNode *child, node->children() ) const auto constChildren = node->children();
for ( QgsLayerTreeNode *child : constChildren )
fetchCheckedLayers( child, layers ); fetchCheckedLayers( child, layers );
} }


Expand Down
18 changes: 12 additions & 6 deletions src/core/layertree/qgslayertreeutils.cpp
Expand Up @@ -154,7 +154,8 @@ static QDomElement _writeOldLegendGroup( QDomDocument &doc, QgsLayerTreeGroup *n


static void _writeOldLegendGroupChildren( QDomDocument &doc, QDomElement &groupElem, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QList<QgsMapLayer *> &order ) static void _writeOldLegendGroupChildren( QDomDocument &doc, QDomElement &groupElem, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QList<QgsMapLayer *> &order )
{ {
Q_FOREACH ( QgsLayerTreeNode *node, nodeGroup->children() ) const auto constChildren = nodeGroup->children();
for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
{ {
Expand Down Expand Up @@ -294,7 +295,8 @@ bool QgsLayerTreeUtils::layersModified( const QList<QgsLayerTreeLayer *> &layerN
void QgsLayerTreeUtils::removeInvalidLayers( QgsLayerTreeGroup *group ) void QgsLayerTreeUtils::removeInvalidLayers( QgsLayerTreeGroup *group )
{ {
QList<QgsLayerTreeNode *> nodesToRemove; QList<QgsLayerTreeNode *> nodesToRemove;
Q_FOREACH ( QgsLayerTreeNode *node, group->children() ) const auto constChildren = group->children();
for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
removeInvalidLayers( QgsLayerTree::toGroup( node ) ); removeInvalidLayers( QgsLayerTree::toGroup( node ) );
Expand Down Expand Up @@ -382,7 +384,8 @@ QStringList QgsLayerTreeUtils::invisibleLayerList( QgsLayerTreeNode *node )


void QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups( QgsLayerTreeGroup *group ) void QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups( QgsLayerTreeGroup *group )
{ {
Q_FOREACH ( QgsLayerTreeNode *child, group->children() ) const auto constChildren = group->children();
for ( QgsLayerTreeNode *child : constChildren )
{ {
if ( QgsLayerTree::isGroup( child ) ) if ( QgsLayerTree::isGroup( child ) )
{ {
Expand All @@ -402,7 +405,8 @@ void QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups( QgsLayerTreeGroup *grou


void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup *group, const QgsProject *project ) void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup *group, const QgsProject *project )
{ {
Q_FOREACH ( QgsLayerTreeNode *node, group->children() ) const auto constChildren = group->children();
for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( !node->customProperty( QStringLiteral( "embedded_project" ) ).toString().isEmpty() ) if ( !node->customProperty( QStringLiteral( "embedded_project" ) ).toString().isEmpty() )
{ {
Expand Down Expand Up @@ -433,7 +437,8 @@ QString QgsLayerTreeUtils::legendFilterByExpression( const QgsLayerTreeLayer &la


bool QgsLayerTreeUtils::hasLegendFilterExpression( const QgsLayerTreeGroup &group ) bool QgsLayerTreeUtils::hasLegendFilterExpression( const QgsLayerTreeGroup &group )
{ {
Q_FOREACH ( QgsLayerTreeLayer *l, group.findLayers() ) const auto constFindLayers = group.findLayers();
for ( QgsLayerTreeLayer *l : constFindLayers )
{ {
bool exprEnabled; bool exprEnabled;
QString expr = legendFilterByExpression( *l, &exprEnabled ); QString expr = legendFilterByExpression( *l, &exprEnabled );
Expand All @@ -453,7 +458,8 @@ QgsLayerTreeLayer *QgsLayerTreeUtils::insertLayerBelow( QgsLayerTreeGroup *group
return nullptr; return nullptr;


int idx = 0; int idx = 0;
Q_FOREACH ( QgsLayerTreeNode *vl, inTree->parent()->children() ) const auto constChildren = inTree->parent()->children();
for ( QgsLayerTreeNode *vl : constChildren )
{ {
if ( vl->nodeType() == QgsLayerTreeNode::NodeLayer && static_cast<QgsLayerTreeLayer *>( vl )->layer() == refLayer ) if ( vl->nodeType() == QgsLayerTreeNode::NodeLayer && static_cast<QgsLayerTreeLayer *>( vl )->layer() == refLayer )
{ {
Expand Down
3 changes: 2 additions & 1 deletion src/core/layout/qgslayoutitemlegend.cpp
Expand Up @@ -744,7 +744,8 @@ void QgsLayoutItemLegend::mapLayerStyleOverridesChanged()
{ {
mLegendModel->setLayerStyleOverrides( mMap->layerStyleOverrides() ); mLegendModel->setLayerStyleOverrides( mMap->layerStyleOverrides() );


Q_FOREACH ( QgsLayerTreeLayer *nodeLayer, mLegendModel->rootGroup()->findLayers() ) const auto constFindLayers = mLegendModel->rootGroup()->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : constFindLayers )
mLegendModel->refreshLayerLegend( nodeLayer ); mLegendModel->refreshLayerLegend( nodeLayer );
} }


Expand Down
9 changes: 6 additions & 3 deletions src/core/metadata/qgslayermetadatavalidator.cpp
Expand Up @@ -94,7 +94,8 @@ bool QgsNativeMetadataBaseValidator::validate( const QgsAbstractMetadataBase *me


// validate contacts // validate contacts
index = 0; index = 0;
Q_FOREACH ( const QgsAbstractMetadataBase::Contact &contact, metadata->contacts() ) const auto constContacts = metadata->contacts();
for ( const QgsAbstractMetadataBase::Contact &contact : constContacts )
{ {
if ( contact.name.isEmpty() ) if ( contact.name.isEmpty() )
{ {
Expand All @@ -106,7 +107,8 @@ bool QgsNativeMetadataBaseValidator::validate( const QgsAbstractMetadataBase *me


// validate links // validate links
index = 0; index = 0;
Q_FOREACH ( const QgsAbstractMetadataBase::Link &link, metadata->links() ) const auto constLinks = metadata->links();
for ( const QgsAbstractMetadataBase::Link &link : constLinks )
{ {
if ( link.name.isEmpty() ) if ( link.name.isEmpty() )
{ {
Expand Down Expand Up @@ -158,7 +160,8 @@ bool QgsNativeMetadataValidator::validate( const QgsAbstractMetadataBase *baseMe
} }


int index = 0; int index = 0;
Q_FOREACH ( const QgsLayerMetadata::SpatialExtent &extent, metadata->extent().spatialExtents() ) const auto constSpatialExtents = metadata->extent().spatialExtents();
for ( const QgsLayerMetadata::SpatialExtent &extent : constSpatialExtents )
{ {
if ( !extent.extentCrs.isValid() ) if ( !extent.extentCrs.isValid() )
{ {
Expand Down
24 changes: 16 additions & 8 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -99,7 +99,8 @@ QgsProcessingAlgorithm::Flags QgsProcessingModelAlgorithm::flags() const
QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const
{ {
QVariantMap childParams; QVariantMap childParams;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, child.algorithm()->parameterDefinitions() ) const auto constParameterDefinitions = child.algorithm()->parameterDefinitions();
for ( const QgsProcessingParameterDefinition *def : constParameterDefinitions )
{ {
if ( !def->isDestination() ) if ( !def->isDestination() )
{ {
Expand Down Expand Up @@ -219,7 +220,8 @@ bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId,
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin(); QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin();
for ( ; childParamIt != candidateChildParams.constEnd(); ++childParamIt ) for ( ; childParamIt != candidateChildParams.constEnd(); ++childParamIt )
{ {
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, childParamIt.value() ) const auto constValue = childParamIt.value();
for ( const QgsProcessingModelChildParameterSource &source : constValue )
{ {
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput
&& source.outputChildId() == childId && source.outputChildId() == childId
Expand Down Expand Up @@ -869,7 +871,8 @@ QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSo
continue; continue;


bool ok = sourceDef->dataTypes().isEmpty(); bool ok = sourceDef->dataTypes().isEmpty();
Q_FOREACH ( int type, sourceDef->dataTypes() ) const auto constDataTypes = sourceDef->dataTypes();
for ( int type : constDataTypes )
{ {
if ( dataTypes.contains( type ) || type == QgsProcessing::TypeMapLayer || type == QgsProcessing::TypeVector || type == QgsProcessing::TypeVectorAnyGeometry ) if ( dataTypes.contains( type ) || type == QgsProcessing::TypeMapLayer || type == QgsProcessing::TypeVector || type == QgsProcessing::TypeVectorAnyGeometry )
{ {
Expand Down Expand Up @@ -905,7 +908,8 @@ QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSo
if ( !alg ) if ( !alg )
continue; continue;


Q_FOREACH ( const QgsProcessingOutputDefinition *out, alg->outputDefinitions() ) const auto constOutputDefinitions = alg->outputDefinitions();
for ( const QgsProcessingOutputDefinition *out : constOutputDefinitions )
{ {
if ( outputTypes.contains( out->type() ) ) if ( outputTypes.contains( out->type() ) )
{ {
Expand Down Expand Up @@ -1283,7 +1287,8 @@ bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QStrin
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin(); QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt ) for ( ; paramIt != childParams.constEnd(); ++paramIt )
{ {
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) const auto constValue = paramIt.value();
for ( const QgsProcessingModelChildParameterSource &source : constValue )
{ {
if ( source.source() == QgsProcessingModelChildParameterSource::ModelParameter if ( source.source() == QgsProcessingModelChildParameterSource::ModelParameter
&& source.parameterName() == name ) && source.parameterName() == name )
Expand Down Expand Up @@ -1336,7 +1341,8 @@ void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QStri
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin(); QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt ) for ( ; paramIt != childParams.constEnd(); ++paramIt )
{ {
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) const auto constValue = paramIt.value();
for ( const QgsProcessingModelChildParameterSource &source : constValue )
{ {
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput
&& source.outputChildId() == childId ) && source.outputChildId() == childId )
Expand Down Expand Up @@ -1372,7 +1378,8 @@ void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QStri
const QgsProcessingModelChildAlgorithm &alg = mChildAlgorithms.value( childId ); const QgsProcessingModelChildAlgorithm &alg = mChildAlgorithms.value( childId );


// add direct dependencies // add direct dependencies
Q_FOREACH ( const QString &c, alg.dependencies() ) const auto constDependencies = alg.dependencies();
for ( const QString &c : constDependencies )
{ {
if ( !depends.contains( c ) ) if ( !depends.contains( c ) )
{ {
Expand All @@ -1386,7 +1393,8 @@ void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QStri
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin(); QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt ) for ( ; paramIt != childParams.constEnd(); ++paramIt )
{ {
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) const auto constValue = paramIt.value();
for ( const QgsProcessingModelChildParameterSource &source : constValue )
{ {
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) ) if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) )
{ {
Expand Down
Expand Up @@ -98,7 +98,8 @@ QVariant QgsProcessingModelChildAlgorithm::toVariant() const
for ( ; paramIt != mParams.constEnd(); ++paramIt ) for ( ; paramIt != mParams.constEnd(); ++paramIt )
{ {
QVariantList sources; QVariantList sources;
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() ) const auto constValue = paramIt.value();
for ( const QgsProcessingModelChildParameterSource &source : constValue )
{ {
sources << source.toVariant(); sources << source.toVariant();
} }
Expand Down Expand Up @@ -137,7 +138,8 @@ bool QgsProcessingModelChildAlgorithm::loadVariant( const QVariant &child )
for ( ; paramIt != paramMap.constEnd(); ++paramIt ) for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{ {
QgsProcessingModelChildParameterSources sources; QgsProcessingModelChildParameterSources sources;
Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() ) const auto constToList = paramIt->toList();
for ( const QVariant &sourceVar : constToList )
{ {
QgsProcessingModelChildParameterSource param; QgsProcessingModelChildParameterSource param;
if ( !param.loadVariant( sourceVar.toMap() ) ) if ( !param.loadVariant( sourceVar.toMap() ) )
Expand Down

0 comments on commit 398f7f2

Please sign in to comment.