Skip to content

Commit

Permalink
Fix some Clazy detaching container warnings
Browse files Browse the repository at this point in the history
(not all are valid, but at worst this flips some more
Q_FOREACH uses to c++11 for loops)
  • Loading branch information
nyalldawson committed Aug 29, 2017
1 parent 82a772f commit be5d297
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/app/dwg/qgsdwgimportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void QgsDwgImportDialog::on_buttonBox_accepted()
QgsLayerTreeGroup *dwgGroup = QgisApp::instance()->layerTreeView()->layerTreeModel()->rootGroup()->addGroup( leLayerGroup->text() );
Q_ASSERT( dwgGroup );

Q_FOREACH ( QString layer, layers.keys() )
Q_FOREACH ( const QString &layer, layers.keys() )
{
createGroup( dwgGroup, layer, QStringList( layer ), layers[layer] );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/dwg/qgsdwgimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ bool QgsDwgImporter::expandInserts( QString &error )
QTransform t;
t.translate( p.x(), p.y() ).scale( xscale, yscale ).rotateRadians( angle );

Q_FOREACH ( QString name, QStringList() << "hatches" << "lines" << "polylines" << "texts" << "points" )
Q_FOREACH ( const QString &name, QStringList() << "hatches" << "lines" << "polylines" << "texts" << "points" )
{
OGRLayerH src = OGR_DS_ExecuteSQL( mDs, QString( "SELECT * FROM %1 WHERE block=%2" ).arg( name ).arg( handle ).toUtf8().constData(), nullptr, nullptr );
if ( !src )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgscrashreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const QString QgsCrashReport::toHtml() const
}

QString report;
Q_FOREACH ( QString line, reportData )
Q_FOREACH ( const QString &line, reportData )
{
report += line + "<br>";
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsjoindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void QgsJoinDialog::joinedLayerChanged( QgsMapLayer *layer )

mUseJoinFieldsSubset->setChecked( false );
QStandardItemModel *subsetModel = new QStandardItemModel( this );
Q_FOREACH ( const QgsField &field, vLayer->fields() )
const QgsFields layerFields = vLayer->fields();
for ( const QgsField &field : layerFields )
{
QStandardItem *subsetItem = new QStandardItem( field.name() );
subsetItem->setCheckable( true );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaplayerstyleguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QList<QAction *> QgsMapLayerStyleGuiUtils::actionsUseStyle( QgsMapLayer *layer,
bool onlyOneStyle = mgr->styles().count() == 1;

QList<QAction *> actions;
Q_FOREACH ( QString name, mgr->styles() )
Q_FOREACH ( const QString &name, mgr->styles() )
{
bool active = name == mgr->currentStyle();
QAction *actionUse = new QAction( name, parent );
Expand Down
7 changes: 4 additions & 3 deletions src/core/composer/qgscomposerattributetablev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ void QgsComposerAttributeTableV2::resetColumns()

//rebuild columns list from vector layer fields
int idx = 0;
Q_FOREACH ( const QgsField &field, source->fields() )
const QgsFields sourceFields = source->fields();
for ( const auto &field : sourceFields )
{
QString currentAlias = source->attributeDisplayName( idx );
QgsComposerTableColumn *col = new QgsComposerTableColumn;
Expand Down Expand Up @@ -319,7 +320,7 @@ void QgsComposerAttributeTableV2::setDisplayedFields( const QStringList &fields,
qDeleteAll( mColumns );
mColumns.clear();

QgsFields layerFields = source->fields();
const QgsFields layerFields = source->fields();

if ( !fields.isEmpty() )
{
Expand All @@ -340,7 +341,7 @@ void QgsComposerAttributeTableV2::setDisplayedFields( const QStringList &fields,
{
//resetting, so add all attributes to columns
int idx = 0;
Q_FOREACH ( const QgsField &field, layerFields )
for ( const QgsField &field : layerFields )
{
QString currentAlias = source->attributeDisplayName( idx );
QgsComposerTableColumn *col = new QgsComposerTableColumn;
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/memory/qgsmemoryproviderutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ QgsVectorLayer *QgsMemoryProviderUtils::createMemoryLayer( const QString &name,
{
parts << QStringLiteral( "crs=" ) + crs.authid();
}
Q_FOREACH ( const QgsField &field, fields )
for ( const auto &field : fields )
{
parts << QStringLiteral( "field=%1:%2" ).arg( field.name(), memoryLayerFieldType( field.type() ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsattributetableconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void QgsAttributeTableConfig::update( const QgsFields &fields )
}
}

Q_FOREACH ( const QgsField &field, fields )
for ( const auto &field : fields )
{
if ( !columns.contains( field.name() ) )
{
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,10 +1135,8 @@ void QgsZipItem::init()
// keys << "ogr" << "gdal";
keys << QStringLiteral( "gdal" ) << QStringLiteral( "ogr" );

QStringList::const_iterator i;
for ( i = keys.begin(); i != keys.end(); ++i )
for ( const auto &k : qgsAsConst( keys ) )
{
QString k( *i );
QgsDebugMsgLevel( "provider " + k, 3 );
// some providers hangs with empty uri (PostGIS) etc...
// -> using libraries directly
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
{
QString currentTypename( QString::fromUtf8( pszLocalName, localNameLen ) );
QMap< QString, LayerProperties >::const_iterator iter = mMapTypeNameToProperties.constFind( currentTypename );
if ( iter != mMapTypeNameToProperties.end() )
if ( iter != mMapTypeNameToProperties.constEnd() )
{
mFeatureTupleDepth = mParseDepth;
mCurrentTypename = currentTypename;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsjsonutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
QgsFeatureIterator it = childLayer->getFeatures( req );
QVector<QVariant> attributeWidgetCaches;
int fieldIndex = 0;
Q_FOREACH ( const QgsField &field, childLayer->fields() )
for ( const auto &field : childLayer->fields() )
{
QgsEditorWidgetSetup setup = field.editorWidgetSetup();
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsofflineediting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
// create table
QString sql = QStringLiteral( "CREATE TABLE '%1' (" ).arg( tableName );
QString delim = QLatin1String( "" );
Q_FOREACH ( const QgsField &field, layer->dataProvider()->fields() )
const QgsFields providerFields = layer->dataProvider()->fields();
for ( const auto &field : providerFields )
{
QString dataType = QLatin1String( "" );
QVariant::Type type = field.type();
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgsprojectproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ QgsProjectProperty::QgsProjectProperty() //NOLINT

void QgsProjectPropertyValue::dump( int tabs ) const
{
Q_UNUSED( tabs );
#ifdef QGISDEBUG

QString tabString;
tabString.fill( '\t', tabs );

if ( QVariant::StringList == mValue.type() )
{
QStringList sl = mValue.toStringList();
const QStringList sl = mValue.toStringList();

for ( QStringList::const_iterator i = sl.begin(); i != sl.end(); ++i )
for ( const auto &string : sl )
{
QgsDebugMsg( QString( "%1[%2] " ).arg( tabString, *i ) );
QgsDebugMsg( QString( "%1[%2] " ).arg( tabString, string ) );
}
}
else
{
QgsDebugMsg( QString( "%1%2" ).arg( tabString, mValue.toString() ) );
}
#endif
}

bool QgsProjectPropertyValue::readXml( const QDomNode &keyNode )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ QgsVectorLayer *QgsVectorLayer::clone() const
layer->setDefaultValueExpression( i, defaultValueExpression( i ) );

QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> constraints = fieldConstraintsAndStrength( i );
for ( QgsFieldConstraints::Constraint c : constraints.keys() )
Q_FOREACH ( QgsFieldConstraints::Constraint c, constraints.keys() )
{
layer->setFieldConstraint( i, c, constraints.value( c ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
{
if ( provider->doesStrictFeatureTypeCheck() )
{
for ( QgsFeature f : mAddedFeatures )
for ( const auto &f : qgsAsConst( mAddedFeatures ) )
{
if ( ( ! f.hasGeometry() ) ||
( f.geometry().wkbType() == provider->wkbType() ) )
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ bool QgsVectorLayerJoinBuffer::addFeatures( QgsFeatureList &features, QgsFeature
}
else
{
Q_FOREACH ( const QgsField &field, joinFeature.fields() )
const QgsFields joinFields = joinFeature.fields();
for ( const auto &field : joinFields )
{
QVariant newValue = joinFeature.attribute( field.name() );
int fieldIndex = joinLayer->fields().indexOf( field.name() );
Expand All @@ -576,7 +577,8 @@ bool QgsVectorLayerJoinBuffer::addFeatures( QgsFeatureList &features, QgsFeature
{
// joined feature is added only if one of its field is not null
bool notNullFields = false;
Q_FOREACH ( const QgsField &field, joinFeature.fields() )
const QgsFields joinFields = joinFeature.fields();
for ( const auto &field : joinFields )
{
if ( field.name() == info.joinFieldName() )
continue;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayerjoininfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ QgsFeature QgsVectorLayerJoinInfo::extractJoinedFeature( const QgsFeature &featu
joinFeature.setFields( joinLayer()->fields() );
joinFeature.setAttribute( joinFieldName(), idFieldValue );

Q_FOREACH ( const QgsField &field, joinFeature.fields() )
const QgsFields joinFields = joinFeature.fields();
for ( const auto &field : joinFields )
{
const QString prefixedName = prefixedFieldName( field );

Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvirtuallayerdefinitionutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinitionUtils::fromJoinedLayer( QgsVe
def.setUid( uid );
}
}
Q_FOREACH ( const QgsField &f, layer->dataProvider()->fields() )
const QgsFields providerFields = layer->dataProvider()->fields();
for ( const auto &f : providerFields )
{
columns << "t." + f.name();
}
Expand All @@ -72,7 +73,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinitionUtils::fromJoinedLayer( QgsVe
}
else
{
Q_FOREACH ( const QgsField &f, joinedLayer->fields() )
const QgsFields joinFields = joinedLayer->fields();
for ( const QgsField &f : joinFields )
{
if ( f.name() == join.joinFieldName() )
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsziputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )

if ( rc == ZIP_ER_OK && z != NULL )
{
Q_FOREACH ( QString file, files )
for ( const auto &file : files )
{
QFileInfo fileInfo( file );
if ( !fileInfo.exists() )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,8 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
}
else
{
Q_FOREACH ( const QgsField &field, joinFeature.fields() )
const QgsFields joinFields = joinFeature.fields();
for ( const QgsField &field : joinFields )
{
QString prefixedName = info->prefixedFieldName( field );
QVariant val;
Expand Down
7 changes: 5 additions & 2 deletions src/gui/qgsfilewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ QString QgsFileWidget::filePath()
QStringList QgsFileWidget::splitFilePaths( const QString &path )
{
QStringList paths;
for ( auto pathsPart : path.split( QRegExp( "\"\\s+\"" ), QString::SkipEmptyParts ) )
const QStringList pathParts = path.split( QRegExp( "\"\\s+\"" ), QString::SkipEmptyParts );
for ( const auto &pathsPart : pathParts )
{
paths.append( pathsPart.remove( QRegExp( "(^\\s*\")|(\"\\s*)" ) ) );
QString cleaned = pathsPart;
cleaned.remove( QRegExp( "(^\\s*\")|(\"\\s*)" ) );
paths.append( cleaned );
}
return paths;
}
Expand Down
7 changes: 4 additions & 3 deletions src/gui/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,12 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
}

// list of feature stores for a single sublayer
QgsFeatureStoreList featureStoreList = values.value( i ).value<QgsFeatureStoreList>();
const QgsFeatureStoreList featureStoreList = values.value( i ).value<QgsFeatureStoreList>();

Q_FOREACH ( QgsFeatureStore featureStore, featureStoreList )
for ( const QgsFeatureStore &featureStore : featureStoreList )
{
Q_FOREACH ( QgsFeature feature, featureStore.features() )
const QgsFeatureList storeFeatures = featureStore.features();
for ( QgsFeature feature : storeFeatures )
{
attributes.clear();
// WMS sublayer and feature type, a sublayer may contain multiple feature types.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsoptionsdialogbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void QgsOptionsDialogBase::searchText( const QString &text )
mOptListWidget->setRowHidden( r, !text.isEmpty() );
}

for ( QPair< QgsSearchHighlightOptionWidget *, int > rsw : mRegisteredSearchWidgets )
for ( const QPair< QgsSearchHighlightOptionWidget *, int > &rsw : qgsAsConst( mRegisteredSearchWidgets ) )
{
rsw.first->reset();
if ( !text.isEmpty() && rsw.first->searchHighlight( text ) )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology/qgspointdisplacementrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVecto
//insert attributes into combo box
if ( layer )
{
Q_FOREACH ( const QgsField &f, layer->fields() )
const QgsFields layerFields = layer->fields();
for ( const QgsField &f : layerFields )
{
mLabelFieldComboBox->addItem( f.name() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ void QgsGrass::createTable( dbDriver *driver, const QString &tableName, const Qg
}

QStringList fieldsStringList;
Q_FOREACH ( const QgsField &field, fields )
for ( const QgsField &field : fields )
{
QString name = field.name().toLower().replace( QLatin1String( " " ), QLatin1String( "_" ) );
if ( name.at( 0 ).isDigit() )
Expand Down
8 changes: 4 additions & 4 deletions src/providers/grass/qgsgrassvectormaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ void QgsGrassVectorMapLayer::close()
}
}

QStringList QgsGrassVectorMapLayer::fieldNames( QgsFields &fields )
QStringList QgsGrassVectorMapLayer::fieldNames( const QgsFields &fields )
{
QStringList list;
Q_FOREACH ( const QgsField &field, fields )
for ( const QgsField &field : fields )
{
list << field.name();
}
Expand Down Expand Up @@ -598,7 +598,7 @@ void QgsGrassVectorMapLayer::createTable( const QgsFields &fields, QString &erro

QgsFields catFields;
catFields.append( QgsField( mFieldInfo->key, QVariant::Int, QStringLiteral( "integer" ) ) );
Q_FOREACH ( const QgsField &field, fields )
for ( const QgsField &field : fields )
{
catFields.append( field );
}
Expand Down Expand Up @@ -643,7 +643,7 @@ void QgsGrassVectorMapLayer::createTable( const QgsFields &fields, QString &erro

if ( mFieldInfo )
{
Q_FOREACH ( const QgsField &field, fields )
for ( const QgsField &field : fields )
{
mTableFields.append( field );
mAttributeFields.append( field );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassvectormaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GRASS_LIB_EXPORT QgsGrassVectorMapLayer : public QObject
* This fields are used by layers which are not editied to reflect current state of editing. */
QgsFields &tableFields() { return mTableFields; }

static QStringList fieldNames( QgsFields &fields );
static QStringList fieldNames( const QgsFields &fields );

QMap<int, QList<QVariant> > &attributes() { return mAttributes; }

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ bool QgsWFSSharedData::createCache()
{
mCacheTablename = QStringLiteral( "features" );
sql = QStringLiteral( "CREATE TABLE %1 (%2 INTEGER PRIMARY KEY" ).arg( mCacheTablename, fidName );
Q_FOREACH ( const QgsField &field, cacheFields )
for ( const QgsField &field : qgsAsConst( cacheFields ) )
{
QString type( QStringLiteral( "VARCHAR" ) );
if ( field.type() == QVariant::Int )
Expand Down

0 comments on commit be5d297

Please sign in to comment.