Skip to content
Permalink
Browse files

Some cleanup

  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent 29fe352 commit cbecf25407d004fb52a4ecd49d36d32aeabeef14
@@ -321,12 +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;
const auto constVariableNames = variableNames;
for ( const QString &variableName : constVariableNames )
for ( const QString &variableName : variableNames )
{
if ( varIndex >= variableValues.length() )
{
@@ -526,12 +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;
const auto constVariableNames = variableNames;
for ( const QString &variableName : constVariableNames )

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

writeCommonXml( elem );

const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *node : constMChildren )
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 );

const auto constMCustomLayerOrder = mCustomLayerOrder;
for ( QgsMapLayer *layer : constMCustomLayerOrder )
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
@@ -183,14 +181,13 @@ void QgsLayerTree::nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int
}
else if ( QgsLayerTree::isGroup( child ) )
{
const auto constFindLayers = QgsLayerTree::toGroup( child )->findLayers();
for ( QgsLayerTreeLayer *nodeL : constFindLayers )
const auto nodeLayers = QgsLayerTree::toGroup( child )->findLayers();
for ( QgsLayerTreeLayer *nodeL : nodeLayers )
layers << nodeL->layer();
}
}

const auto constLayers = layers;
for ( QgsMapLayer *layer : constLayers )
for ( QgsMapLayer *layer : qgis::as_const( layers ) )
{
if ( !mCustomLayerOrder.contains( layer ) && layer )
mCustomLayerOrder.append( layer );
@@ -221,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,8 +138,7 @@ void QgsLayerTreeGroup::removeChildNode( QgsLayerTreeNode *node )

void QgsLayerTreeGroup::removeLayer( QgsMapLayer *layer )
{
const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *child : constMChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -174,8 +173,8 @@ void QgsLayerTreeGroup::removeChildren( int from, int count )
void QgsLayerTreeGroup::removeChildrenGroupWithoutLayers()
{
// clean the layer tree by removing empty group
const auto constChildren = children();
for ( QgsLayerTreeNode *treeNode : constChildren )
const auto childNodes = children();
for ( QgsLayerTreeNode *treeNode : childNodes )
{
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
{
@@ -203,8 +202,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( QgsMapLayer *layer ) const

QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
{
const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *child : constMChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -225,8 +223,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const
{
QList<QgsLayerTreeLayer *> list;
const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *child : constMChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
list << QgsLayerTree::toLayer( child );
@@ -238,8 +235,7 @@ QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const

QgsLayerTreeGroup *QgsLayerTreeGroup::findGroup( const QString &name )
{
const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *child : constMChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
{
@@ -315,8 +311,7 @@ void QgsLayerTreeGroup::writeXml( QDomElement &parentElement, const QgsReadWrite

writeCommonXml( elem );

const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *node : constMChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->writeXml( elem, context );

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

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

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

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

int index = 0;
const auto constMChildren = mChildren;
for ( QgsLayerTreeNode *child : constMChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
child->setItemVisibilityCheckedRecursive( checked && ( mMutuallyExclusiveChildIndex < 0 || index == mMutuallyExclusiveChildIndex ) );
++index;
@@ -474,8 +474,7 @@ static bool _isChildOfNode( QgsLayerTreeNode *child, QgsLayerTreeNode *node )

static bool _isChildOfNodes( QgsLayerTreeNode *child, const QList<QgsLayerTreeNode *> &nodes )
{
const auto constNodes = nodes;
for ( QgsLayerTreeNode *n : constNodes )
for ( QgsLayerTreeNode *n : nodes )
{
if ( _isChildOfNode( child, n ) )
return true;
@@ -503,8 +502,7 @@ QList<QgsLayerTreeNode *> QgsLayerTreeModel::indexes2nodes( const QModelIndexLis

// remove any children of nodes if both parent node and children are selected
QList<QgsLayerTreeNode *> nodesFinal;
const auto constNodes = nodes;
for ( QgsLayerTreeNode *node : constNodes )
for ( QgsLayerTreeNode *node : qgis::as_const( nodes ) )
{
if ( !_isChildOfNodes( node, nodes ) )
nodesFinal << node;
@@ -614,8 +612,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
const auto constFindLayers = mRootNode->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : constFindLayers )
const auto layers = mRootNode->findLayers();
for ( QgsLayerTreeLayer *nodeLayer : layers )
refreshLayerLegend( nodeLayer );
}

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

setAutoCollapseLegendNodes( bkAutoCollapse );
@@ -1050,8 +1048,7 @@ QMimeData *QgsLayerTreeModel::mimeData( const QModelIndexList &indexes ) const

QDomDocument doc;
QDomElement rootElem = doc.createElement( QStringLiteral( "layer_tree_model_data" ) );
const auto constNodesFinal = nodesFinal;
for ( QgsLayerTreeNode *node : constNodesFinal )
for ( QgsLayerTreeNode *node : qgis::as_const( nodesFinal ) )
node->writeXml( rootElem, QgsReadWriteContext() );
doc.appendChild( rootElem );
QString txt = doc.toString();
@@ -1156,8 +1153,7 @@ QList<QgsLayerTreeModelLegendNode *> QgsLayerTreeModel::filterLegendNodes( const

if ( mLegendFilterByScale > 0 )
{
const auto constNodes = nodes;
for ( QgsLayerTreeModelLegendNode *node : constNodes )
for ( QgsLayerTreeModelLegendNode *node : qgis::as_const( nodes ) )
{
if ( node->isScaleOK( mLegendFilterByScale ) )
filtered << node;
@@ -1167,8 +1163,7 @@ QList<QgsLayerTreeModelLegendNode *> QgsLayerTreeModel::filterLegendNodes( const
{
if ( !nodes.isEmpty() && mLegendFilterMapSettings->layers().contains( nodes.at( 0 )->layerNode()->layer() ) )
{
const auto constNodes = nodes;
for ( QgsLayerTreeModelLegendNode *node : constNodes )
for ( QgsLayerTreeModelLegendNode *node : qgis::as_const( nodes ) )
{
QString ruleKey = node->data( QgsSymbolLegendNode::RuleKeyRole ).toString();
bool checked = mLegendFilterUsesExtent || node->data( Qt::CheckStateRole ).toInt() == Qt::Checked;

0 comments on commit cbecf25

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