Skip to content
Permalink
Browse files

Make sure a lot of foreach loops use references

  • Loading branch information
nyalldawson committed Sep 8, 2015
1 parent bd2d78c commit 73ffb83ad4ee1c6ec6230c163c2eb7798bbafc7c
Showing with 162 additions and 162 deletions.
  1. +1 −1 src/app/composer/qgscomposerlegendwidget.cpp
  2. +1 −1 src/app/composer/qgscomposermapwidget.cpp
  3. +1 −1 src/app/main.cpp
  4. +4 −4 src/app/qgisapp.cpp
  5. +1 −1 src/app/qgsbookmarks.cpp
  6. +4 −4 src/app/qgsbrowserdockwidget.cpp
  7. +1 −1 src/app/qgsclipboard.cpp
  8. +1 −1 src/app/qgsmaptoolfeatureaction.cpp
  9. +5 −5 src/app/qgsoptions.cpp
  10. +3 −2 src/app/qgspluginregistry.cpp
  11. +4 −4 src/app/qgsprojectlayergroupdialog.cpp
  12. +1 −1 src/app/qgsprojectproperties.cpp
  13. +1 −1 src/app/qgsrasterlayerproperties.cpp
  14. +1 −1 src/app/qgssnappingdialog.cpp
  15. +3 −3 src/app/qgsvisibilitypresets.cpp
  16. +1 −1 src/core/composer/qgsatlascomposition.cpp
  17. +1 −1 src/core/composer/qgscomposermap.cpp
  18. +5 −5 src/core/composer/qgscomposertablev2.cpp
  19. +2 −2 src/core/diagram/qgshistogramdiagram.cpp
  20. +5 −5 src/core/dxf/qgsdxfexport.cpp
  21. +1 −1 src/core/effects/qgspainteffectregistry.cpp
  22. +2 −2 src/core/gps/qgsgpsdetector.cpp
  23. +1 −1 src/core/layertree/qgslayertreemodel.cpp
  24. +2 −2 src/core/layertree/qgslayertreeregistrybridge.cpp
  25. +1 −1 src/core/layertree/qgslayertreeutils.cpp
  26. +1 −1 src/core/pal/layer.cpp
  27. +1 −1 src/core/pal/pal.cpp
  28. +2 −2 src/core/qgsapplication.cpp
  29. +1 −1 src/core/qgsbrowsermodel.cpp
  30. +1 −1 src/core/qgscolorscheme.cpp
  31. +6 −6 src/core/qgsconditionalstyle.cpp
  32. +1 −1 src/core/qgsconditionalstyle.h
  33. +2 −2 src/core/qgscoordinatereferencesystem.cpp
  34. +6 −7 src/core/qgsdataitem.cpp
  35. +1 −1 src/core/qgsdataitemproviderregistry.cpp
  36. +3 −3 src/core/qgsdatasourceuri.cpp
  37. +1 −1 src/core/qgserror.cpp
  38. +3 −3 src/core/qgsexpression.cpp
  39. +12 −12 src/core/qgsexpressioncontext.cpp
  40. +4 −4 src/core/qgsgmlschema.cpp
  41. +4 −4 src/core/qgslegendrenderer.cpp
  42. +1 −1 src/core/qgsmaphittest.cpp
  43. +1 −1 src/core/qgsmaplayerlegend.cpp
  44. +1 −1 src/core/qgsmaprenderercache.cpp
  45. +1 −1 src/core/qgsmaprenderercustompainterjob.cpp
  46. +1 −1 src/core/qgsmaprendererjob.cpp
  47. +1 −1 src/core/qgsnetworkaccessmanager.cpp
  48. +1 −1 src/core/qgsnetworkreplyparser.cpp
  49. +1 −1 src/core/qgsobjectcustomproperties.cpp
  50. +3 −3 src/core/qgspallabeling.cpp
  51. +1 −1 src/core/qgspluginlayerregistry.cpp
  52. +1 −1 src/core/qgsproject.cpp
  53. +1 −1 src/core/qgsrelation.cpp
  54. +1 −1 src/core/qgssnappingutils.cpp
  55. +1 −1 src/core/qgsvectordataprovider.cpp
  56. +3 −3 src/core/qgsvectorfilewriter.cpp
  57. +2 −2 src/core/qgsvectorlayer.cpp
  58. +1 −1 src/core/qgsvectorlayerjoinbuffer.cpp
  59. +6 −6 src/core/qgsvisibilitypresetcollection.cpp
  60. +4 −4 src/core/raster/qgsrasterinterface.cpp
  61. +1 −1 src/core/raster/qgsrasterlayer.cpp
  62. +1 −1 src/core/raster/qgsrasterrange.cpp
  63. +3 −3 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  64. +4 −4 src/core/symbology-ng/qgscolorbrewerpalette.h
  65. +4 −4 src/core/symbology-ng/qgscptcityarchive.cpp
  66. +1 −1 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  67. +4 −4 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  68. +1 −1 src/core/symbology-ng/qgsrendererv2registry.cpp
  69. +2 −2 src/core/symbology-ng/qgsstylev2.cpp
  70. +1 −1 src/core/symbology-ng/qgssymbollayerv2registry.cpp
  71. +5 −5 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  72. +1 −1 src/core/symbology-ng/qgsvectorcolorrampv2.cpp
@@ -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 );
@@ -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 );
@@ -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 )
@@ -2870,7 +2870,7 @@ void QgisApp::updateProjectFromTemplates()
mProjectFromTemplateMenu->clear();

// Add entries
foreach ( QString templateFile, templateFiles )
foreach ( const QString& templateFile, templateFiles )
{
mProjectFromTemplateMenu->addAction( templateFile );
}
@@ -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() )
@@ -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 )
{
@@ -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 );
@@ -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() )
{
@@ -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 );
@@ -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 );
@@ -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 ) )
@@ -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 )
@@ -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 );
@@ -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 )
{
@@ -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 );
}
@@ -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 ) )
@@ -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 );
}
@@ -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 );
}
}
@@ -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 );
}
@@ -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 ) )
@@ -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 ) )
@@ -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 ) )
@@ -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 );
}
@@ -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 );
}
@@ -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 ) )
{
@@ -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;

@@ -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 )
@@ -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 )
@@ -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;
@@ -70,7 +70,7 @@ void QgsAtlasComposition::removeLayers( QStringList layers )
return;
}

foreach ( QString layerId, layers )
foreach ( const QString& layerId, layers )
{
if ( layerId == mCoverageLayer->id() )
{
@@ -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 )
@@ -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 ) );
}
@@ -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 ) );
}
@@ -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 ) )
{
@@ -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( " " );
@@ -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 );
@@ -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();

0 comments on commit 73ffb83

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