Skip to content

Commit

Permalink
More clazy recommended optimisations:
Browse files Browse the repository at this point in the history
- 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 9319176
Show file tree
Hide file tree
Showing 47 changed files with 164 additions and 163 deletions.
4 changes: 2 additions & 2 deletions src/app/qgssettingstree.cpp
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
18 changes: 9 additions & 9 deletions src/core/geometry/qgswkbtypes.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsattributeaction.cpp
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsdataitem.cpp
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsexpression.cpp
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgslabelingenginev2.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsrelation.h
Expand Up @@ -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; }
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/gui/auth/qgsauthsslimportdialog.cpp
Expand Up @@ -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() );
}
Expand Down
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
Expand Up @@ -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 )
{
Expand Down
Expand Up @@ -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;
Expand All @@ -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 )
{
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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 )
Expand Down Expand Up @@ -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 ) )
Expand Down
Expand Up @@ -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 ) );
}
Expand Down
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 ) )
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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 )
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 9319176

Please sign in to comment.