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 398f7f2 commit a063363
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/core/layertree/qgslayertree.cpp
Expand Up @@ -183,7 +183,8 @@ void QgsLayerTree::nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int
}
else if ( QgsLayerTree::isGroup( child ) )
{
Q_FOREACH ( QgsLayerTreeLayer *nodeL, QgsLayerTree::toGroup( child )->findLayers() )
const auto constFindLayers = QgsLayerTree::toGroup( child )->findLayers();
for ( QgsLayerTreeLayer *nodeL : constFindLayers )
layers << nodeL->layer();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/layertree/qgslayertreegroup.cpp
Expand Up @@ -174,7 +174,8 @@ void QgsLayerTreeGroup::removeChildren( int from, int count )
void QgsLayerTreeGroup::removeChildrenGroupWithoutLayers()
{
// clean the layer tree by removing empty group
Q_FOREACH ( QgsLayerTreeNode *treeNode, children() )
const auto constChildren = children();
for ( QgsLayerTreeNode *treeNode : constChildren )
{
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/layertree/qgslayertreeutils.cpp
Expand Up @@ -366,7 +366,8 @@ QStringList QgsLayerTreeUtils::invisibleLayerList( QgsLayerTreeNode *node )

if ( QgsLayerTree::isGroup( node ) )
{
Q_FOREACH ( QgsLayerTreeNode *child, QgsLayerTree::toGroup( node )->children() )
const auto constChildren = QgsLayerTree::toGroup( node )->children();
for ( QgsLayerTreeNode *child : constChildren )
{
list << invisibleLayerList( child );
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/layout/qgslayout.cpp
Expand Up @@ -470,7 +470,8 @@ QRectF QgsLayout::layoutBounds( bool ignorePages, double margin ) const
QRectF bounds;

//add all layout items and pages which are in the layout
Q_FOREACH ( const QGraphicsItem *item, items() )
const auto constItems = items();
for ( const QGraphicsItem *item : constItems )
{
const QgsLayoutItem *layoutItem = dynamic_cast<const QgsLayoutItem *>( item );
if ( !layoutItem )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsarchive.cpp
Expand Up @@ -113,7 +113,8 @@ QStringList QgsArchive::files() const

QString QgsProjectArchive::projectFile() const
{
Q_FOREACH ( const QString &file, files() )
const auto constFiles = files();
for ( const QString &file : constFiles )
{
QFileInfo fileInfo( file );
if ( fileInfo.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) == 0 )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsbrowsermodel.cpp
Expand Up @@ -126,7 +126,8 @@ void QgsBrowserModel::addRootItems()
// container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
QMap<int, QgsDataItem *> providerMap;

Q_FOREACH ( QgsDataItemProvider *pr, QgsApplication::dataItemProviderRegistry()->providers() )
const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers();
for ( QgsDataItemProvider *pr : constProviders )
{
int capabilities = pr->capabilities();
if ( capabilities == QgsDataProvider::NoDataCapabilities )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsdataitem.cpp
Expand Up @@ -1331,7 +1331,8 @@ QVector<QgsDataItem *> QgsFavoritesItem::createChildren( const QString &favDir,
{
QVector<QgsDataItem *> children;
QString pathName = pathComponent( favDir );
Q_FOREACH ( QgsDataItemProvider *provider, QgsApplication::dataItemProviderRegistry()->providers() )
const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers();
for ( QgsDataItemProvider *provider : constProviders )
{
int capabilities = provider->capabilities();

Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsdiagramrenderer.cpp
Expand Up @@ -471,7 +471,8 @@ QSet<QString> QgsDiagramRenderer::referencedFields( const QgsExpressionContext &
if ( !mDiagram )
return referenced;

Q_FOREACH ( const QString &att, diagramAttributes() )
const auto constDiagramAttributes = diagramAttributes();
for ( const QString &att : constDiagramAttributes )
{
QgsExpression *expression = mDiagram->getExpression( att, context );
const auto constReferencedColumns = expression->referencedColumns();
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsellipsoidutils.cpp
Expand Up @@ -452,7 +452,8 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
QStringList QgsEllipsoidUtils::acronyms()
{
QStringList result;
Q_FOREACH ( const QgsEllipsoidUtils::EllipsoidDefinition &def, definitions() )
const auto constDefinitions = definitions();
for ( const QgsEllipsoidUtils::EllipsoidDefinition &def : constDefinitions )
{
result << def.acronym;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayerstylemanager.cpp
Expand Up @@ -73,7 +73,8 @@ void QgsMapLayerStyleManager::writeXml( QDomElement &mgrElement ) const
QDomDocument doc = mgrElement.ownerDocument();
mgrElement.setAttribute( QStringLiteral( "current" ), mCurrentStyle );

Q_FOREACH ( const QString &name, styles() )
const auto constStyles = styles();
for ( const QString &name : constStyles )
{
QDomElement ch = doc.createElement( QStringLiteral( "map-layer-style" ) );
ch.setAttribute( QStringLiteral( "name" ), name );
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmimedatautils.cpp
Expand Up @@ -157,7 +157,8 @@ static void _addLayerTreeNodeToUriList( QgsLayerTreeNode *node, QgsMimeDataUtils
{
if ( QgsLayerTree::isGroup( node ) )
{
Q_FOREACH ( QgsLayerTreeNode *child, QgsLayerTree::toGroup( node )->children() )
const auto constChildren = QgsLayerTree::toGroup( node )->children();
for ( QgsLayerTreeNode *child : constChildren )
_addLayerTreeNodeToUriList( child, uris );
}
else if ( QgsLayerTree::isLayer( node ) )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsproviderregistry.cpp
Expand Up @@ -553,7 +553,8 @@ void QgsProviderRegistry::registerGuis( QWidget *parent )
{
typedef void registerGui_function( QWidget * parent );

Q_FOREACH ( const QString &provider, providerList() )
const auto constProviderList = providerList();
for ( const QString &provider : constProviderList )
{
registerGui_function *registerGui = reinterpret_cast< registerGui_function * >( cast_to_fptr( function( provider, "registerGui" ) ) );

Expand Down
8 changes: 5 additions & 3 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1711,7 +1711,8 @@ bool QgsVectorLayer::writeXml( QDomNode &layer_node,

// dependencies
QDomElement dependenciesElement = document.createElement( QStringLiteral( "layerDependencies" ) );
Q_FOREACH ( const QgsMapLayerDependency &dep, dependencies() )
const auto constDependencies = dependencies();
for ( const QgsMapLayerDependency &dep : constDependencies )
{
if ( dep.type() != QgsMapLayerDependency::PresenceDependency )
continue;
Expand All @@ -1723,7 +1724,7 @@ bool QgsVectorLayer::writeXml( QDomNode &layer_node,

// change dependencies
QDomElement dataDependenciesElement = document.createElement( QStringLiteral( "dataDependencies" ) );
Q_FOREACH ( const QgsMapLayerDependency &dep, dependencies() )
for ( const QgsMapLayerDependency &dep : constDependencies )
{
if ( dep.type() != QgsMapLayerDependency::DataDependency )
continue;
Expand Down Expand Up @@ -4858,7 +4859,8 @@ QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties

// also clear old-style labeling config
removeCustomProperty( QStringLiteral( "labeling" ) );
Q_FOREACH ( const QString &key, customPropertyKeys() )
const auto constCustomPropertyKeys = customPropertyKeys();
for ( const QString &key : constCustomPropertyKeys )
{
if ( key.startsWith( QLatin1String( "labeling/" ) ) )
removeCustomProperty( key );
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Expand Up @@ -533,7 +533,8 @@ bool QgsVectorLayerJoinBuffer::addFeatures( QgsFeatureList &features, QgsFeature
return false;

// try to add/update a feature in each joined layer
Q_FOREACH ( const QgsVectorLayerJoinInfo &info, vectorJoins() )
const auto constVectorJoins = vectorJoins();
for ( const QgsVectorLayerJoinInfo &info : constVectorJoins )
{
QgsVectorLayer *joinLayer = info.joinLayer();

Expand Down Expand Up @@ -674,7 +675,8 @@ bool QgsVectorLayerJoinBuffer::deleteFeatures( const QgsFeatureIds &fids ) const
const auto constFids = fids;
for ( const QgsFeatureId &fid : constFids )
{
Q_FOREACH ( const QgsVectorLayerJoinInfo &info, vectorJoins() )
const auto constVectorJoins = vectorJoins();
for ( const QgsVectorLayerJoinInfo &info : constVectorJoins )
{
if ( info.isEditable() && info.hasCascadedDelete() )
{
Expand Down
12 changes: 8 additions & 4 deletions src/core/qgsvirtuallayerdefinition.cpp
Expand Up @@ -173,7 +173,8 @@ QUrl QgsVirtualLayerDefinition::toUrl() const
if ( !filePath().isEmpty() )
url = QUrl::fromLocalFile( filePath() );

Q_FOREACH ( const QgsVirtualLayerDefinition::SourceLayer &l, sourceLayers() )
const auto constSourceLayers = sourceLayers();
for ( const QgsVirtualLayerDefinition::SourceLayer &l : constSourceLayers )
{
if ( l.isReferenced() )
url.addQueryItem( QStringLiteral( "layer_ref" ), QStringLiteral( "%1:%2" ).arg( l.reference(), l.name() ) );
Expand Down Expand Up @@ -203,7 +204,8 @@ QUrl QgsVirtualLayerDefinition::toUrl() const
url.addQueryItem( QStringLiteral( "geometry" ), geometryField() );
}

Q_FOREACH ( const QgsField &f, fields() )
const auto constFields = fields();
for ( const QgsField &f : constFields )
{
if ( f.type() == QVariant::Int )
url.addQueryItem( QStringLiteral( "field" ), f.name() + ":int" );
Expand Down Expand Up @@ -238,7 +240,8 @@ void QgsVirtualLayerDefinition::addSource( const QString &name, const QString &s

bool QgsVirtualLayerDefinition::hasSourceLayer( const QString &name ) const
{
Q_FOREACH ( const QgsVirtualLayerDefinition::SourceLayer &l, sourceLayers() )
const auto constSourceLayers = sourceLayers();
for ( const QgsVirtualLayerDefinition::SourceLayer &l : constSourceLayers )
{
if ( l.name() == name )
{
Expand All @@ -250,7 +253,8 @@ bool QgsVirtualLayerDefinition::hasSourceLayer( const QString &name ) const

bool QgsVirtualLayerDefinition::hasReferencedLayers() const
{
Q_FOREACH ( const QgsVirtualLayerDefinition::SourceLayer &l, sourceLayers() )
const auto constSourceLayers = sourceLayers();
for ( const QgsVirtualLayerDefinition::SourceLayer &l : constSourceLayers )
{
if ( l.isReferenced() )
{
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology/qgscptcityarchive.cpp
Expand Up @@ -836,7 +836,8 @@ QVector< QgsCptCityDataItem * > QgsCptCityCollectionItem::childrenRamps( bool re
populate();

// recursively add children
Q_FOREACH ( QgsCptCityDataItem *childItem, children() )
const auto constChildren = children();
for ( QgsCptCityDataItem *childItem : constChildren )
{
QgsCptCityCollectionItem *collectionItem = dynamic_cast<QgsCptCityCollectionItem *>( childItem );
QgsCptCityColorRampItem *rampItem = dynamic_cast<QgsCptCityColorRampItem *>( childItem );
Expand Down Expand Up @@ -921,7 +922,8 @@ QVector<QgsCptCityDataItem *> QgsCptCityDirectoryItem::createChildren()
}

// add children dirs
Q_FOREACH ( const QString &childPath, dirEntries() )
const auto constDirEntries = dirEntries();
for ( const QString &childPath : constDirEntries )
{
QgsCptCityDataItem *childItem =
QgsCptCityDirectoryItem::dataItem( this, childPath, mPath + '/' + childPath );
Expand Down

0 comments on commit a063363

Please sign in to comment.