Skip to content
Permalink
Browse files

More Q_FOREACH to range-based for loop conversion

  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent 6958b7a commit 398f7f27b863eba689e4cc3d49c9c4949d7e0f8a
Showing with 234 additions and 121 deletions.
  1. +12 −6 src/core/layertree/qgslayertreemodel.cpp
  2. +2 −1 src/core/layertree/qgslayertreenode.cpp
  3. +12 −6 src/core/layertree/qgslayertreeutils.cpp
  4. +2 −1 src/core/layout/qgslayoutitemlegend.cpp
  5. +6 −3 src/core/metadata/qgslayermetadatavalidator.cpp
  6. +16 −8 src/core/processing/models/qgsprocessingmodelalgorithm.cpp
  7. +4 −2 src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp
  8. +32 −16 src/core/processing/qgsprocessingparameters.cpp
  9. +2 −1 src/core/processing/qgsprocessingregistry.cpp
  10. +2 −1 src/core/qgsblockingnetworkrequest.cpp
  11. +2 −1 src/core/qgsbrowsermodel.cpp
  12. +3 −2 src/core/qgsdatasourceuri.cpp
  13. +8 −4 src/core/qgsdiagramrenderer.cpp
  14. +2 −1 src/core/qgsfeature.cpp
  15. +2 −1 src/core/qgsinterval.cpp
  16. +2 −1 src/core/qgsjsonutils.cpp
  17. +2 −1 src/core/qgslegendrenderer.cpp
  18. +2 −1 src/core/qgsmaphittest.cpp
  19. +4 −2 src/core/qgsmaplayer.cpp
  20. +2 −1 src/core/qgsmaplayerlegend.cpp
  21. +2 −1 src/core/qgsmaprendererjob.cpp
  22. +2 −1 src/core/qgsmapsettingsutils.cpp
  23. +6 −3 src/core/qgsmapthemecollection.cpp
  24. +4 −2 src/core/qgsnetworkaccessmanager.cpp
  25. +2 −1 src/core/qgsnetworkreplyparser.cpp
  26. +2 −1 src/core/qgsobjectcustomproperties.cpp
  27. +15 −8 src/core/qgsogcutils.cpp
  28. +10 −5 src/core/qgsproject.cpp
  29. +2 −1 src/core/qgsproviderregistry.cpp
  30. +2 −1 src/core/qgsrelationmanager.cpp
  31. +2 −1 src/core/qgssnappingconfig.cpp
  32. +9 −6 src/core/qgssnappingutils.cpp
  33. +4 −2 src/core/qgssqlexpressioncompiler.cpp
  34. +8 −4 src/core/qgssqlstatement.cpp
  35. +15 −6 src/core/qgstracer.cpp
  36. +2 −1 src/core/qgsvectorlayer.cpp
  37. +4 −2 src/core/qgsvectorlayercache.cpp
  38. +6 −3 src/core/qgsvectorlayereditbuffer.cpp
  39. +7 −6 src/core/qgsvectorlayerfeatureiterator.cpp
  40. +2 −1 src/core/qgsvectorlayerjoinbuffer.cpp
  41. +2 −1 src/core/qgsvirtuallayerdefinitionutils.cpp
  42. +3 −2 src/core/symbology/qgscptcityarchive.cpp
  43. +4 −2 src/core/symbology/qgsrulebasedrenderer.cpp
@@ -614,7 +614,8 @@ void QgsLayerTreeModel::setLegendFilterByScale( double scale )

// this could be later done in more efficient way
// 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 );
}

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

// this could be later done in more efficient way
// 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 );

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

void QgsLayerTreeModel::connectToLayers( QgsLayerTreeGroup *parentGroup )
{
Q_FOREACH ( QgsLayerTreeNode *node, parentGroup->children() )
const auto constChildren = parentGroup->children();
for ( QgsLayerTreeNode *node : constChildren )
{
if ( QgsLayerTree::isGroup( node ) )
connectToLayers( QgsLayerTree::toGroup( node ) );
@@ -949,7 +954,8 @@ void QgsLayerTreeModel::connectToLayers( 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 ) )
disconnectFromLayers( QgsLayerTree::toGroup( node ) );
@@ -142,7 +142,8 @@ void fetchCheckedLayers( const QgsLayerTreeNode *node, QList<QgsMapLayer *> &lay
layers << nodeLayer->layer();
}

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

@@ -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 )
{
Q_FOREACH ( QgsLayerTreeNode *node, nodeGroup->children() )
const auto constChildren = nodeGroup->children();
for ( QgsLayerTreeNode *node : constChildren )
{
if ( QgsLayerTree::isGroup( node ) )
{
@@ -294,7 +295,8 @@ bool QgsLayerTreeUtils::layersModified( const QList<QgsLayerTreeLayer *> &layerN
void QgsLayerTreeUtils::removeInvalidLayers( QgsLayerTreeGroup *group )
{
QList<QgsLayerTreeNode *> nodesToRemove;
Q_FOREACH ( QgsLayerTreeNode *node, group->children() )
const auto constChildren = group->children();
for ( QgsLayerTreeNode *node : constChildren )
{
if ( QgsLayerTree::isGroup( node ) )
removeInvalidLayers( QgsLayerTree::toGroup( node ) );
@@ -382,7 +384,8 @@ QStringList QgsLayerTreeUtils::invisibleLayerList( QgsLayerTreeNode *node )

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

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() )
{
@@ -433,7 +437,8 @@ QString QgsLayerTreeUtils::legendFilterByExpression( const QgsLayerTreeLayer &la

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

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 )
{
@@ -744,7 +744,8 @@ void QgsLayoutItemLegend::mapLayerStyleOverridesChanged()
{
mLegendModel->setLayerStyleOverrides( mMap->layerStyleOverrides() );

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

@@ -94,7 +94,8 @@ bool QgsNativeMetadataBaseValidator::validate( const QgsAbstractMetadataBase *me

// validate contacts
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() )
{
@@ -106,7 +107,8 @@ bool QgsNativeMetadataBaseValidator::validate( const QgsAbstractMetadataBase *me

// validate links
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() )
{
@@ -158,7 +160,8 @@ bool QgsNativeMetadataValidator::validate( const QgsAbstractMetadataBase *baseMe
}

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() )
{
@@ -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 childParams;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, child.algorithm()->parameterDefinitions() )
const auto constParameterDefinitions = child.algorithm()->parameterDefinitions();
for ( const QgsProcessingParameterDefinition *def : constParameterDefinitions )
{
if ( !def->isDestination() )
{
@@ -219,7 +220,8 @@ bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId,
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin();
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
&& source.outputChildId() == childId
@@ -869,7 +871,8 @@ QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSo
continue;

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 )
{
@@ -905,7 +908,8 @@ QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSo
if ( !alg )
continue;

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

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

0 comments on commit 398f7f2

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