Skip to content

Commit

Permalink
Less auto
Browse files Browse the repository at this point in the history
(cherry picked from commit 1a07654)
  • Loading branch information
nyalldawson committed Mar 16, 2020
1 parent 5a8e131 commit 3e05f07
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions src/core/qgsmapthemecollection.cpp
Expand Up @@ -45,8 +45,8 @@ QgsMapThemeCollection::MapThemeLayerRecord QgsMapThemeCollection::createThemeLay
bool hasCheckableItems = false; bool hasCheckableItems = false;
bool someItemsUnchecked = false; bool someItemsUnchecked = false;
QSet<QString> checkedItems; QSet<QString> checkedItems;
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true ); const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes ) for ( QgsLayerTreeModelLegendNode *legendNode : layerLegendNodes )
{ {
if ( legendNode->flags() & Qt::ItemIsUserCheckable ) if ( legendNode->flags() & Qt::ItemIsUserCheckable )
{ {
Expand Down Expand Up @@ -80,7 +80,7 @@ static QString _groupId( QgsLayerTreeNode *node )


void QgsMapThemeCollection::createThemeFromCurrentState( QgsLayerTreeGroup *parent, QgsLayerTreeModel *model, QgsMapThemeCollection::MapThemeRecord &rec ) void QgsMapThemeCollection::createThemeFromCurrentState( QgsLayerTreeGroup *parent, QgsLayerTreeModel *model, QgsMapThemeCollection::MapThemeRecord &rec )
{ {
const auto constChildren = parent->children(); const QList<QgsLayerTreeNode *> constChildren = parent->children();
for ( QgsLayerTreeNode *node : constChildren ) for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
Expand Down Expand Up @@ -150,7 +150,7 @@ void QgsMapThemeCollection::applyThemeToLayer( QgsLayerTreeLayer *nodeLayer, Qgs
if ( layerRec.usingLegendItems ) if ( layerRec.usingLegendItems )
{ {
// some nodes are not checked // some nodes are not checked
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true ); const QList<QgsLayerTreeModelLegendNode *> constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes ) for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
{ {
QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString(); QString ruleKey = legendNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString();
Expand All @@ -163,7 +163,7 @@ void QgsMapThemeCollection::applyThemeToLayer( QgsLayerTreeLayer *nodeLayer, Qgs
else else
{ {
// all nodes should be checked // all nodes should be checked
const auto constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true ); const QList<QgsLayerTreeModelLegendNode *> constLayerLegendNodes = model->layerLegendNodes( nodeLayer, true );
for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes ) for ( QgsLayerTreeModelLegendNode *legendNode : constLayerLegendNodes )
{ {
if ( ( legendNode->flags() & Qt::ItemIsUserCheckable ) && if ( ( legendNode->flags() & Qt::ItemIsUserCheckable ) &&
Expand All @@ -183,7 +183,7 @@ void QgsMapThemeCollection::applyThemeToLayer( QgsLayerTreeLayer *nodeLayer, Qgs


void QgsMapThemeCollection::applyThemeToGroup( QgsLayerTreeGroup *parent, QgsLayerTreeModel *model, const QgsMapThemeCollection::MapThemeRecord &rec ) void QgsMapThemeCollection::applyThemeToGroup( QgsLayerTreeGroup *parent, QgsLayerTreeModel *model, const QgsMapThemeCollection::MapThemeRecord &rec )
{ {
const auto constChildren = parent->children(); const QList<QgsLayerTreeNode *> constChildren = parent->children();
for ( QgsLayerTreeNode *node : constChildren ) for ( QgsLayerTreeNode *node : constChildren )
{ {
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
Expand Down Expand Up @@ -234,8 +234,8 @@ QList<QgsMapLayer *> QgsMapThemeCollection::masterLayerOrder() const


QList<QgsMapLayer *> QgsMapThemeCollection::masterVisibleLayers() const QList<QgsMapLayer *> QgsMapThemeCollection::masterVisibleLayers() const
{ {
QList< QgsMapLayer *> allLayers = masterLayerOrder(); const QList< QgsMapLayer *> allLayers = masterLayerOrder();
QList< QgsMapLayer * > visibleLayers = mProject->layerTreeRoot()->checkedLayers(); const QList< QgsMapLayer * > visibleLayers = mProject->layerTreeRoot()->checkedLayers();


if ( allLayers.isEmpty() ) if ( allLayers.isEmpty() )
{ {
Expand All @@ -245,8 +245,7 @@ QList<QgsMapLayer *> QgsMapThemeCollection::masterVisibleLayers() const
else else
{ {
QList< QgsMapLayer * > orderedVisibleLayers; QList< QgsMapLayer * > orderedVisibleLayers;
const auto constAllLayers = allLayers; for ( QgsMapLayer *layer : allLayers )
for ( QgsMapLayer *layer : constAllLayers )
{ {
if ( visibleLayers.contains( layer ) ) if ( visibleLayers.contains( layer ) )
orderedVisibleLayers << layer; orderedVisibleLayers << layer;
Expand Down Expand Up @@ -309,7 +308,7 @@ QStringList QgsMapThemeCollection::mapThemes() const
QStringList QgsMapThemeCollection::mapThemeVisibleLayerIds( const QString &name ) const QStringList QgsMapThemeCollection::mapThemeVisibleLayerIds( const QString &name ) const
{ {
QStringList layerIds; QStringList layerIds;
const auto constMapThemeVisibleLayers = mapThemeVisibleLayers( name ); const QList<QgsMapLayer *> constMapThemeVisibleLayers = mapThemeVisibleLayers( name );
for ( QgsMapLayer *layer : constMapThemeVisibleLayers ) for ( QgsMapLayer *layer : constMapThemeVisibleLayers )
{ {
layerIds << layer->id(); layerIds << layer->id();
Expand All @@ -320,12 +319,12 @@ QStringList QgsMapThemeCollection::mapThemeVisibleLayerIds( const QString &name
QList<QgsMapLayer *> QgsMapThemeCollection::mapThemeVisibleLayers( const QString &name ) const QList<QgsMapLayer *> QgsMapThemeCollection::mapThemeVisibleLayers( const QString &name ) const
{ {
QList<QgsMapLayer *> layers; QList<QgsMapLayer *> layers;
const QList<MapThemeLayerRecord> &recs = mMapThemes.value( name ).mLayerRecords; const QList<MapThemeLayerRecord> recs = mMapThemes.value( name ).mLayerRecords;
QList<QgsMapLayer *> layerOrder = masterLayerOrder(); const QList<QgsMapLayer *> layerOrder = masterLayerOrder();
if ( layerOrder.isEmpty() ) if ( layerOrder.isEmpty() )
{ {
// no master layer order - so we have to just use the stored theme layer order as a fallback // no master layer order - so we have to just use the stored theme layer order as a fallback
const auto records {mMapThemes.value( name ).mLayerRecords}; const QList<MapThemeLayerRecord> records { mMapThemes.value( name ).mLayerRecords };
for ( const MapThemeLayerRecord &layerRec : records ) for ( const MapThemeLayerRecord &layerRec : records )
{ {
if ( layerRec.isVisible && layerRec.layer() ) if ( layerRec.isVisible && layerRec.layer() )
Expand All @@ -334,11 +333,9 @@ QList<QgsMapLayer *> QgsMapThemeCollection::mapThemeVisibleLayers( const QString
} }
else else
{ {
const auto constLayerOrder = layerOrder; for ( QgsMapLayer *layer : layerOrder )
for ( QgsMapLayer *layer : constLayerOrder )
{ {
const auto constRecs = recs; for ( const MapThemeLayerRecord &layerRec : recs )
for ( const MapThemeLayerRecord &layerRec : constRecs )
{ {
if ( layerRec.isVisible && layerRec.layer() == layer ) if ( layerRec.isVisible && layerRec.layer() == layer )
layers << layerRec.layer(); layers << layerRec.layer();
Expand Down Expand Up @@ -379,7 +376,7 @@ QMap<QString, QString> QgsMapThemeCollection::mapThemeStyleOverrides( const QStr
if ( !mMapThemes.contains( presetName ) ) if ( !mMapThemes.contains( presetName ) )
return styleOverrides; return styleOverrides;


const auto records {mMapThemes.value( presetName ).mLayerRecords}; const QList<MapThemeLayerRecord> records {mMapThemes.value( presetName ).mLayerRecords};
for ( const MapThemeLayerRecord &layerRec : records ) for ( const MapThemeLayerRecord &layerRec : records )
{ {
if ( !layerRec.layer() ) if ( !layerRec.layer() )
Expand Down Expand Up @@ -408,8 +405,7 @@ void QgsMapThemeCollection::reconnectToLayersStyleManager()
// disconnect( 0, 0, this, SLOT( layerStyleRenamed( QString, QString ) ) ); // disconnect( 0, 0, this, SLOT( layerStyleRenamed( QString, QString ) ) );


QSet<QgsMapLayer *> layers; QSet<QgsMapLayer *> layers;
const auto constMMapThemes = mMapThemes; for ( const MapThemeRecord &rec : qgis::as_const( mMapThemes ) )
for ( const MapThemeRecord &rec : constMMapThemes )
{ {
for ( const MapThemeLayerRecord &layerRec : qgis::as_const( rec.mLayerRecords ) ) for ( const MapThemeLayerRecord &layerRec : qgis::as_const( rec.mLayerRecords ) )
{ {
Expand All @@ -418,7 +414,7 @@ void QgsMapThemeCollection::reconnectToLayersStyleManager()
} }
} }


const auto constLayers = layers; const QSet<QgsMapLayer *> constLayers = layers;
for ( QgsMapLayer *ml : constLayers ) for ( QgsMapLayer *ml : constLayers )
{ {
connect( ml->styleManager(), &QgsMapLayerStyleManager::styleRenamed, this, &QgsMapThemeCollection::layerStyleRenamed ); connect( ml->styleManager(), &QgsMapLayerStyleManager::styleRenamed, this, &QgsMapThemeCollection::layerStyleRenamed );
Expand Down Expand Up @@ -562,7 +558,7 @@ void QgsMapThemeCollection::writeXml( QDomDocument &doc )
{ {
QDomElement visPresetsElem = doc.createElement( QStringLiteral( "visibility-presets" ) ); QDomElement visPresetsElem = doc.createElement( QStringLiteral( "visibility-presets" ) );


auto keys = mMapThemes.keys(); QList< QString > keys = mMapThemes.keys();


std::sort( keys.begin(), keys.end() ); std::sort( keys.begin(), keys.end() );


Expand Down Expand Up @@ -668,8 +664,7 @@ void QgsMapThemeCollection::registryLayersRemoved( const QStringList &layerIDs )
} }
} }


const auto constChangedThemes = changedThemes; for ( const QString &theme : qgis::as_const( changedThemes ) )
for ( const QString &theme : constChangedThemes )
{ {
emit mapThemeChanged( theme ); emit mapThemeChanged( theme );
} }
Expand Down Expand Up @@ -701,8 +696,8 @@ void QgsMapThemeCollection::layerStyleRenamed( const QString &oldName, const QSt
} }
} }
} }
const auto constChangedThemes = changedThemes;
for ( const QString &theme : constChangedThemes ) for ( const QString &theme : qgis::as_const( changedThemes ) )
{ {
emit mapThemeChanged( theme ); emit mapThemeChanged( theme );
} }
Expand All @@ -726,8 +721,7 @@ void QgsMapThemeCollection::MapThemeRecord::addLayerRecord( const QgsMapThemeCol
QHash<QgsMapLayer *, QgsMapThemeCollection::MapThemeLayerRecord> QgsMapThemeCollection::MapThemeRecord::validLayerRecords() const QHash<QgsMapLayer *, QgsMapThemeCollection::MapThemeLayerRecord> QgsMapThemeCollection::MapThemeRecord::validLayerRecords() const
{ {
QHash<QgsMapLayer *, MapThemeLayerRecord> validSet; QHash<QgsMapLayer *, MapThemeLayerRecord> validSet;
const auto constMLayerRecords = mLayerRecords; for ( const MapThemeLayerRecord &layerRec : mLayerRecords )
for ( const MapThemeLayerRecord &layerRec : constMLayerRecords )
{ {
if ( layerRec.layer() ) if ( layerRec.layer() )
validSet.insert( layerRec.layer(), layerRec ); validSet.insert( layerRec.layer(), layerRec );
Expand Down

0 comments on commit 3e05f07

Please sign in to comment.