Skip to content
Permalink
Browse files

Fix some Clazy detaching container warnings

(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 be5d2979b93ecf5acc923c92816d3e6918747355
@@ -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] );
}
@@ -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 )
@@ -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>";
}
@@ -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 );
@@ -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 );
@@ -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;
@@ -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() )
{
@@ -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;
@@ -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() ) );
}
@@ -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() ) )
{
@@ -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
@@ -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;
@@ -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() );
@@ -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();
@@ -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 )
@@ -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 ) );
}
@@ -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() ) )
@@ -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() );
@@ -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;
@@ -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 );

@@ -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();
}
@@ -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;
@@ -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() )
@@ -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;
@@ -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;
}
@@ -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.
@@ -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 ) )
@@ -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() );
}
@@ -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() )
@@ -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();
}
@@ -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 );
}
@@ -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 );
@@ -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; }

@@ -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 )

0 comments on commit be5d297

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