Skip to content
Permalink
Browse files

Fix clazy allocating unneeded temporary container warnings

  • Loading branch information
nyalldawson committed Sep 25, 2017
1 parent fd9bcd6 commit e8b90c33e46b528d88f22e686d362ed2e5f85f4c
@@ -11795,9 +11795,10 @@ void QgisApp::onTaskCompleteShowNotify( long taskId, int status )

void QgisApp::onTransactionGroupsChanged()
{
Q_FOREACH ( QgsTransactionGroup *tg, QgsProject::instance()->transactionGroups().values() )
const auto groups = QgsProject::instance()->transactionGroups();
for ( auto it = groups.constBegin(); it != groups.constEnd(); ++it )
{
connect( tg, &QgsTransactionGroup::commitError, this, &QgisApp::transactionGroupCommitError, Qt::UniqueConnection );
connect( it.value(), &QgsTransactionGroup::commitError, this, &QgisApp::transactionGroupCommitError, Qt::UniqueConnection );
}
}

@@ -232,9 +232,9 @@ void QgsSnappingLayerTreeModel::onSnappingSettingsChanged()
{
const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> oldSettings = mIndividualLayerSettings;

Q_FOREACH ( QgsVectorLayer *vl, oldSettings.keys() )
for ( auto it = oldSettings.constBegin(); it != oldSettings.constEnd(); ++it )
{
if ( !mProject->snappingConfig().individualLayerSettings().contains( vl ) )
if ( !mProject->snappingConfig().individualLayerSettings().contains( it.key() ) )
{
beginResetModel();
mIndividualLayerSettings = mProject->snappingConfig().individualLayerSettings();
@@ -606,12 +606,9 @@ QString QgsDataSourceUri::uri( bool expandAuthConfig ) const
QByteArray QgsDataSourceUri::encodedUri() const
{
QUrl url;
Q_FOREACH ( const QString &key, mParams.uniqueKeys() )
for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
{
Q_FOREACH ( const QString &value, mParams.values( key ) )
{
url.addQueryItem( key, value );
}
url.addQueryItem( it.key(), it.value() );
}
return url.encodedQuery();
}
@@ -52,9 +52,10 @@ void QgsMapLayerModel::setItemsCheckable( bool checkable )

void QgsMapLayerModel::checkAll( Qt::CheckState checkState )
{
Q_FOREACH ( const QString &key, mLayersChecked.keys() )
QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
for ( ; i != mLayersChecked.end(); ++i )
{
mLayersChecked[key] = checkState;
*i = checkState;
}
emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
}
@@ -1932,9 +1932,11 @@ bool QgsProject::evaluateDefaultValues() const

void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues )
{
Q_FOREACH ( QgsMapLayer *layer, mapLayers().values() )
const QMap<QString, QgsMapLayer *> layers = mapLayers();
QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
for ( ; layerIt != layers.constEnd(); ++layerIt )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerIt.value() );
if ( vl )
{
vl->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues );
@@ -2284,9 +2286,10 @@ void QgsProject::setTrustLayerMetadata( bool trust )
{
mTrustLayerMetadata = trust;

Q_FOREACH ( QgsMapLayer *layer, mapLayers().values() )
auto layers = mapLayers();
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
if ( vl )
{
vl->setReadExtentFromXml( trust );
@@ -354,12 +354,13 @@ void QgsSnappingConfig::writeProject( QDomDocument &doc )
snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );

QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
Q_FOREACH ( QgsVectorLayer *vl, mIndividualLayerSettings.keys() )
QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
for ( ; layerIt != mIndividualLayerSettings.constEnd(); ++layerIt )
{
IndividualLayerSettings setting = mIndividualLayerSettings.value( vl );
const IndividualLayerSettings &setting = layerIt.value();

QDomElement layerElement = doc.createElement( QStringLiteral( "layer-setting" ) );
layerElement.setAttribute( QStringLiteral( "id" ), vl->id() );
layerElement.setAttribute( QStringLiteral( "id" ), layerIt.key()->id() );
layerElement.setAttribute( QStringLiteral( "enabled" ), QString::number( setting.enabled() ) );
layerElement.setAttribute( QStringLiteral( "type" ), ( int )setting.type() );
layerElement.setAttribute( QStringLiteral( "tolerance" ), setting.tolerance() );
@@ -256,9 +256,10 @@ QgsVectorLayer *QgsVectorLayer::clone() const
layer->setDefaultValueExpression( i, defaultValueExpression( i ) );

QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> constraints = fieldConstraintsAndStrength( i );
Q_FOREACH ( QgsFieldConstraints::Constraint c, constraints.keys() )
auto constraintIt = constraints.constBegin();
for ( ; constraintIt != constraints.constEnd(); ++ constraintIt )
{
layer->setFieldConstraint( i, c, constraints.value( c ) );
layer->setFieldConstraint( i, constraintIt.key(), constraintIt.value() );
}

if ( fields().fieldOrigin( i ) == QgsFields::OriginExpression )
@@ -316,9 +316,9 @@ void QgsExpressionBuilderWidget::loadFieldNames( const QgsFields &fields )
void QgsExpressionBuilderWidget::loadFieldsAndValues( const QMap<QString, QStringList> &fieldValues )
{
QgsFields fields;
Q_FOREACH ( const QString &fieldName, fieldValues.keys() )
for ( auto it = fieldValues.constBegin(); it != fieldValues.constEnd(); ++it )
{
fields.append( QgsField( fieldName ) );
fields.append( QgsField( it.key() ) );
}
loadFieldNames( fields );
mFieldValues = fieldValues;
@@ -559,16 +559,16 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
QgsGeometry geometry;
if ( format == QgsRaster::IdentifyFormatValue )
{
Q_FOREACH ( int bandNo, values.keys() )
for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
{
QString valueString;
if ( values.value( bandNo ).isNull() )
if ( it.value().isNull() )
{
valueString = tr( "no data" );
}
else
{
QVariant value( values.value( bandNo ) );
QVariant value( it.value() );
// The cast is legit. Quoting QT doc :
// "Although this function is declared as returning QVariant::Type,
// the return value should be interpreted as QMetaType::Type"
@@ -581,16 +581,16 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
valueString = QgsRasterBlock::printValue( value.toDouble() );
}
}
attributes.insert( dprovider->generateBandName( bandNo ), valueString );
attributes.insert( dprovider->generateBandName( it.key() ), valueString );
}
QString label = layer->name();
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
}
else if ( format == QgsRaster::IdentifyFormatFeature )
{
Q_FOREACH ( int i, values.keys() )
for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
{
QVariant value = values.value( i );
QVariant value = it.value();
if ( value.type() == QVariant::Bool && !value.toBool() )
{
// sublayer not visible or not queryable
@@ -601,7 +601,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
{
// error
// TODO: better error reporting
QString label = layer->subLayers().value( i );
QString label = layer->subLayers().value( it.key() );
attributes.clear();
attributes.insert( tr( "Error" ), value.toString() );

@@ -610,7 +610,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
}

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

for ( const QgsFeatureStore &featureStore : featureStoreList )
{
@@ -649,13 +649,13 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
else // text or html
{
QgsDebugMsg( QString( "%1 HTML or text values" ).arg( values.size() ) );
Q_FOREACH ( int bandNo, values.keys() )
for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
{
QString value = values.value( bandNo ).toString();
QString value = it.value().toString();
attributes.clear();
attributes.insert( QLatin1String( "" ), value );

QString label = layer->subLayers().value( bandNo );
QString label = layer->subLayers().value( it.key() );
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
}
}
@@ -89,8 +89,8 @@ void QgsRasterPyramidsOptionsWidget::updateUi()
}
else
{
Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
mOverviewCheckBoxes[ i ]->setChecked( false );
for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
it.value()->setChecked( false );
}
tmpStr = mySettings.value( prefix + "overviewList", "" ).toString();
Q_FOREACH ( const QString &lev, tmpStr.split( ' ', QString::SkipEmptyParts ) )
@@ -134,10 +134,10 @@ void QgsRasterPyramidsOptionsWidget::apply()

// overview list
tmpStr = QLatin1String( "" );
Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
{
if ( mOverviewCheckBoxes[ i ]->isChecked() )
tmpStr += QString::number( i ) + ' ';
if ( it.value()->isChecked() )
tmpStr += QString::number( it.key() ) + ' ';
}
mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() );

@@ -146,16 +146,16 @@ void QgsRasterPyramidsOptionsWidget::apply()

void QgsRasterPyramidsOptionsWidget::checkAllLevels( bool checked )
{
Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
mOverviewCheckBoxes[ i ]->setChecked( checked );
for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
it.value()->setChecked( checked );
}

void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled )
{
// if toggled, disable checkboxes and enable line edit
lePyramidsLevels->setEnabled( toggled );
Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
mOverviewCheckBoxes[ i ]->setEnabled( ! toggled );
for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
it.value()->setEnabled( ! toggled );
setOverviewList();
}

@@ -205,10 +205,10 @@ void QgsRasterPyramidsOptionsWidget::setOverviewList()
}
else
{
Q_FOREACH ( int i, mOverviewCheckBoxes.keys() )
for ( auto it = mOverviewCheckBoxes.constBegin(); it != mOverviewCheckBoxes.constEnd(); ++it )
{
if ( mOverviewCheckBoxes[ i ]->isChecked() )
mOverviewList << i;
if ( it.value()->isChecked() )
mOverviewList << it.key();
}
}

@@ -207,9 +207,10 @@ void QgsRelationEditorWidget::setRelations( const QgsRelation &relation, const Q

mToggleEditingButton->setVisible( true );

Q_FOREACH ( QgsTransactionGroup *tg, QgsProject::instance()->transactionGroups().values() )
const auto transactionGroups = QgsProject::instance()->transactionGroups();
for ( auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
{
if ( tg->layers().contains( mRelation.referencingLayer() ) )
if ( it.value()->layers().contains( mRelation.referencingLayer() ) )
{
mToggleEditingButton->setVisible( false );
mSaveEditsButton->setVisible( false );
@@ -863,10 +863,11 @@ QVariant QgsRuleBasedRendererModel::data( const QModelIndex &index, int role ) c
if ( mFeatureCountMap[rule].duplicateCount > 0 )
{
QString tip = QStringLiteral( "<p style='margin:0px;'><ul>" );
Q_FOREACH ( QgsRuleBasedRenderer::Rule *duplicateRule, mFeatureCountMap[rule].duplicateCountMap.keys() )
const auto duplicateMap = mFeatureCountMap[rule].duplicateCountMap;
for ( auto it = duplicateMap.constBegin(); it != duplicateMap.constEnd(); ++it )
{
QString label = duplicateRule->label().replace( '&', QLatin1String( "&amp;" ) ).replace( '>', QLatin1String( "&gt;" ) ).replace( '<', QLatin1String( "&lt;" ) );
tip += tr( "<li><nobr>%1 features also in rule %2</nobr></li>" ).arg( mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).arg( label );
QString label = it.key()->label().replace( '&', QLatin1String( "&amp;" ) ).replace( '>', QLatin1String( "&gt;" ) ).replace( '<', QLatin1String( "&lt;" ) );
tip += tr( "<li><nobr>%1 features also in rule %2</nobr></li>" ).arg( it.value() ).arg( label );
}
tip += QLatin1String( "</ul>" );
return tip;
@@ -33,7 +33,7 @@ struct QgsRuleBasedRendererCount SIP_SKIP
int count; // number of features
int duplicateCount; // number of features present also in other rule(s)
// map of feature counts in other rules
QMap<QgsRuleBasedRenderer::Rule *, int> duplicateCountMap;
QHash<QgsRuleBasedRenderer::Rule *, int> duplicateCountMap;
};

/** \ingroup gui
@@ -156,11 +156,8 @@ void QgsSmartGroupEditorDialog::setConditionMap( const QgsSmartConditionMap &map
constraints << QStringLiteral( "tag" ) << QStringLiteral( "name" ) << QStringLiteral( "!tag" ) << QStringLiteral( "!name" );

// clear any defaults
Q_FOREACH ( int id, mConditionMap.keys() )
{
QgsSmartGroupCondition *cond = mConditionMap.take( id );
delete cond;
}
qDeleteAll( mConditionMap );
mConditionMap.clear();

//set the constraints
Q_FOREACH ( const QString &constr, constraints )
@@ -221,16 +221,16 @@ static inline QString dumpVariantMap( const QVariantMap &variantMap, const QStri
{
result += QStringLiteral( "<tr><td class=\"glossy\" colspan=\"2\">%1</td></tr>" ).arg( title );
}
foreach ( const QString &key, variantMap.keys() )
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
{
QVariantMap childMap = variantMap[key].toMap();
QVariantMap childMap = it.value().toMap();
if ( childMap.isEmpty() )
{
result += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key, variantMap[key].toString() );
result += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( it.key(), it.value().toString() );
}
else
{
result += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key, dumpVariantMap( childMap ) );
result += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( it.key(), dumpVariantMap( childMap ) );
}
}
result += QLatin1String( "</table>" );
@@ -399,12 +399,12 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
{
foreach ( const QVariant &result, queryResults )
{
QVariantMap resultMap = result.toMap();
const QVariantMap resultMap = result.toMap();
QVariantMap attributesMap = resultMap[QStringLiteral( "attributes" )].toMap();
QString valueStr;
foreach ( const QString &attribute, attributesMap.keys() )
for ( auto it = attributesMap.constBegin(); it != attributesMap.constEnd(); ++it )
{
valueStr += QStringLiteral( "%1 = %2\n" ).arg( attribute, attributesMap[attribute].toString() );
valueStr += QStringLiteral( "%1 = %2\n" ).arg( it.key(), it.value().toString() );
}
entries.insert( entries.size(), valueStr );
}
@@ -413,15 +413,15 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
{
foreach ( const QVariant &result, queryResults )
{
QVariantMap resultMap = result.toMap();
const QVariantMap resultMap = result.toMap();

QgsFields fields;
QVariantMap attributesMap = resultMap[QStringLiteral( "attributes" )].toMap();
const QVariantMap attributesMap = resultMap[QStringLiteral( "attributes" )].toMap();
QgsAttributes featureAttributes;
foreach ( const QString &attribute, attributesMap.keys() )
for ( auto it = attributesMap.constBegin(); it != attributesMap.constEnd(); ++it )
{
fields.append( QgsField( attribute, QVariant::String, QStringLiteral( "string" ) ) );
featureAttributes.append( attributesMap[attribute].toString() );
fields.append( QgsField( it.key(), QVariant::String, QStringLiteral( "string" ) ) );
featureAttributes.append( it.value().toString() );
}
QgsCoordinateReferenceSystem crs;
QgsAbstractGeometry *geometry = QgsArcGisRestUtils::parseEsriGeoJSON( resultMap[QStringLiteral( "geometry" )].toMap(), resultMap[QStringLiteral( "geometryType" )].toString(), false, false, &crs );
@@ -444,14 +444,14 @@ int main( int argc, char **argv )

int centroidsCount = centroids.size();
count = 0;
Q_FOREACH ( const QgsFeature &centroid, centroids.values() )
for ( auto it = centroids.constBegin(); it != centroids.constEnd(); ++it )
{
QgsPointXY point = centroid.geometry().asPoint();
QgsPointXY point = it.value().geometry().asPoint();

if ( centroid.attributes().size() > 0 )
if ( it.value().attributes().size() > 0 )
{
Vect_reset_cats( cats );
Q_FOREACH ( const QVariant &attribute, centroid.attributes() )
Q_FOREACH ( const QVariant &attribute, it.value().attributes() )
{
Vect_cat_set( cats, 1, attribute.toInt() );
}

0 comments on commit e8b90c3

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