Skip to content

Commit

Permalink
Rewrite all core header usages of Q_FOREACH
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 26, 2018
1 parent b64a958 commit 2d5ec75
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 69 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsrelation.sip.in
Expand Up @@ -238,7 +238,7 @@ The second element of each pair are the field names of the matching primary key.
%MethodCode %MethodCode
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs(); const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
sipRes = new QMap< QString, QString >(); sipRes = new QMap< QString, QString >();
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs ) for ( const QgsRelation::FieldPair &pair : pairs )
{ {
sipRes->insert( pair.first, pair.second ); sipRes->insert( pair.first, pair.second );
} }
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsexpressionsorter.h
Expand Up @@ -36,7 +36,7 @@ class QgsExpressionSorter
bool operator()( const QgsIndexedFeature &f1, const QgsIndexedFeature &f2 ) const bool operator()( const QgsIndexedFeature &f1, const QgsIndexedFeature &f2 ) const
{ {
int i = 0; int i = 0;
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &orderBy, mPreparedOrderBys ) for ( const QgsFeatureRequest::OrderByClause &orderBy : qgis::as_const( mPreparedOrderBys ) )
{ {
const QVariant &v1 = f1.mIndexes.at( i ); const QVariant &v1 = f1.mIndexes.at( i );
const QVariant &v2 = f2.mIndexes.at( i ); const QVariant &v2 = f2.mIndexes.at( i );
Expand Down Expand Up @@ -143,15 +143,15 @@ class QgsExpressionSorter


QgsIndexedFeature indexedFeature; QgsIndexedFeature indexedFeature;


Q_FOREACH ( const QgsFeature &f, features ) for ( const QgsFeature &f : qgis::as_const( features ) )
{ {
indexedFeature.mIndexes.resize( mPreparedOrderBys.size() ); indexedFeature.mIndexes.resize( mPreparedOrderBys.size() );
indexedFeature.mFeature = f; indexedFeature.mFeature = f;


expressionContext->setFeature( indexedFeature.mFeature ); expressionContext->setFeature( indexedFeature.mFeature );


int i = 0; int i = 0;
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &orderBy, mPreparedOrderBys ) for ( const QgsFeatureRequest::OrderByClause &orderBy : qgis::as_const( mPreparedOrderBys ) )
{ {
indexedFeature.mIndexes.replace( i++, orderBy.expression().evaluate( expressionContext ) ); indexedFeature.mIndexes.replace( i++, orderBy.expression().evaluate( expressionContext ) );
} }
Expand All @@ -164,7 +164,7 @@ class QgsExpressionSorter


features.clear(); features.clear();


Q_FOREACH ( const QgsIndexedFeature &indexedFeature, indexedFeatures ) for ( const QgsIndexedFeature &indexedFeature : qgis::as_const( indexedFeatures ) )
features.append( indexedFeature.mFeature ); features.append( indexedFeature.mFeature );
} }


Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsmaplayerlistutils.h
Expand Up @@ -35,7 +35,7 @@ inline QList<QgsMapLayer *> _qgis_listQPointerToRaw( const QgsWeakMapLayerPointe
{ {
QList<QgsMapLayer *> lst; QList<QgsMapLayer *> lst;
lst.reserve( layers.count() ); lst.reserve( layers.count() );
Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, layers ) for ( const QgsWeakMapLayerPointer &layerPtr : layers )
{ {
if ( layerPtr ) if ( layerPtr )
lst.append( layerPtr.data() ); lst.append( layerPtr.data() );
Expand All @@ -47,7 +47,7 @@ inline QgsWeakMapLayerPointerList _qgis_listRawToQPointer( const QList<QgsMapLay
{ {
QgsWeakMapLayerPointerList lst; QgsWeakMapLayerPointerList lst;
lst.reserve( layers.count() ); lst.reserve( layers.count() );
Q_FOREACH ( QgsMapLayer *layer, layers ) for ( QgsMapLayer *layer : layers )
{ {
lst.append( layer ); lst.append( layer );
} }
Expand All @@ -58,7 +58,7 @@ inline QList<QgsMapLayer *> _qgis_listRefToRaw( const QList< QgsMapLayerRef > &l
{ {
QList<QgsMapLayer *> lst; QList<QgsMapLayer *> lst;
lst.reserve( layers.count() ); lst.reserve( layers.count() );
Q_FOREACH ( const QgsMapLayerRef &layer, layers ) for ( const QgsMapLayerRef &layer : layers )
{ {
if ( layer ) if ( layer )
lst.append( layer.get() ); lst.append( layer.get() );
Expand All @@ -70,7 +70,7 @@ inline QList< QgsMapLayerRef > _qgis_listRawToRef( const QList<QgsMapLayer *> &l
{ {
QList< QgsMapLayerRef > lst; QList< QgsMapLayerRef > lst;
lst.reserve( layers.count() ); lst.reserve( layers.count() );
Q_FOREACH ( QgsMapLayer *layer, layers ) for ( QgsMapLayer *layer : layers )
{ {
lst.append( QgsMapLayerRef( layer ) ); lst.append( QgsMapLayerRef( layer ) );
} }
Expand All @@ -92,7 +92,7 @@ inline QStringList _qgis_listQPointerToIDs( const QgsWeakMapLayerPointerList &la
{ {
QStringList lst; QStringList lst;
lst.reserve( layers.count() ); lst.reserve( layers.count() );
Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, layers ) for ( const QgsWeakMapLayerPointer &layerPtr : layers )
{ {
if ( layerPtr ) if ( layerPtr )
lst << layerPtr->id(); lst << layerPtr->id();
Expand All @@ -107,7 +107,7 @@ inline static QgsMapLayer *_qgis_findLayer( const QList< QgsMapLayer *> &layers,
QgsMapLayer *matchNameInsensitive = nullptr; QgsMapLayer *matchNameInsensitive = nullptr;


// Look for match against layer IDs // Look for match against layer IDs
Q_FOREACH ( QgsMapLayer *layer, layers ) for ( QgsMapLayer *layer : layers )
{ {
if ( !matchId && layer->id() == identifier ) if ( !matchId && layer->id() == identifier )
{ {
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayerref.h
Expand Up @@ -171,7 +171,8 @@ struct _LayerRef


if ( project && !name.isEmpty() ) if ( project && !name.isEmpty() )
{ {
Q_FOREACH ( QgsMapLayer *l, project->mapLayersByName( name ) ) const QList<QgsMapLayer *> layers = project->mapLayersByName( name );
for ( QgsMapLayer *l : layers )
{ {
if ( TYPE *tl = qobject_cast< TYPE *>( l ) ) if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
{ {
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrelation.h
Expand Up @@ -296,7 +296,7 @@ class CORE_EXPORT QgsRelation
% MethodCode % MethodCode
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs(); const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
sipRes = new QMap< QString, QString >(); sipRes = new QMap< QString, QString >();
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs ) for ( const QgsRelation::FieldPair &pair : pairs )
{ {
sipRes->insert( pair.first, pair.second ); sipRes->insert( pair.first, pair.second );
} }
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsrulebasedlabeling.cpp
Expand Up @@ -86,6 +86,17 @@ void QgsRuleBasedLabeling::Rule::setSettings( QgsPalLayerSettings *settings )
mSettings = settings; mSettings = settings;
} }


QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::Rule::descendants() const
{
RuleList l;
for ( Rule *c : mChildren )
{
l += c;
l += c->descendants();
}
return l;
}

void QgsRuleBasedLabeling::Rule::initFilter() void QgsRuleBasedLabeling::Rule::initFilter()
{ {
if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 ) if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrulebasedlabeling.h
Expand Up @@ -203,7 +203,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
* *
* \returns A list of descendant rules * \returns A list of descendant rules
*/ */
QgsRuleBasedLabeling::RuleList descendants() const { RuleList l; Q_FOREACH ( Rule *c, mChildren ) { l += c; l += c->descendants(); } return l; } QgsRuleBasedLabeling::RuleList descendants() const;


/** /**
* The parent rule * The parent rule
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgssqlstatement.cpp
Expand Up @@ -251,6 +251,14 @@ bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
/////////////////////////////////////////////// ///////////////////////////////////////////////
// nodes // nodes


void QgsSQLStatement::NodeList::accept( QgsSQLStatement::Visitor &v ) const
{
for ( QgsSQLStatement::Node *node : mList )
{
node->accept( v );
}
}

QgsSQLStatement::NodeList *QgsSQLStatement::NodeList::clone() const QgsSQLStatement::NodeList *QgsSQLStatement::NodeList::clone() const
{ {
NodeList *nl = new NodeList; NodeList *nl = new NodeList;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgssqlstatement.h
Expand Up @@ -301,7 +301,7 @@ class CORE_EXPORT QgsSQLStatement
int count() const { return mList.count(); } int count() const { return mList.count(); }


//! Accept visitor //! Accept visitor
void accept( QgsSQLStatement::Visitor &v ) const { Q_FOREACH ( QgsSQLStatement::Node *node, mList ) { node->accept( v ); } } void accept( QgsSQLStatement::Visitor &v ) const;


//! Creates a deep copy of this list. Ownership is transferred to the caller //! Creates a deep copy of this list. Ownership is transferred to the caller
QgsSQLStatement::NodeList *clone() const SIP_FACTORY; QgsSQLStatement::NodeList *clone() const SIP_FACTORY;
Expand Down
53 changes: 53 additions & 0 deletions src/core/symbology/qgscolorbrewerpalette.cpp
Expand Up @@ -291,3 +291,56 @@ const char *QgsColorBrewerPalette::BREWER_STRING =
"PuBuGn-7-246,239,247 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n" "PuBuGn-7-246,239,247 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n"
"PuBuGn-8-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n" "PuBuGn-8-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n"
"PuBuGn-9-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,108,89 1,70,54"; "PuBuGn-9-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,108,89 1,70,54";

QList<QColor> QgsColorBrewerPalette::listSchemeColors( const QString &schemeName, int colors )
{
QList<QColor> pal;
QString palette( BREWER_STRING );
const QStringList list = palette.split( QChar( '\n' ) );
for ( const QString &entry : list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
continue;
const QStringList colors = items[2].split( QChar( ' ' ) );
for ( const QString &clr : colors )
{
pal << QgsSymbolLayerUtils::parseColor( clr );
}
}
return pal;
}

QStringList QgsColorBrewerPalette::listSchemes()
{
QStringList schemes;

QString palette( BREWER_STRING );
const QStringList list = palette.split( QChar( '\n' ) );
for ( const QString &entry : list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 )
continue;
if ( !schemes.contains( items[0] ) )
schemes << items[0];
}
return schemes;
}

QList<int> QgsColorBrewerPalette::listSchemeVariants( const QString &schemeName )
{
QList<int> variants;

QString palette( BREWER_STRING );
const QStringList list = palette.split( QChar( '\n' ) );
for ( const QString &entry : list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 || items[0] != schemeName )
continue;
variants << items[1].toInt();
}

return variants;
}
53 changes: 3 additions & 50 deletions src/core/symbology/qgscolorbrewerpalette.h
Expand Up @@ -28,58 +28,11 @@
class CORE_EXPORT QgsColorBrewerPalette class CORE_EXPORT QgsColorBrewerPalette
{ {
public: public:
static QList<QColor> listSchemeColors( const QString &schemeName, int colors ) static QList<QColor> listSchemeColors( const QString &schemeName, int colors );
{
QList<QColor> pal;
QString palette( BREWER_STRING );
QStringList list = palette.split( QChar( '\n' ) );
Q_FOREACH ( const QString &entry, list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
continue;
QStringList colors = items[2].split( QChar( ' ' ) );
Q_FOREACH ( const QString &clr, colors )
{
pal << QgsSymbolLayerUtils::parseColor( clr );
}
}
return pal;
}


static QStringList listSchemes() static QStringList listSchemes();
{
QStringList schemes;


QString palette( BREWER_STRING ); static QList<int> listSchemeVariants( const QString &schemeName );
QStringList list = palette.split( QChar( '\n' ) );
Q_FOREACH ( const QString &entry, list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 )
continue;
if ( !schemes.contains( items[0] ) )
schemes << items[0];
}
return schemes;
}

static QList<int> listSchemeVariants( const QString &schemeName )
{
QList<int> variants;

QString palette( BREWER_STRING );
QStringList list = palette.split( QChar( '\n' ) );
Q_FOREACH ( const QString &entry, list )
{
QStringList items = entry.split( QChar( '-' ) );
if ( items.count() != 3 || items[0] != schemeName )
continue;
variants << items[1].toInt();
}

return variants;
}


// extracted ColorBrewer data // extracted ColorBrewer data
static const char *BREWER_STRING; static const char *BREWER_STRING;
Expand Down
11 changes: 11 additions & 0 deletions src/core/symbology/qgsrulebasedrenderer.cpp
Expand Up @@ -701,6 +701,17 @@ QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::create( QDomElement &rul
return rule; return rule;
} }


QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::descendants() const
{
RuleList l;
for ( QgsRuleBasedRenderer::Rule *c : mChildren )
{
l += c;
l += c->descendants();
}
return l;
}

QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::createFromSld( QDomElement &ruleElem, QgsWkbTypes::GeometryType geomType ) QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::createFromSld( QDomElement &ruleElem, QgsWkbTypes::GeometryType geomType )
{ {
if ( ruleElem.localName() != QLatin1String( "Rule" ) ) if ( ruleElem.localName() != QLatin1String( "Rule" ) )
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology/qgsrulebasedrenderer.h
Expand Up @@ -84,7 +84,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
struct RenderLevel struct RenderLevel
{ {
explicit RenderLevel( int z ): zIndex( z ) {} explicit RenderLevel( int z ): zIndex( z ) {}
~RenderLevel() { Q_FOREACH ( RenderJob *j, jobs ) delete j; } ~RenderLevel() { qDeleteAll( jobs ); }
int zIndex; int zIndex;


//! List of jobs to render, owned by this object. //! List of jobs to render, owned by this object.
Expand All @@ -95,7 +95,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
zIndex = rh.zIndex; zIndex = rh.zIndex;
qDeleteAll( jobs ); qDeleteAll( jobs );
jobs.clear(); jobs.clear();
Q_FOREACH ( RenderJob *job, rh.jobs ) for ( RenderJob *job : qgis::as_const( rh.jobs ) )
{ {
jobs << new RenderJob( *job ); jobs << new RenderJob( *job );
} }
Expand All @@ -105,7 +105,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
RenderLevel( const QgsRuleBasedRenderer::RenderLevel &other ) RenderLevel( const QgsRuleBasedRenderer::RenderLevel &other )
: zIndex( other.zIndex ) : zIndex( other.zIndex )
{ {
Q_FOREACH ( RenderJob *job, other.jobs ) for ( RenderJob *job : qgis::as_const( other.jobs ) )
{ {
jobs << new RenderJob( *job ); jobs << new RenderJob( *job );
} }
Expand Down Expand Up @@ -381,7 +381,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
* *
* \returns A list of descendant rules * \returns A list of descendant rules
*/ */
QgsRuleBasedRenderer::RuleList descendants() const { RuleList l; Q_FOREACH ( QgsRuleBasedRenderer::Rule *c, mChildren ) { l += c; l += c->descendants(); } return l; } QgsRuleBasedRenderer::RuleList descendants() const;


/** /**
* The parent rule * The parent rule
Expand Down

0 comments on commit 2d5ec75

Please sign in to comment.