Skip to content

Commit

Permalink
Move qgsAsConst to qgis::as_const
Browse files Browse the repository at this point in the history
So it's more inline with the std::as_const implementation which
it fills in for, and allows us to 'polyfill' other c++>11
features into the qgis:: namespace.
  • Loading branch information
nyalldawson committed Oct 13, 2017
1 parent 1852d2b commit 24a9c52
Show file tree
Hide file tree
Showing 47 changed files with 150 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutappmenuprovider.cpp
Expand Up @@ -55,7 +55,7 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
bool foundSelectedGroup = false;
QList< QgsLayoutItemGroup * > groups;
layout->layoutItems( groups );
for ( QgsLayoutItemGroup *group : qgsAsConst( groups ) )
for ( QgsLayoutItemGroup *group : qgis::as_const( groups ) )
{
if ( group->isSelected() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -1166,7 +1166,7 @@ int main( int argc, char *argv[] )
/////////////////////////////////////////////////////////////////////
// autoload any file names that were passed in on the command line
/////////////////////////////////////////////////////////////////////
for ( const QString &layerName : qgsAsConst( sFileList ) )
for ( const QString &layerName : qgis::as_const( sFileList ) )
{
QgsDebugMsg( QString( "Trying to load file : %1" ).arg( layerName ) );
// don't load anything with a .qgs extension - these are project files
Expand Down
32 changes: 16 additions & 16 deletions src/app/nodetool/qgsnodetool.cpp
Expand Up @@ -332,11 +332,11 @@ void QgsNodeTool::clearDragBands()
mDragPointMarkers.clear();
mDragPointMarkersOffset.clear();

for ( const StraightBand &b : qgsAsConst( mDragStraightBands ) )
for ( const StraightBand &b : qgis::as_const( mDragStraightBands ) )
delete b.band;
mDragStraightBands.clear();

for ( const CircularBand &b : qgsAsConst( mDragCircularBands ) )
for ( const CircularBand &b : qgis::as_const( mDragCircularBands ) )
delete b.band;
mDragCircularBands.clear();
}
Expand All @@ -352,7 +352,7 @@ void QgsNodeTool::cadCanvasPressEvent( QgsMapMouseEvent *e )
QgsPointLocator::Match m = snapToEditableLayer( e );
if ( m.hasVertex() )
{
for ( const Vertex &selectedNode : qgsAsConst( mSelectedNodes ) )
for ( const Vertex &selectedNode : qgis::as_const( mSelectedNodes ) )
{
if ( selectedNode.layer == m.layer() && selectedNode.fid == m.featureId() && selectedNode.vertexId == m.vertexIndex() )
{
Expand Down Expand Up @@ -783,7 +783,7 @@ void QgsNodeTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
QgsPointSequence points;
QgsGeometryUtils::segmentizeArc( QgsPoint( pX ), QgsPoint( p0 ), QgsPoint( p1 ), points );
mEdgeBand->reset();
for ( const QgsPoint &pt : qgsAsConst( points ) )
for ( const QgsPoint &pt : qgis::as_const( points ) )
mEdgeBand->addPoint( pt );
}
else if ( isCircularVertex( geom, m.vertexIndex() + 1 ) )
Expand All @@ -794,7 +794,7 @@ void QgsNodeTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
QgsPointSequence points;
QgsGeometryUtils::segmentizeArc( QgsPoint( p0 ), QgsPoint( p1 ), QgsPoint( pX ), points );
mEdgeBand->reset();
for ( const QgsPoint &pt : qgsAsConst( points ) )
for ( const QgsPoint &pt : qgis::as_const( points ) )
mEdgeBand->addPoint( pt );
}
else
Expand Down Expand Up @@ -974,7 +974,7 @@ void QgsNodeTool::deleteNodeEditorSelection()
QgsVectorLayer *layer = mSelectedFeature->vlayer();
QgsFeatureId fid = mSelectedFeature->featureId();
QgsGeometry geometry = cachedGeometry( layer, fid );
for ( QgsVertexEntry *vertex : qgsAsConst( selFeatureVertices ) )
for ( QgsVertexEntry *vertex : qgis::as_const( selFeatureVertices ) )
{
if ( vertex->isSelected() )
{
Expand Down Expand Up @@ -1053,7 +1053,7 @@ void QgsNodeTool::startDraggingMoveVertex( const QgsPointLocator::Match &m )
QgsPointXY origDraggingVertexPoint = geom.vertexAt( mDraggingVertex->vertexId );

// if there are other highlighted nodes, they should be dragged as well with their offset
for ( const Vertex &v : qgsAsConst( mSelectedNodes ) )
for ( const Vertex &v : qgis::as_const( mSelectedNodes ) )
{
if ( v != *mDraggingVertex )
{
Expand Down Expand Up @@ -1100,7 +1100,7 @@ void QgsNodeTool::startDraggingMoveVertex( const QgsPointLocator::Match &m )

QSet<Vertex> movingVertices;
movingVertices << *mDraggingVertex;
for ( const Vertex &v : qgsAsConst( mDraggingExtraVertices ) )
for ( const Vertex &v : qgis::as_const( mDraggingExtraVertices ) )
movingVertices << v;

QgsPointXY dragVertexMapPoint = m.point();
Expand All @@ -1116,7 +1116,7 @@ void QgsNodeTool::buildDragBandsForVertices( const QSet<Vertex> &movingVertices,
// i.e. every circular band is defined by its middle circular vertex
QSet<Vertex> verticesInCircularBands;

for ( const Vertex &v : qgsAsConst( movingVertices ) )
for ( const Vertex &v : qgis::as_const( movingVertices ) )
{
int v0idx, v1idx;
QgsGeometry geom = cachedGeometry( v.layer, v.fid );
Expand Down Expand Up @@ -1328,7 +1328,7 @@ void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsP

QgsPointXY layerPoint = toLayerCoordinates( m.layer(), mapPoint );

for ( const Vertex &v : qgsAsConst( movingVertices ) )
for ( const Vertex &v : qgis::as_const( movingVertices ) )
{
mDraggingExtraVertices << v;
mDraggingExtraVerticesOffset << ( geom.vertexAt( v.vertexId ) - QgsPoint( layerPoint ) );
Expand Down Expand Up @@ -1535,7 +1535,7 @@ void QgsNodeTool::deleteVertex()
{
// if topo editing is enabled, delete all the vertices that are on the same location
QSet<Vertex> topoVerticesToDelete;
for ( const Vertex &vertexToDelete : qgsAsConst( toDelete ) )
for ( const Vertex &vertexToDelete : qgis::as_const( toDelete ) )
{
QgsPointXY layerPt = cachedGeometryForVertex( vertexToDelete ).vertexAt( vertexToDelete.vertexId );
QgsPointXY mapPt = toMapCoordinates( vertexToDelete.layer, layerPt );
Expand All @@ -1555,7 +1555,7 @@ void QgsNodeTool::deleteVertex()

// switch from a plain list to dictionary { layer: { fid: [vertexNr1, vertexNr2, ...] } }
QHash<QgsVectorLayer *, QHash<QgsFeatureId, QList<int> > > toDeleteGrouped;
for ( const Vertex &vertex : qgsAsConst( toDelete ) )
for ( const Vertex &vertex : qgis::as_const( toDelete ) )
{
toDeleteGrouped[vertex.layer][vertex.fid].append( vertex.vertexId );
}
Expand Down Expand Up @@ -1591,7 +1591,7 @@ void QgsNodeTool::deleteVertex()
}
}
// now delete the duplicities
for ( int duplicateVertexIndex : qgsAsConst( duplicateVertexIndices ) )
for ( int duplicateVertexIndex : qgis::as_const( duplicateVertexIndices ) )
vertexIds.removeOne( duplicateVertexIndex );
}
}
Expand Down Expand Up @@ -1670,7 +1670,7 @@ void QgsNodeTool::setHighlightedNodes( QList<Vertex> listNodes )
mSelectedNodesMarkers.clear();
mSelectedNodes.clear();

for ( const Vertex &node : qgsAsConst( listNodes ) )
for ( const Vertex &node : qgis::as_const( listNodes ) )
{
QgsGeometry geom = cachedGeometryForVertex( node );
QgsVertexId vid;
Expand All @@ -1689,7 +1689,7 @@ void QgsNodeTool::setHighlightedNodes( QList<Vertex> listNodes )

void QgsNodeTool::setHighlightedNodesVisible( bool visible )
{
for ( QgsVertexMarker *marker : qgsAsConst( mSelectedNodesMarkers ) )
for ( QgsVertexMarker *marker : qgis::as_const( mSelectedNodesMarkers ) )
marker->setVisible( visible );
}

Expand Down Expand Up @@ -1784,7 +1784,7 @@ void QgsNodeTool::CircularBand::updateRubberBand( const QgsPointXY &mapPoint )
QgsGeometryUtils::segmentizeArc( QgsPoint( v0 ), QgsPoint( v1 ), QgsPoint( v2 ), points );
// it would be useful to have QgsRubberBand::setPoints() call
band->reset();
for ( const QgsPoint &p : qgsAsConst( points ) )
for ( const QgsPoint &p : qgis::as_const( points ) )
band->addPoint( p );
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -1423,7 +1423,7 @@ void QgisApp::dropEvent( QDropEvent *event )
{
freezeCanvases();

for ( const QString &file : qgsAsConst( files ) )
for ( const QString &file : qgis::as_const( files ) )
{
bool handled = false;

Expand Down Expand Up @@ -7926,7 +7926,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )

pasteVectorLayer->addFeatures( newFeatures );
QgsFeatureIds newIds;
for ( const QgsFeature &f : qgsAsConst( newFeatures ) )
for ( const QgsFeature &f : qgis::as_const( newFeatures ) )
{
newIds << f.id();
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoollabel.cpp
Expand Up @@ -732,7 +732,7 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexe
if ( !vlayer->auxiliaryLayer() )
return false;

for ( const QgsPalLayerSettings::Property &p : qgsAsConst( mPalProperties ) )
for ( const QgsPalLayerSettings::Property &p : qgis::as_const( mPalProperties ) )
{
int index = -1;

Expand Down Expand Up @@ -779,7 +779,7 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsDiagramIn
if ( !vlayer->auxiliaryLayer() )
return false;

for ( const QgsDiagramLayerSettings::Property &p : qgsAsConst( mDiagramProperties ) )
for ( const QgsDiagramLayerSettings::Property &p : qgis::as_const( mDiagramProperties ) )
{
int index = -1;

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -142,7 +142,7 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
QList<QgsLabelPosition> positions;
if ( selectedLabelFeatures( vlayer, positions ) )
{
for ( const QgsLabelPosition &pos : qgsAsConst( positions ) )
for ( const QgsLabelPosition &pos : qgis::as_const( positions ) )
{
if ( showHide( pos, false ) )
labelChanged = true;
Expand All @@ -154,7 +154,7 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
QgsFeatureIds fids;
if ( selectedFeatures( vlayer, fids ) )
{
for ( const QgsFeatureId &fid : qgsAsConst( fids ) )
for ( const QgsFeatureId &fid : qgis::as_const( fids ) )
{
QgsLabelPosition pos;
pos.featureId = fid;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -2416,7 +2416,7 @@ void QgsOptions::showHelp()
QString link;

// give first priority to created pages which have specified a help key
for ( const QgsOptionsPageWidget *widget : qgsAsConst( mAdditionalOptionWidgets ) )
for ( const QgsOptionsPageWidget *widget : qgis::as_const( mAdditionalOptionWidgets ) )
{
if ( widget == activeTab )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/annotations/qgsannotationmanager.cpp
Expand Up @@ -62,7 +62,7 @@ bool QgsAnnotationManager::removeAnnotation( QgsAnnotation *annotation )

void QgsAnnotationManager::clear()
{
for ( auto *a : qgsAsConst( mAnnotations ) )
for ( auto *a : qgis::as_const( mAnnotations ) )
{
removeAnnotation( a );
}
Expand All @@ -76,7 +76,7 @@ QList<QgsAnnotation *> QgsAnnotationManager::annotations() const
QList<QgsAnnotation *> QgsAnnotationManager::cloneAnnotations() const
{
QList<QgsAnnotation *> results;
for ( const auto *a : qgsAsConst( mAnnotations ) )
for ( const auto *a : qgis::as_const( mAnnotations ) )
{
results << a->clone();
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -2437,7 +2437,7 @@ const QList<QSslCertificate> QgsAuthManager::getExtraFileCAs()
filecerts = QgsAuthCertUtils::certsFromFile( cafile );
}
// only CAs or certs capable of signing other certs are allowed
for ( const auto &cert : qgsAsConst( filecerts ) )
for ( const auto &cert : qgis::as_const( filecerts ) )
{
if ( !allowinvalid.toBool() && !cert.isValid() )
{
Expand Down Expand Up @@ -3403,7 +3403,7 @@ bool QgsAuthManager::reencryptAllAuthenticationSettings( const QString &prevpass
QStringList encryptedsettings;
encryptedsettings << "";

for ( const auto & sett, qgsAsConst( encryptedsettings ) )
for ( const auto & sett, qgis::as_const( encryptedsettings ) )
{
if ( sett.isEmpty() || !existsAuthSetting( sett ) )
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/core/diagram/qgshistogramdiagram.cpp
Expand Up @@ -49,7 +49,7 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsFeature &feature, const QgsRen
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

for ( const QString &cat : qgsAsConst( s.categoryAttributes ) )
for ( const QString &cat : qgis::as_const( s.categoryAttributes ) )
{
QgsExpression *expression = getExpression( cat, expressionContext );
maxValue = std::max( expression->evaluate( &expressionContext ).toDouble(), maxValue );
Expand Down Expand Up @@ -151,7 +151,7 @@ void QgsHistogramDiagram::renderDiagram( const QgsFeature &feature, QgsRenderCon
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

for ( const QString &cat : qgsAsConst( s.categoryAttributes ) )
for ( const QString &cat : qgis::as_const( s.categoryAttributes ) )
{
QgsExpression *expression = getExpression( cat, expressionContext );
double currentVal = expression->evaluate( &expressionContext ).toDouble();
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -802,7 +802,7 @@ void QgsDxfExport::writeTables()
writeGroup( 6, QStringLiteral( "CONTINUOUS" ) );
writeHandle( 390, DXF_HANDPLOTSTYLE );

for ( const QString &layerName : qgsAsConst( layerNames ) )
for ( const QString &layerName : qgis::as_const( layerNames ) )
{
writeGroup( 0, QStringLiteral( "LAYER" ) );
writeHandle();
Expand Down
8 changes: 4 additions & 4 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -514,7 +514,7 @@ QString QgsExpression::helpText( QString name )
.arg( tr( "%1 %2" ).arg( f.mType, name ),
f.mDescription ) );

for ( const HelpVariant &v : qgsAsConst( f.mVariants ) )
for ( const HelpVariant &v : qgis::as_const( f.mVariants ) )
{
if ( f.mVariants.size() > 1 )
{
Expand Down Expand Up @@ -546,7 +546,7 @@ QString QgsExpression::helpText( QString name )
helpContents += '(';

QString delim;
for ( const HelpArg &a : qgsAsConst( v.mArguments ) )
for ( const HelpArg &a : qgis::as_const( v.mArguments ) )
{
helpContents += delim;
delim = QStringLiteral( ", " );
Expand All @@ -572,7 +572,7 @@ QString QgsExpression::helpText( QString name )
{
helpContents += QStringLiteral( "<h4>%1</h4>\n<div class=\"arguments\">\n<table>" ).arg( tr( "Arguments" ) );

for ( const HelpArg &a : qgsAsConst( v.mArguments ) )
for ( const HelpArg &a : qgis::as_const( v.mArguments ) )
{
if ( a.mSyntaxOnly )
continue;
Expand All @@ -587,7 +587,7 @@ QString QgsExpression::helpText( QString name )
{
helpContents += QStringLiteral( "<h4>%1</h4>\n<div class=\"examples\">\n<ul>\n" ).arg( tr( "Examples" ) );

for ( const HelpExample &e : qgsAsConst( v.mExamples ) )
for ( const HelpExample &e : qgis::as_const( v.mExamples ) )
{
helpContents += "<li><code>" + e.mExpression + "</code> &rarr; <code>" + e.mReturns + "</code>";

Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -2853,7 +2853,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
while ( orderedGeom->partCount() )
orderedGeom->removeGeometry( 0 );

for ( const QgsFeature &feature : qgsAsConst( partFeatures ) )
for ( const QgsFeature &feature : qgis::as_const( partFeatures ) )
{
orderedGeom->addGeometry( feature.geometry().geometry()->clone() );
}
Expand Down Expand Up @@ -4467,7 +4467,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
QgsExpressionContextUtils::registerContextFunctions();

//QgsExpression has ownership of all built-in functions
for ( QgsExpressionFunction *func : qgsAsConst( sFunctions ) )
for ( QgsExpressionFunction *func : qgis::as_const( sFunctions ) )
{
sOwnedFunctions << func;
sBuiltinFunctions << func->name();
Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionnodeimpl.cpp
Expand Up @@ -1256,7 +1256,7 @@ QgsExpressionNode::NodeType QgsExpressionNodeCondition::nodeType() const

QVariant QgsExpressionNodeCondition::evalNode( QgsExpression *parent, const QgsExpressionContext *context )
{
for ( WhenThen *cond : qgsAsConst( mConditions ) )
for ( WhenThen *cond : qgis::as_const( mConditions ) )
{
QVariant vWhen = cond->mWhenExp->eval( parent, context );
QgsExpressionUtils::TVL tvl = QgsExpressionUtils::getTVLValue( vWhen, parent );
Expand All @@ -1283,7 +1283,7 @@ QVariant QgsExpressionNodeCondition::evalNode( QgsExpression *parent, const QgsE
bool QgsExpressionNodeCondition::prepareNode( QgsExpression *parent, const QgsExpressionContext *context )
{
bool res;
for ( WhenThen *cond : qgsAsConst( mConditions ) )
for ( WhenThen *cond : qgis::as_const( mConditions ) )
{
res = cond->mWhenExp->prepare( parent, context )
& cond->mThenExp->prepare( parent, context );
Expand Down
4 changes: 2 additions & 2 deletions src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp
Expand Up @@ -57,7 +57,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer *layer, i
QStringList keyList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );
QStringList valueList;

for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgsAsConst( vrCache ) )
for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgis::as_const( vrCache ) )
{
if ( keyList.contains( item.key.toString() ) )
{
Expand All @@ -74,7 +74,7 @@ QString QgsValueRelationFieldFormatter::representValue( QgsVectorLayer *layer, i
return QgsApplication::nullRepresentation();
}

for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgsAsConst( vrCache ) )
for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgis::as_const( vrCache ) )
{
if ( item.key == value )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/geocms/geonode/qgsgeonoderequest.cpp
Expand Up @@ -284,7 +284,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con

if ( majorVersion == 2 && minorVersion == 6 )
{
for ( const QVariant &layer : qgsAsConst( layerList ) )
for ( const QVariant &layer : qgis::as_const( layerList ) )
{
QgsGeoNodeRequest::ServiceLayerDetail layerStruct;
const QVariantMap layerMap = layer.toMap();
Expand Down Expand Up @@ -323,7 +323,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
// Geonode version 2.7 or newer
else if ( ( majorVersion == 2 && minorVersion >= 7 ) || ( majorVersion >= 3 ) )
{
for ( const QVariant &layer : qgsAsConst( layerList ) )
for ( const QVariant &layer : qgis::as_const( layerList ) )
{
QgsGeoNodeRequest::ServiceLayerDetail layerStruct;
const QVariantMap layerMap = layer.toMap();
Expand Down

0 comments on commit 24a9c52

Please sign in to comment.