Skip to content

Commit

Permalink
Make sure a lot of foreach loops use references
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 8, 2015
1 parent bd2d78c commit 73ffb83
Show file tree
Hide file tree
Showing 72 changed files with 162 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -795,7 +795,7 @@ void QgsComposerLegendWidget::resetLayerNodeToDefaults()

mLegend->beginCommand( tr( "Legend updated" ) );

foreach ( QString key, nodeLayer->customProperties() )
foreach ( const QString& key, nodeLayer->customProperties() )
{
if ( key.startsWith( "legend/" ) )
nodeLayer->removeCustomProperty( key );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -298,7 +298,7 @@ void QgsComposerMapWidget::aboutToShowVisibilityPresetsMenu()
return;

menu->clear();
foreach ( QString presetName, QgsProject::instance()->visibilityPresetCollection()->presets() )
foreach ( const QString& presetName, QgsProject::instance()->visibilityPresetCollection()->presets() )
{
QAction* a = menu->addAction( presetName, this, SLOT( visibilityPresetSelected() ) );
a->setCheckable( true );
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -1141,7 +1141,7 @@ APP_EXPORT int main( int argc, char *argv[] )
QList< QPair<QgsVectorLayer *, int > > layers;
if ( !dxfPreset.isEmpty() )
{
foreach ( QString layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
foreach ( const QString& layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer ) );
if ( !vl )
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -2870,7 +2870,7 @@ void QgisApp::updateProjectFromTemplates()
mProjectFromTemplateMenu->clear();

// Add entries
foreach ( QString templateFile, templateFiles )
foreach ( const QString& templateFile, templateFiles )
{
mProjectFromTemplateMenu->addAction( templateFile );
}
Expand Down Expand Up @@ -3003,7 +3003,7 @@ QString QgisApp::crsAndFormatAdjustedLayerUri( const QString &uri, const QString

// Adjust layer CRS to project CRS
QgsCoordinateReferenceSystem testCrs;
foreach ( QString c, supportedCrs )
foreach ( const QString& c, supportedCrs )
{
testCrs.createFromOgcWmsCrs( c );
if ( testCrs == mMapCanvas->mapSettings().destinationCrs() )
Expand All @@ -3016,7 +3016,7 @@ QString QgisApp::crsAndFormatAdjustedLayerUri( const QString &uri, const QString

// Use the last used image format
QString lastImageEncoding = QSettings().value( "/qgis/lastWmsImageEncoding", "image/png" ).toString();
foreach ( QString fmt, supportedFormats )
foreach ( const QString& fmt, supportedFormats )
{
if ( fmt == lastImageEncoding )
{
Expand Down Expand Up @@ -3561,7 +3561,7 @@ void QgisApp::addDatabaseLayers( QStringList const & layerPathList, QString cons

QApplication::setOverrideCursor( Qt::WaitCursor );

foreach ( QString layerPath, layerPathList )
foreach ( const QString& layerPath, layerPathList )
{
// create the layer
QgsDataSourceURI uri( layerPath );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -293,7 +293,7 @@ void QgsBookmarks::importFromXML()
QStringList queriesList = queries.split( ";" );
QSqlQuery query( model->database() );

foreach ( QString queryTxt, queriesList )
foreach ( const QString& queryTxt, queriesList )
{
if ( queryTxt.trimmed().isEmpty() )
{
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -135,7 +135,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
mREList.clear();
if ( mPatternSyntax == "normal" )
{
foreach ( QString f, mFilter.split( "|" ) )
foreach ( const QString& f, mFilter.split( "|" ) )
{
QRegExp rx( QString( "*%1*" ).arg( f.trimmed() ) );
rx.setPatternSyntax( QRegExp::Wildcard );
Expand All @@ -145,7 +145,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
}
else if ( mPatternSyntax == "wildcard" )
{
foreach ( QString f, mFilter.split( "|" ) )
foreach ( const QString& f, mFilter.split( "|" ) )
{
QRegExp rx( f.trimmed() );
rx.setPatternSyntax( QRegExp::Wildcard );
Expand Down Expand Up @@ -175,7 +175,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
{
if ( mPatternSyntax == "normal" || mPatternSyntax == "wildcard" )
{
foreach ( QRegExp rx, mREList )
foreach ( const QRegExp& rx, mREList )
{
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.exactMatch( value ) ) );
if ( rx.exactMatch( value ) )
Expand All @@ -184,7 +184,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
}
else
{
foreach ( QRegExp rx, mREList )
foreach ( const QRegExp& rx, mREList )
{
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.indexIn( value ) ) );
if ( rx.indexIn( value ) != -1 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsclipboard.cpp
Expand Up @@ -162,7 +162,7 @@ QgsFeatureList QgsClipboard::copyOf( const QgsFields &fields )
return mFeatureClipboard;

QgsFeatureList features;
foreach ( QString row, values )
foreach ( const QString& row, values )
{
// Assume that it's just WKT for now.
QgsGeometry* geometry = QgsGeometry::fromWkt( row );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -131,7 +131,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
if ( featList.size() == 0 )
return false;

foreach ( QgsFeature feat, featList )
foreach ( const QgsFeature& feat, featList )
{
if ( layer->actions()->defaultAction() >= 0 )
{
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsoptions.cpp
Expand Up @@ -750,7 +750,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( mySystemLocale ) );
QString myUserLocale = settings.value( "locale/userLocale", "" ).toString();
QStringList myI18nList = i18nList();
foreach ( QString l, myI18nList )
foreach ( const QString& l, myI18nList )
{
cboLocale->addItem( QIcon( QString( ":/images/flags/%1.png" ).arg( l ) ), QLocale( l ).nativeLanguageName(), l );
}
Expand Down Expand Up @@ -1762,11 +1762,11 @@ void QgsOptions::loadGdalDriverList()
// myDrivers.sort();
// sort list case insensitive - no existing function for this!
QMap<QString, QString> strMap;
foreach ( QString str, myDrivers )
foreach ( const QString& str, myDrivers )
strMap.insert( str.toLower(), str );
myDrivers = strMap.values();

foreach ( QString myName, myDrivers )
foreach ( const QString& myName, myDrivers )
{
QTreeWidgetItem * mypItem = new QTreeWidgetItem( QStringList( myName ) );
if ( mySkippedDrivers.contains( myName ) )
Expand Down Expand Up @@ -1794,13 +1794,13 @@ void QgsOptions::loadGdalDriverList()

// populate cmbEditCreateOptions with gdal write drivers - sorted, GTiff first
strMap.clear();
foreach ( QString str, myGdalWriteDrivers )
foreach ( const QString& str, myGdalWriteDrivers )
strMap.insert( str.toLower(), str );
myGdalWriteDrivers = strMap.values();
myGdalWriteDrivers.removeAll( "Gtiff" );
myGdalWriteDrivers.prepend( "GTiff" );
cmbEditCreateOptions->clear();
foreach ( QString myName, myGdalWriteDrivers )
foreach ( const QString& myName, myGdalWriteDrivers )
{
cmbEditCreateOptions->addItem( myName );
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgspluginregistry.cpp
Expand Up @@ -138,8 +138,9 @@ void QgsPluginRegistry::dump()
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
QgsDebugMsg( "PYTHON PLUGINS IN REGISTRY:" );
foreach ( QString pluginName, mPythonUtils->listActivePlugins() )
foreach ( const QString& pluginName, mPythonUtils->listActivePlugins() )
{
Q_UNUSED( pluginName );
QgsDebugMsg( pluginName );
}
}
Expand Down Expand Up @@ -176,7 +177,7 @@ void QgsPluginRegistry::unloadAll()

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
foreach ( QString pluginName, mPythonUtils->listActivePlugins() )
foreach ( const QString& pluginName, mPythonUtils->listActivePlugins() )
{
mPythonUtils->unloadPlugin( pluginName );
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsprojectlayergroupdialog.cpp
Expand Up @@ -62,7 +62,7 @@ QStringList QgsProjectLayerGroupDialog::selectedGroups() const
{
QStringList groups;
QgsLayerTreeModel* model = mTreeView->layerTreeModel();
foreach ( QModelIndex index, mTreeView->selectionModel()->selectedIndexes() )
foreach ( const QModelIndex& index, mTreeView->selectionModel()->selectedIndexes() )
{
QgsLayerTreeNode* node = model->index2node( index );
if ( QgsLayerTree::isGroup( node ) )
Expand All @@ -75,7 +75,7 @@ QStringList QgsProjectLayerGroupDialog::selectedLayerIds() const
{
QStringList layerIds;
QgsLayerTreeModel* model = mTreeView->layerTreeModel();
foreach ( QModelIndex index, mTreeView->selectionModel()->selectedIndexes() )
foreach ( const QModelIndex& index, mTreeView->selectionModel()->selectedIndexes() )
{
QgsLayerTreeNode* node = model->index2node( index );
if ( QgsLayerTree::isLayer( node ) )
Expand All @@ -88,7 +88,7 @@ QStringList QgsProjectLayerGroupDialog::selectedLayerNames() const
{
QStringList layerNames;
QgsLayerTreeModel* model = mTreeView->layerTreeModel();
foreach ( QModelIndex index, mTreeView->selectionModel()->selectedIndexes() )
foreach ( const QModelIndex& index, mTreeView->selectionModel()->selectedIndexes() )
{
QgsLayerTreeNode* node = model->index2node( index );
if ( QgsLayerTree::isLayer( node ) )
Expand Down Expand Up @@ -204,7 +204,7 @@ void QgsProjectLayerGroupDialog::removeEmbeddedNodes( QgsLayerTreeGroup* node )

void QgsProjectLayerGroupDialog::onTreeViewSelectionChanged()
{
foreach ( QModelIndex index, mTreeView->selectionModel()->selectedIndexes() )
foreach ( const QModelIndex& index, mTreeView->selectionModel()->selectedIndexes() )
{
unselectChildren( index );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -311,7 +311,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
if ( grpWMSList->isChecked() )
{
QStringList list;
foreach ( QString value, values )
foreach ( const QString& value, values )
{
list << QString( "EPSG:%1" ).arg( value );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -355,7 +355,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv

//fill available renderers into combo box
QgsRasterRendererRegistryEntry entry;
foreach ( QString name, QgsRasterRendererRegistry::instance()->renderersList() )
foreach ( const QString& name, QgsRasterRendererRegistry::instance()->renderersList() )
{
if ( QgsRasterRendererRegistry::instance()->rendererData( name, entry ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgssnappingdialog.cpp
Expand Up @@ -459,7 +459,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )

void QgsSnappingDialog::layersWillBeRemoved( QStringList thelayers )
{
foreach ( QString theLayerId, thelayers )
foreach ( const QString& theLayerId, thelayers )
{
QTreeWidgetItem *item = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsvisibilitypresets.cpp
Expand Up @@ -59,7 +59,7 @@ void QgsVisibilityPresets::addPerLayerCheckedLegendSymbols( QgsVisibilityPresetC
{
QgsLayerTreeModel* model = QgisApp::instance()->layerTreeView()->layerTreeModel();

foreach ( QString layerID, rec.mVisibleLayerIDs )
foreach ( const QString& layerID, rec.mVisibleLayerIDs )
{
QgsLayerTreeLayer* nodeLayer = model->rootGroup()->findLayer( layerID );
if ( !nodeLayer )
Expand Down Expand Up @@ -90,7 +90,7 @@ void QgsVisibilityPresets::addPerLayerCurrentStyle( QgsVisibilityPresetCollectio
{
QgsLayerTreeModel* model = QgisApp::instance()->layerTreeView()->layerTreeModel();

foreach ( QString layerID, rec.mVisibleLayerIDs )
foreach ( const QString& layerID, rec.mVisibleLayerIDs )
{
QgsLayerTreeLayer* nodeLayer = model->rootGroup()->findLayer( layerID );
if ( !nodeLayer )
Expand Down Expand Up @@ -136,7 +136,7 @@ QStringList QgsVisibilityPresets::orderedPresetVisibleLayers( const QString& nam
QgsLayerTreeMapCanvasBridge* bridge = QgisApp::instance()->layerTreeCanvasBridge();
QStringList order = bridge->hasCustomLayerOrder() ? bridge->customLayerOrder() : bridge->defaultLayerOrder();
QStringList order2;
foreach ( QString layerID, order )
foreach ( const QString& layerID, order )
{
if ( visibleIds.contains( layerID ) )
order2 << layerID;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -70,7 +70,7 @@ void QgsAtlasComposition::removeLayers( QStringList layers )
return;
}

foreach ( QString layerId, layers )
foreach ( const QString& layerId, layers )
{
if ( layerId == mCoverageLayer->id() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -555,7 +555,7 @@ QStringList QgsComposerMap::layersToRender() const

QStringList layerNames = exprVal.toString().split( "|" );
//need to convert layer names to layer ids
Q_FOREACH ( QString name, layerNames )
Q_FOREACH ( const QString& name, layerNames )
{
QList< QgsMapLayer* > matchingLayers = QgsMapLayerRegistry::instance()->mapLayersByName( name );
Q_FOREACH ( QgsMapLayer* layer, matchingLayers )
Expand Down
10 changes: 5 additions & 5 deletions src/core/composer/qgscomposertablev2.cpp
Expand Up @@ -942,7 +942,7 @@ bool QgsComposerTableV2::calculateMaxColumnWidths()
//column width set to automatic, so check content size
QStringList multiLineSplit = ( *colIt ).toString().split( "\n" );
currentCellTextWidth = 0;
Q_FOREACH ( QString line, multiLineSplit )
Q_FOREACH ( const QString& line, multiLineSplit )
{
currentCellTextWidth = qMax( currentCellTextWidth, QgsComposerUtils::textWidthMM( mContentFont, line ) );
}
Expand Down Expand Up @@ -1168,7 +1168,7 @@ bool QgsComposerTableV2::textRequiresWrapping( const QString& text, double colum

QStringList multiLineSplit = text.split( "\n" );
double currentTextWidth = 0;
Q_FOREACH ( QString line, multiLineSplit )
Q_FOREACH ( const QString& line, multiLineSplit )
{
currentTextWidth = qMax( currentTextWidth, QgsComposerUtils::textWidthMM( font, line ) );
}
Expand All @@ -1180,15 +1180,15 @@ QString QgsComposerTableV2::wrappedText( const QString &value, double columnWidt
{
QStringList lines = value.split( "\n" );
QStringList outLines;
Q_FOREACH ( QString line, lines )
Q_FOREACH ( const QString& line, lines )
{
if ( textRequiresWrapping( line, columnWidth, font ) )
{
//first step is to identify words which must be on their own line (too long to fit)
QStringList words = line.split( " " );
QStringList linesToProcess;
QString wordsInCurrentLine;
Q_FOREACH ( QString word, words )
Q_FOREACH ( const QString& word, words )
{
if ( textRequiresWrapping( word, columnWidth, font ) )
{
Expand All @@ -1208,7 +1208,7 @@ QString QgsComposerTableV2::wrappedText( const QString &value, double columnWidt
if ( !wordsInCurrentLine.isEmpty() )
linesToProcess << wordsInCurrentLine;

Q_FOREACH ( QString line, linesToProcess )
Q_FOREACH ( const QString& line, linesToProcess )
{
QString remainingText = line;
int lastPos = remainingText.lastIndexOf( " " );
Expand Down
4 changes: 2 additions & 2 deletions src/core/diagram/qgshistogramdiagram.cpp
Expand Up @@ -53,7 +53,7 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsFeature& feature, const QgsRen
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );

foreach ( QString cat, s.categoryAttributes )
foreach ( const QString& cat, s.categoryAttributes )
{
QgsExpression* expression = getExpression( cat, expressionContext );
maxValue = qMax( expression->evaluate( &expressionContext ).toDouble(), maxValue );
Expand Down Expand Up @@ -135,7 +135,7 @@ void QgsHistogramDiagram::renderDiagram( const QgsFeature& feature, QgsRenderCon
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );

foreach ( QString cat, s.categoryAttributes )
foreach ( const QString& cat, s.categoryAttributes )
{
QgsExpression* expression = getExpression( cat, expressionContext );
double currentVal = expression->evaluate( &expressionContext ).toDouble();
Expand Down

0 comments on commit 73ffb83

Please sign in to comment.