Skip to content
Permalink
Browse files
Merge pull request #9722 from m-kuhn/code_modernization
Make QGIS core library a Q_FOREACH free zone
  • Loading branch information
m-kuhn committed Apr 7, 2019
2 parents 4a87cc9 + 4852bac commit 736e8cbbc34ef8ea4ec935851766dd295a365b1a
Show file tree
Hide file tree
Showing 191 changed files with 1,747 additions and 921 deletions.
@@ -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(
@@ -321,11 +321,11 @@ QgsExpressionContextScope *QgsExpressionContextUtils::layerScope( const QgsMapLa
return scope;

//add variables defined in layer properties
QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
const QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
const QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();

int varIndex = 0;
Q_FOREACH ( const QString &variableName, variableNames )
for ( const QString &variableName : variableNames )
{
if ( varIndex >= variableValues.length() )
{
@@ -525,11 +525,12 @@ QgsExpressionContextScope *QgsExpressionContextUtils::layoutScope( const QgsLayo
return scope.release();

//add variables defined in layout properties
QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
const QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
const QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();

int varIndex = 0;
Q_FOREACH ( const QString &variableName, variableNames )

for ( const QString &variableName : variableNames )
{
if ( varIndex >= variableValues.length() )
{
@@ -129,14 +129,14 @@ void QgsLayerTree::writeXml( QDomElement &parentElement, const QgsReadWriteConte

writeCommonXml( elem );

Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->writeXml( elem, context );

QDomElement customOrderElem = doc.createElement( QStringLiteral( "custom-order" ) );
customOrderElem.setAttribute( QStringLiteral( "enabled" ), mHasCustomLayerOrder ? 1 : 0 );
elem.appendChild( customOrderElem );

Q_FOREACH ( QgsMapLayer *layer, mCustomLayerOrder )
for ( QgsMapLayer *layer : qgis::as_const( mCustomLayerOrder ) )
{
// Safety belt, see https://issues.qgis.org/issues/19145
// Crash when deleting an item from the layout legend
@@ -181,12 +181,13 @@ void QgsLayerTree::nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int
}
else if ( QgsLayerTree::isGroup( child ) )
{
Q_FOREACH ( QgsLayerTreeLayer *nodeL, QgsLayerTree::toGroup( child )->findLayers() )
const auto nodeLayers = QgsLayerTree::toGroup( child )->findLayers();
for ( QgsLayerTreeLayer *nodeL : nodeLayers )
layers << nodeL->layer();
}
}

Q_FOREACH ( QgsMapLayer *layer, layers )
for ( QgsMapLayer *layer : qgis::as_const( layers ) )
{
if ( !mCustomLayerOrder.contains( layer ) && layer )
mCustomLayerOrder.append( layer );
@@ -217,8 +218,8 @@ void QgsLayerTree::addMissingLayers()
{
bool changed = false;

const QList< QgsLayerTreeLayer * > foundLayers = findLayers();
for ( const auto layer : foundLayers )
const QList< QgsLayerTreeLayer * > layers = findLayers();
for ( const auto layer : layers )
{
if ( !mCustomLayerOrder.contains( layer->layer() ) &&
layer->layer() && layer->layer()->isSpatial() )
@@ -138,7 +138,7 @@ void QgsLayerTreeGroup::removeChildNode( QgsLayerTreeNode *node )

void QgsLayerTreeGroup::removeLayer( QgsMapLayer *layer )
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -173,7 +173,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 childNodes = children();
for ( QgsLayerTreeNode *treeNode : childNodes )
{
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
{
@@ -201,7 +202,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( QgsMapLayer *layer ) const

QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -222,7 +223,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const
{
QList<QgsLayerTreeLayer *> list;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
list << QgsLayerTree::toLayer( child );
@@ -234,7 +235,7 @@ QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const

QgsLayerTreeGroup *QgsLayerTreeGroup::findGroup( const QString &name )
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
{
@@ -310,7 +311,7 @@ void QgsLayerTreeGroup::writeXml( QDomElement &parentElement, const QgsReadWrite

writeCommonXml( elem );

Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->writeXml( elem, context );

parentElement.appendChild( elem );
@@ -336,7 +337,7 @@ QString QgsLayerTreeGroup::dump() const
{
QString header = QStringLiteral( "GROUP: %1 checked=%2 expanded=%3\n" ).arg( name() ).arg( mChecked ).arg( mExpanded );
QStringList childrenDump;
Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
childrenDump << node->dump().split( '\n' );
for ( int i = 0; i < childrenDump.count(); ++i )
childrenDump[i].prepend( " " );
@@ -350,7 +351,7 @@ QgsLayerTreeGroup *QgsLayerTreeGroup::clone() const

void QgsLayerTreeGroup::resolveReferences( const QgsProject *project, bool looseMatching )
{
Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->resolveReferences( project, looseMatching );
}

@@ -379,7 +380,7 @@ void QgsLayerTreeGroup::setIsMutuallyExclusive( bool enabled, int initialChildIn
{
// try to use first checked index
int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( _nodeIsChecked( child ) )
{
@@ -396,7 +397,7 @@ void QgsLayerTreeGroup::setIsMutuallyExclusive( bool enabled, int initialChildIn
QStringList QgsLayerTreeGroup::findLayerIds() const
{
QStringList lst;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
lst << QgsLayerTree::toGroup( child )->findLayerIds();
@@ -432,7 +433,7 @@ void QgsLayerTreeGroup::updateChildVisibilityMutuallyExclusive()
mChangingChildVisibility = true; // guard against running again setVisible() triggered from children

int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
child->setItemVisibilityChecked( index == mMutuallyExclusiveChildIndex );
++index;
@@ -448,7 +449,7 @@ void QgsLayerTreeGroup::setItemVisibilityCheckedRecursive( bool checked )
mChangingChildVisibility = true; // guard against running again setVisible() triggered from children

int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
child->setItemVisibilityCheckedRecursive( checked && ( mMutuallyExclusiveChildIndex < 0 || index == mMutuallyExclusiveChildIndex ) );
++index;

0 comments on commit 736e8cb

Please sign in to comment.