Fix clazy container detach warnings

This commit is contained in:
Nyall Dawson 2018-02-02 12:55:30 +10:00
parent 7400b465ba
commit 2dbda4f66b
22 changed files with 72 additions and 59 deletions

View File

@ -99,7 +99,7 @@ QgsFeature QgsAddIncrementalFieldAlgorithm::processFeature( const QgsFeature &fe
{
if ( !mGroupedFieldNames.empty() && mGroupedFields.empty() )
{
for ( const QString &field : mGroupedFieldNames )
for ( const QString &field : qgis::as_const( mGroupedFieldNames ) )
{
int idx = mFields.lookupField( field );
if ( idx >= 0 )

View File

@ -114,7 +114,8 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( const QString &layerId, QgsFeature
const QgsAbstractGeometry *geom = featureGeometry.constGet();
// Search for touching neighboring geometries
for ( QgsFeatureId testId : featurePool->getIntersects( featureGeometry.boundingBox() ) )
const QgsFeatureIds intersects = featurePool->getIntersects( featureGeometry.boundingBox() );
for ( QgsFeatureId testId : intersects )
{
QgsFeature testFeature;
if ( !featurePool->get( testId, testFeature ) )

View File

@ -134,7 +134,8 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
void setFixed( int method )
{
mStatus = StatusFixed;
mResolutionMessage = mCheck->getResolutionMethods()[method];
const QStringList methods = mCheck->getResolutionMethods();
mResolutionMessage = methods[method];
}
void setFixFailed( const QString &reason )
{

View File

@ -29,13 +29,13 @@ QgsGeometryChecker::QgsGeometryChecker( const QList<QgsGeometryCheck *> &checks,
: mChecks( checks )
, mContext( context )
{
for ( const QgsFeaturePool *featurePool : mContext->featurePools.values() )
for ( auto it = mContext->featurePools.constBegin(); it != mContext->featurePools.constEnd(); ++it )
{
if ( featurePool->getLayer() )
if ( it.value()->getLayer() )
{
featurePool->getLayer()->setReadOnly( true );
it.value()->getLayer()->setReadOnly( true );
// Enter update mode to defer ogr dataset repacking until the checker has finished
featurePool->getLayer()->dataProvider()->enterUpdateMode();
it.value()->getLayer()->dataProvider()->enterUpdateMode();
}
}
}
@ -44,14 +44,14 @@ QgsGeometryChecker::~QgsGeometryChecker()
{
qDeleteAll( mCheckErrors );
qDeleteAll( mChecks );
for ( const QgsFeaturePool *featurePool : mContext->featurePools.values() )
for ( auto it = mContext->featurePools.constBegin(); it != mContext->featurePools.constEnd(); ++it )
{
if ( featurePool->getLayer() )
if ( it.value()->getLayer() )
{
featurePool->getLayer()->dataProvider()->leaveUpdateMode();
featurePool->getLayer()->setReadOnly( false );
it.value()->getLayer()->dataProvider()->leaveUpdateMode();
it.value()->getLayer()->setReadOnly( false );
}
delete featurePool;
delete it.value();
}
delete mContext;
}
@ -61,13 +61,13 @@ QFuture<void> QgsGeometryChecker::execute( int *totalSteps )
if ( totalSteps )
{
*totalSteps = 0;
for ( QgsGeometryCheck *check : mChecks )
for ( QgsGeometryCheck *check : qgis::as_const( mChecks ) )
{
for ( const QgsFeaturePool *featurePool : mContext->featurePools.values() )
for ( auto it = mContext->featurePools.constBegin(); it != mContext->featurePools.constEnd(); ++it )
{
if ( check->getCheckType() <= QgsGeometryCheck::FeatureCheck )
{
*totalSteps += check->getCompatibility( featurePool->getLayer()->geometryType() ) ? featurePool->getFeatureIds().size() : 0;
*totalSteps += check->getCompatibility( it.value()->getLayer()->geometryType() ) ? it.value()->getFeatureIds().size() : 0;
}
else
{
@ -140,15 +140,15 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
// Determine what to recheck
// - Collect all features which were changed, get affected area
QMap<QString, QSet<QgsFeatureId>> recheckFeatures;
for ( const QString &layerId : changes.keys() )
for ( auto it = changes.constBegin(); it != changes.constEnd(); ++it )
{
const QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>> &layerChanges = changes[layerId];
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
const QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>> &layerChanges = it.value();
QgsFeaturePool *featurePool = mContext->featurePools[it.key()];
QgsCoordinateTransform t( featurePool->getLayer()->crs(), mContext->mapCrs, QgsProject::instance() );
for ( QgsFeatureId id : layerChanges.keys() )
for ( auto layerChangeIt = layerChanges.constBegin(); layerChangeIt != layerChanges.constEnd(); ++layerChangeIt )
{
bool removed = false;
for ( const QgsGeometryCheck::Change &change : layerChanges.value( id ) )
for ( const QgsGeometryCheck::Change &change : layerChangeIt.value() )
{
if ( change.what == QgsGeometryCheck::ChangeFeature && change.type == QgsGeometryCheck::ChangeRemoved )
{
@ -159,16 +159,16 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
if ( !removed )
{
QgsFeature f;
if ( featurePool->get( id, f ) )
if ( featurePool->get( layerChangeIt.key(), f ) )
{
recheckFeatures[layerId].insert( id );
recheckFeatures[it.key()].insert( layerChangeIt.key() );
recheckArea.combineExtentWith( t.transformBoundingBox( f.geometry().boundingBox() ) );
}
}
}
}
// - Determine extent to recheck for gaps
for ( QgsGeometryCheckError *err : mCheckErrors )
for ( QgsGeometryCheckError *err : qgis::as_const( mCheckErrors ) )
{
if ( err->check()->getCheckType() == QgsGeometryCheck::LayerCheck )
{
@ -189,7 +189,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
// Recheck feature / changed area to detect new errors
QList<QgsGeometryCheckError *> recheckErrors;
for ( const QgsGeometryCheck *check : mChecks )
for ( const QgsGeometryCheck *check : qgis::as_const( mChecks ) )
{
if ( check->getCheckType() == QgsGeometryCheck::LayerCheck )
{
@ -208,7 +208,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
}
// Go through error list, update other errors of the checked feature
for ( QgsGeometryCheckError *err : mCheckErrors )
for ( QgsGeometryCheckError *err : qgis::as_const( mCheckErrors ) )
{
if ( err == error || err->status() == QgsGeometryCheckError::StatusObsolete )
{
@ -222,7 +222,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
// Check if this error now matches one found when rechecking the feature/area
QgsGeometryCheckError *matchErr = nullptr;
int nMatch = 0;
for ( QgsGeometryCheckError *recheckErr : recheckErrors )
for ( QgsGeometryCheckError *recheckErr : qgis::as_const( recheckErrors ) )
{
if ( recheckErr->isEqual( err ) || recheckErr->closeMatch( err ) )
{
@ -258,7 +258,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
}
// Add new errors
for ( QgsGeometryCheckError *recheckErr : recheckErrors )
for ( QgsGeometryCheckError *recheckErr : qgis::as_const( recheckErrors ) )
{
emit errorAdded( recheckErr );
mCheckErrors.append( recheckErr );
@ -285,7 +285,7 @@ void QgsGeometryChecker::runCheck( const QgsGeometryCheck *check )
mCheckErrors.append( errors );
mMessages.append( messages );
mErrorListMutex.unlock();
for ( QgsGeometryCheckError *error : errors )
for ( QgsGeometryCheckError *error : qgis::as_const( errors ) )
{
emit errorAdded( error );
}

View File

@ -22,11 +22,11 @@
QString QgsGeometryDuplicateCheckError::duplicatesString( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QList<QgsFeatureId>> &duplicates )
{
QStringList str;
for ( const QString &layerId : duplicates.keys() )
for ( auto it = duplicates.constBegin(); it != duplicates.constEnd(); ++it )
{
str.append( featurePools[layerId]->getLayer()->name() + ":" );
str.append( featurePools[it.key()]->getLayer()->name() + ":" );
QStringList ids;
for ( QgsFeatureId id : duplicates[layerId] )
for ( QgsFeatureId id : it.value() )
{
ids.append( QString::number( id ) );
}

View File

@ -59,7 +59,8 @@ void QgsGeometryLineIntersectionCheck::collectErrors( QList<QgsGeometryCheckErro
{
continue;
}
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeatureA, inter, QgsVertexId( iPart ), layerFeatureB.id() ) );
}

View File

@ -45,16 +45,19 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( QList<QgsGeometryChec
const QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart );
if ( const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( part ) )
{
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
}
}
else if ( const QgsPolygon *polygon = dynamic_cast<const QgsPolygon *>( part ) )
{
for ( const QgsLineString *ring : QgsGeometryCheckerUtils::polygonRings( polygon ) )
QList< const QgsLineString* > rings = QgsGeometryCheckerUtils::polygonRings( polygon );
for ( const QgsLineString *ring : rings )
{
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance ) )
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
}

View File

@ -81,7 +81,8 @@ QList<QgsMapLayer *> QgsLayerTree::layerOrder() const
else
{
QList<QgsMapLayer *> layers;
for ( const auto &treeLayer : findLayers() )
const QList< QgsLayerTreeLayer * > foundLayers = findLayers();
for ( const auto &treeLayer : foundLayers )
{
QgsMapLayer *layer = treeLayer->layer();
if ( !layer || !layer->isSpatial() )
@ -212,7 +213,8 @@ void QgsLayerTree::addMissingLayers()
{
bool changed = false;
for ( const auto layer : findLayers() )
const QList< QgsLayerTreeLayer * > foundLayers = findLayers();
for ( const auto layer : foundLayers )
{
if ( !mCustomLayerOrder.contains( layer->layer() ) &&
layer->layer() && layer->layer()->isSpatial() )

View File

@ -303,7 +303,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
if ( !layer->abstract().isEmpty() )
{
parts << QStringLiteral();
for ( const auto &l : layer->abstract().split( "\n" ) )
const QStringList abstractLines = layer->abstract().split( "\n" );
for ( const auto &l : abstractLines )
{
parts << l.toHtmlEscaped();
}

View File

@ -333,7 +333,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToImage( const QString
}
else
{
for ( int page : settings.pages )
for ( int page : qgis::as_const( settings.pages ) )
{
if ( page >= 0 && page < mLayout->pageCollection()->pageCount() )
pages << page;

View File

@ -75,7 +75,7 @@ void QgsLayoutItemGroupUndoCommand::switchState()
mLayout->addLayoutItemPrivate( group );
}
for ( const QString &childUuid : mItemUuids )
for ( const QString &childUuid : qgis::as_const( mItemUuids ) )
{
QgsLayoutItem *childItem = mLayout->itemByUuid( childUuid );
group->addItem( childItem );

View File

@ -201,7 +201,7 @@ bool QgsLayoutItemMapItemStack::writeXml( QDomElement &elem, QDomDocument &doc,
void QgsLayoutItemMapItemStack::finalizeRestoreFromXml()
{
for ( QgsLayoutItemMapItem *item : mItems )
for ( QgsLayoutItemMapItem *item : qgis::as_const( mItems ) )
{
item->finalizeRestoreFromXml();
}

View File

@ -141,7 +141,8 @@ QString QgsProjectArchive::auxiliaryStorageFile() const
{
const QString extension = QgsAuxiliaryStorage::extension();
for ( const QString &file : files() )
const QStringList fileList = files();
for ( const QString &file : fileList )
{
const QFileInfo fileInfo( file );
if ( fileInfo.suffix().compare( extension, Qt::CaseInsensitive ) == 0 )

View File

@ -232,7 +232,8 @@ int QgsAuxiliaryLayer::createProperty( QgsPalLayerSettings::Property property, Q
{
const QgsProperty prop = QgsProperty::fromField( fieldName );
for ( const QString &providerId : layer->labeling()->subProviders() )
const QStringList subProviderIds = layer->labeling()->subProviders();
for ( const QString &providerId : subProviderIds )
{
QgsPalLayerSettings *settings = new QgsPalLayerSettings( layer->labeling()->settings( providerId ) );

View File

@ -2295,7 +2295,7 @@ QList<QgsMapLayer *> QgsProject::addMapLayers(
bool addToLegend,
bool takeOwnership )
{
QList<QgsMapLayer *> myResultList = mLayerStore->addMapLayers( layers, takeOwnership );
const QList<QgsMapLayer *> myResultList = mLayerStore->addMapLayers( layers, takeOwnership );
if ( !myResultList.isEmpty() )
{
if ( addToLegend )

View File

@ -182,7 +182,7 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::findRuleByKey( const QSt
if ( key == mRuleKey )
return this;
for ( Rule *rule : mChildren )
for ( Rule *rule : qgis::as_const( mChildren ) )
{
Rule *r = rule->findRuleByKey( key );
if ( r )

View File

@ -362,7 +362,8 @@ QgsFeature QgsVectorLayerUtils::duplicateFeature( QgsVectorLayer *layer, const Q
//set childlayer editable
relation.referencingLayer()->startEditing();
//change the fk of the child to the id of the new parent
for ( const QgsRelation::FieldPair &fieldPair : relation.fieldPairs() )
const auto pairs = relation.fieldPairs();
for ( const QgsRelation::FieldPair &fieldPair : pairs )
{
childFeature.setAttribute( fieldPair.first, newFeature.attribute( fieldPair.second ) );
}

View File

@ -137,7 +137,8 @@ void QgsAuthSslErrorsDialog::showCertificateChainInfo()
void QgsAuthSslErrorsDialog::showCertificateChainCAsInfo()
{
for ( const auto &cert : mSslConfiguration.caCertificates() )
const QList< QSslCertificate > certificates = mSslConfiguration.caCertificates();
for ( const auto &cert : certificates )
{
qDebug() << cert.subjectInfo( QSslCertificate::SubjectInfo::CommonName );
}

View File

@ -442,7 +442,7 @@ void QgsRelationReferenceWidget::init()
if ( !mFilterFields.isEmpty() )
{
for ( const QString &fieldName : mFilterFields )
for ( const QString &fieldName : qgis::as_const( mFilterFields ) )
{
int idx = mReferencedLayer->fields().lookupField( fieldName );

View File

@ -272,7 +272,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::PointGeometry && QgsWkbTypes::isMultiType( geomType ) )
{
const QgsMultiPointXY mpt = geom.asMultiPoint();
for ( QgsPointXY pt : mpt )
for ( const QgsPointXY &pt : mpt )
{
addPoint( pt, false, idx );
removeLastPoint( idx, false );
@ -282,7 +282,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
else if ( QgsWkbTypes::geometryType( geomType ) == QgsWkbTypes::LineGeometry && !QgsWkbTypes::isMultiType( geomType ) )
{
const QgsPolylineXY line = geom.asPolyline();
for ( QgsPointXY pt : line )
for ( const QgsPointXY &pt : line )
{
addPoint( pt, false, idx );
}
@ -296,7 +296,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
{
continue;
}
for ( QgsPointXY pt : line )
for ( const QgsPointXY &pt : line )
{
addPoint( pt, false, idx );
}
@ -307,7 +307,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
{
const QgsPolygonXY poly = geom.asPolygon();
const QgsPolylineXY line = poly.at( 0 );
for ( QgsPointXY pt : line )
for ( const QgsPointXY &pt : line )
{
addPoint( pt, false, idx );
}
@ -321,7 +321,7 @@ void QgsRubberBand::addGeometry( const QgsGeometry &geometry, const QgsCoordinat
continue;
const QgsPolylineXY line = poly.at( 0 );
for ( QgsPointXY pt : line )
for ( const QgsPointXY &pt : line )
{
addPoint( pt, false, idx );
}

View File

@ -461,7 +461,7 @@ void QgsGeometryCheckerResultTab::fixErrors( bool prompt )
rows = ui.tableWidgetErrors->selectionModel()->selectedRows();
}
QList<QgsGeometryCheckError *> errors;
for ( const QModelIndex &index : rows )
for ( const QModelIndex &index : qgis::as_const( rows ) )
{
QgsGeometryCheckError *error = ui.tableWidgetErrors->item( index.row(), 0 )->data( Qt::UserRole ).value<QgsGeometryCheckError *>();
if ( error->status() < QgsGeometryCheckError::StatusFixed )
@ -507,7 +507,7 @@ void QgsGeometryCheckerResultTab::fixErrors( bool prompt )
ui.progressBarFixErrors->setVisible( true );
ui.progressBarFixErrors->setRange( 0, errors.size() );
for ( QgsGeometryCheckError *error : errors )
for ( QgsGeometryCheckError *error : qgis::as_const( errors ) )
{
int fixMethod = QgsSettings().value( sSettingsGroup + error->check()->errorName(), QVariant::fromValue<int>( 0 ) ).toInt();
mChecker->fixError( error, fixMethod );

View File

@ -369,7 +369,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
// Check if output layers are editable
QList<QgsVectorLayer *> nonEditableLayers;
for ( QgsVectorLayer *layer : processLayers )
for ( QgsVectorLayer *layer : qgis::as_const( processLayers ) )
{
if ( ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeGeometries ) == 0 )
{
@ -387,7 +387,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
{
if ( ui.radioButtonOutputNew->isChecked() )
{
for ( QgsVectorLayer *layer : processLayers )
for ( QgsVectorLayer *layer : qgis::as_const( processLayers ) )
{
QString layerPath = layer->dataProvider()->dataSourceUri();
delete layer;
@ -412,7 +412,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
ui.labelStatus->setText( tr( "<b>Building spatial index...</b>" ) );
QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
QMap<QString, QgsFeaturePool *> featurePools;
for ( QgsVectorLayer *layer : processLayers )
for ( QgsVectorLayer *layer : qgis::as_const( processLayers ) )
{
double layerToMapUntis = mIface->mapCanvas()->mapSettings().layerToMapUnits( layer );
QgsCoordinateTransform layerToMapTransform( layer->crs(), QgsProject::instance()->crs(), QgsProject::instance() );
@ -446,7 +446,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
if ( ui.radioButtonOutputNew->isChecked() )
{
QList<QgsMapLayer *> addLayers;
for ( QgsVectorLayer *layer : processLayers )
for ( QgsVectorLayer *layer : qgis::as_const( processLayers ) )
{
addLayers.append( layer );
}