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 398f7f2 commit a063363eeab55fcc357fb317e7894f11617fdab6
@@ -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();
}
}
@@ -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 )
{
@@ -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 );
}
@@ -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 )
@@ -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 )
@@ -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 )
@@ -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();

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

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

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

0 comments on commit a063363

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