Skip to content
Permalink
Browse files

More clazy recommended optimisations:

- Use constFind instead of find where applicable
- Use midRef instead of mid
- const ref when using Q_FOREACH
- foreach->Q_FOREACH
  • Loading branch information
nyalldawson committed Oct 19, 2015
1 parent b526161 commit 9319176a7c2a97924eb7ee144dff49ad2874d2ee
Showing with 164 additions and 163 deletions.
  1. +2 −2 src/app/qgssettingstree.cpp
  2. +9 −9 src/core/geometry/qgswkbtypes.cpp
  3. +3 −3 src/core/qgsattributeaction.cpp
  4. +3 −2 src/core/qgsdataitem.cpp
  5. +3 −3 src/core/qgsexpression.cpp
  6. +2 −2 src/core/qgslabelingenginev2.cpp
  7. +2 −2 src/core/qgsrelation.h
  8. +1 −1 src/gui/auth/qgsauthsslimportdialog.cpp
  9. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
  10. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
  11. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
  12. +2 −2 src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
  13. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
  14. +3 −3 src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
  15. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.h
  16. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
  17. +3 −3 src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
  18. +1 −1 src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
  19. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
  20. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
  21. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
  22. +3 −3 src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
  23. +1 −1 src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
  24. +10 −10 src/plugins/geometry_checker/qgsgeometrychecker.cpp
  25. +5 −5 src/plugins/geometry_checker/ui/qgsgeometrycheckerfixsummarydialog.cpp
  26. +9 −9 src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp
  27. +6 −6 src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp
  28. +1 −1 src/plugins/geometry_checker/ui/qgsgeometrycheckfixdialog.cpp
  29. +3 −3 src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
  30. +3 −3 src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp
  31. +3 −3 src/plugins/geometry_snapper/qgssnapindex.cpp
  32. +2 −2 src/plugins/grass/qgsgrasseditrenderer.cpp
  33. +4 −4 src/plugins/grass/qgsgrassmodule.cpp
  34. +15 −15 src/plugins/grass/qgsgrassmoduleinput.cpp
  35. +3 −3 src/plugins/grass/qgsgrassmoduleoptions.cpp
  36. +2 −2 src/plugins/grass/qgsgrassmoduleparam.cpp
  37. +2 −2 src/plugins/grass/qgsgrassplugin.cpp
  38. +1 −1 src/plugins/grass/qgsgrasstools.cpp
  39. +11 −11 src/providers/grass/qgis.v.in.cpp
  40. +2 −2 src/providers/grass/qgsgrass.cpp
  41. +1 −1 src/providers/grass/qgsgrassfeatureiterator.cpp
  42. +1 −1 src/providers/grass/qgsgrassimport.cpp
  43. +10 −10 src/providers/grass/qgsgrassprovidermodule.cpp
  44. +2 −2 src/providers/grass/qgsgrassrasterprovider.cpp
  45. +8 −8 src/providers/grass/qgsgrassvector.cpp
  46. +4 −4 src/providers/grass/qgsgrassvectormap.cpp
  47. +7 −7 tests/src/providers/grass/testqgsgrassprovider.cpp
@@ -185,7 +185,7 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent )
{
int dividerIndex = 0;

foreach ( QString group, settings->childGroups() )
Q_FOREACH ( const QString& group, settings->childGroups() )
{
QTreeWidgetItem *child;
int childIndex = findChild( parent, group, dividerIndex );
@@ -209,7 +209,7 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent )
settings->endGroup();
}

foreach ( QString key, settings->childKeys() )
Q_FOREACH ( const QString& key, settings->childKeys() )
{
QTreeWidgetItem *child;
int childIndex = findChild( parent, key, 0 );
@@ -25,7 +25,7 @@ QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry>* QgsWKBTypes::entries()

QgsWKBTypes::Type QgsWKBTypes::singleType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
@@ -35,7 +35,7 @@ QgsWKBTypes::Type QgsWKBTypes::singleType( Type type )

QgsWKBTypes::Type QgsWKBTypes::multiType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
@@ -45,7 +45,7 @@ QgsWKBTypes::Type QgsWKBTypes::multiType( Type type )

QgsWKBTypes::Type QgsWKBTypes::flatType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
@@ -58,7 +58,7 @@ QgsWKBTypes::Type QgsWKBTypes::parseType( const QString &wktStr )
QString typestr = wktStr.left( wktStr.indexOf( '(' ) ).simplified().replace( " ", "" );
Q_FOREACH ( const Type& type, entries()->keys() )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it != entries()->constEnd() && it.value().mName.compare( typestr, Qt::CaseInsensitive ) == 0 )
{
return type;
@@ -74,7 +74,7 @@ bool QgsWKBTypes::isSingleType( Type type )

bool QgsWKBTypes::isMultiType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return Unknown;
@@ -98,7 +98,7 @@ int QgsWKBTypes::wkbDimensions( Type type )

QgsWKBTypes::GeometryType QgsWKBTypes::geometryType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return UnknownGeometry;
@@ -108,7 +108,7 @@ QgsWKBTypes::GeometryType QgsWKBTypes::geometryType( Type type )

QString QgsWKBTypes::displayString( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return QString::null;
@@ -118,7 +118,7 @@ QString QgsWKBTypes::displayString( Type type )

bool QgsWKBTypes::hasZ( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return false;
@@ -128,7 +128,7 @@ bool QgsWKBTypes::hasZ( Type type )

bool QgsWKBTypes::hasM( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
if ( it == entries()->constEnd() )
{
return false;
@@ -224,7 +224,7 @@ QString QgsAttributeAction::expandAction( const QString& action, QgsFeature &fea
if ( exp.hasParserError() )
{
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
expr_action += action.mid( start, index - start );
expr_action += action.midRef( start, index - start );
continue;
}

@@ -235,15 +235,15 @@ QString QgsAttributeAction::expandAction( const QString& action, QgsFeature &fea
if ( exp.hasEvalError() )
{
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
expr_action += action.mid( start, index - start );
expr_action += action.midRef( start, index - start );
continue;
}

QgsDebugMsg( "Expression result is: " + result.toString() );
expr_action += action.mid( start, pos - start ) + result.toString();
}

expr_action += action.mid( index );
expr_action += action.midRef( index );
return expr_action;
}

@@ -1420,10 +1420,11 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, const QString& fileP
QString vsiPath = vsiPrefix + filePath;
if ( zipItem )
{
if ( zipItem->children().size() == 1 )
QVector<QgsDataItem*> children = zipItem->children();
if ( children.size() == 1 )
{
// take the name of the only child so we can get a normal data item from it
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( zipItem->children().first() );
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( children.first() );
if ( layerItem )
vsiPath = layerItem->uri();
}
@@ -2680,7 +2680,7 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasParserError() )
{
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
expr_action += action.mid( start, index - start );
expr_action += action.midRef( start, index - start );
continue;
}

@@ -2695,15 +2695,15 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasEvalError() )
{
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
expr_action += action.mid( start, index - start );
expr_action += action.midRef( start, index - start );
continue;
}

QgsDebugMsg( "Expression result is: " + result.toString() );
expr_action += action.mid( start, pos - start ) + result.toString();
}

expr_action += action.mid( index );
expr_action += action.midRef( index );

// restore overwritten local values
Q_NOWARN_DEPRECATED_PUSH
@@ -132,7 +132,7 @@ void QgsLabelingEngineV2::processProvider( QgsAbstractLabelProvider* provider, Q

QList<QgsLabelFeature*> features = provider->labelFeatures( context );

foreach ( QgsLabelFeature* feature, features )
Q_FOREACH ( QgsLabelFeature* feature, features )
{
try
{
@@ -180,7 +180,7 @@ void QgsLabelingEngineV2::run( QgsRenderContext& context )


// for each provider: get labels and register them in PAL
foreach ( QgsAbstractLabelProvider* provider, mProviders )
Q_FOREACH ( QgsAbstractLabelProvider* provider, mProviders )
{
processProvider( provider, context, p );
}
@@ -47,9 +47,9 @@ class CORE_EXPORT QgsRelation
: QPair< QString, QString >( referencingField, referencedField ) {}

//! Get the name of the referencing field
const QString& referencingField() const { return first; }
QString referencingField() const { return first; }
//! Get the name of the referenced field
const QString& referencedField() const { return second; }
QString referencedField() const { return second; }
};

/**
@@ -319,7 +319,7 @@ void QgsAuthSslImportDialog::sslErrors( const QList<QSslError> &errors )
connect( ui.certificateChainButton, SIGNAL( clicked() ),
this, SLOT( showCertificateInfo() ) );

foreach ( const QSslError &error, errors )
Q_FOREACH ( const QSslError &error, errors )
{
ui.sslErrorList->addItem( error.errorString() );
}
@@ -11,7 +11,7 @@
void QgsGeometryAngleCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -13,7 +13,7 @@
void QgsGeometryAreaCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -121,7 +121,7 @@ bool QgsGeometryAreaCheck::mergeWithNeighbor( QgsFeature& feature, int partIdx,
QgsAbstractGeometryV2* geom = feature.geometry()->geometry();

// Search for touching neighboring geometries
foreach ( const QgsFeatureId& testId, mFeaturePool->getIntersects( feature.geometry()->boundingBox() ) )
Q_FOREACH ( const QgsFeatureId& testId, mFeaturePool->getIntersects( feature.geometry()->boundingBox() ) )
{
QgsFeature testFeature;
if ( !mFeaturePool->get( testId, testFeature ) )
@@ -81,7 +81,7 @@ bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes& chan
return false;
}

foreach ( const QgsGeometryCheck::Change& change, changes.value( featureId() ) )
Q_FOREACH ( const QgsGeometryCheck::Change& change, changes.value( featureId() ) )
{
if ( change.what == QgsGeometryCheck::ChangeFeature )
{
@@ -12,7 +12,7 @@
void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &messages, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -24,7 +24,7 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError*>& er
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
foreach ( const QgsFeatureId& otherid, ids )
Q_FOREACH ( const QgsFeatureId& otherid, ids )
{
if ( otherid == featureid )
{
@@ -11,7 +11,7 @@
void QgsGeometryDegeneratePolygonCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -14,7 +14,7 @@
void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &messages, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -26,7 +26,7 @@ void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError*>& er

QList<QgsFeatureId> duplicates;
QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->geometry()->boundingBox() );
foreach ( const QgsFeatureId& id, ids )
Q_FOREACH ( const QgsFeatureId& id, ids )
{
// > : only report overlaps once
if ( id >= featureid )
@@ -77,7 +77,7 @@ void QgsGeometryDuplicateCheck::fixError( QgsGeometryCheckError* error, int meth
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( feature.geometry()->geometry(), QgsGeometryCheckPrecision::tolerance() );

QgsGeometryDuplicateCheckError* duplicateError = static_cast<QgsGeometryDuplicateCheckError*>( error );
foreach ( const QgsFeatureId& id, duplicateError->duplicates() )
Q_FOREACH ( const QgsFeatureId& id, duplicateError->duplicates() )
{
QgsFeature testFeature;
if ( !mFeaturePool->get( id, testFeature ) )
@@ -34,7 +34,7 @@ class QgsGeometryDuplicateCheckError : public QgsGeometryCheckError
static inline QString duplicatesString( const QList<QgsFeatureId>& duplicates )
{
QStringList str;
foreach ( QgsFeatureId id, duplicates )
Q_FOREACH ( QgsFeatureId id, duplicates )
{
str.append( QString::number( id ) );
}
@@ -12,7 +12,7 @@
void QgsGeometryDuplicateNodesCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -19,7 +19,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
// Collect geometries, build spatial index
QList<const QgsAbstractGeometryV2*> geomList;
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& id, featureIds )
Q_FOREACH ( const QgsFeatureId& id, featureIds )
{
QgsFeature feature;
if ( mFeaturePool->get( id, feature ) )
@@ -97,7 +97,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors,
QgsRectangle gapAreaBBox = geom->boundingBox();
QgsFeatureIds intersectIds = mFeaturePool->getIntersects( geom->boundingBox() );

foreach ( QgsFeatureId id, intersectIds )
Q_FOREACH ( QgsFeatureId id, intersectIds )
{
QgsFeature feature;
if ( !mFeaturePool->get( id, feature ) )
@@ -159,7 +159,7 @@ bool QgsGeometryGapCheck::mergeWithNeighbor( QgsGeometryGapCheckError* err, Chan
QgsAbstractGeometryV2* errGeometry = QgsGeomUtils::getGeomPart( err->geometry(), 0 );

// Search for touching neighboring geometries
foreach ( const QgsFeatureId& testId, err->neighbors() )
Q_FOREACH ( const QgsFeatureId& testId, err->neighbors() )
{
QgsFeature testFeature;
if ( !mFeaturePool->get( testId, testFeature ) )
@@ -11,7 +11,7 @@
void QgsGeometryHoleCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -11,7 +11,7 @@
void QgsGeometryMultipartCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -12,7 +12,7 @@
void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &messages, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;
@@ -24,7 +24,7 @@ void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError*>& erro
QgsGeometryEngine* geomEngine = QgsGeomUtils::createGeomEngine( geom, QgsGeometryCheckPrecision::tolerance() );

QgsFeatureIds ids = mFeaturePool->getIntersects( feature.geometry()->boundingBox() );
foreach ( const QgsFeatureId& otherid, ids )
Q_FOREACH ( const QgsFeatureId& otherid, ids )
{
// >= : only report overlaps once
if ( otherid >= featureid )
@@ -14,7 +14,7 @@
void QgsGeometrySegmentLengthCheck::collectErrors( QList<QgsGeometryCheckError*>& errors, QStringList &/*messages*/, QAtomicInt* progressCounter , const QgsFeatureIds &ids ) const
{
const QgsFeatureIds& featureIds = ids.isEmpty() ? mFeaturePool->getFeatureIds() : ids;
foreach ( const QgsFeatureId& featureid, featureIds )
Q_FOREACH ( const QgsFeatureId& featureid, featureIds )
{
if ( progressCounter ) progressCounter->fetchAndAddRelaxed( 1 );
QgsFeature feature;

0 comments on commit 9319176

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