Skip to content

Commit 2d5ec75

Browse files
committedApr 26, 2018
Rewrite all core header usages of Q_FOREACH
1 parent b64a958 commit 2d5ec75

13 files changed

+106
-69
lines changed
 

‎python/core/qgsrelation.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ The second element of each pair are the field names of the matching primary key.
238238
%MethodCode
239239
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
240240
sipRes = new QMap< QString, QString >();
241-
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs )
241+
for ( const QgsRelation::FieldPair &pair : pairs )
242242
{
243243
sipRes->insert( pair.first, pair.second );
244244
}

‎src/core/qgsexpressionsorter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QgsExpressionSorter
3636
bool operator()( const QgsIndexedFeature &f1, const QgsIndexedFeature &f2 ) const
3737
{
3838
int i = 0;
39-
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &orderBy, mPreparedOrderBys )
39+
for ( const QgsFeatureRequest::OrderByClause &orderBy : qgis::as_const( mPreparedOrderBys ) )
4040
{
4141
const QVariant &v1 = f1.mIndexes.at( i );
4242
const QVariant &v2 = f2.mIndexes.at( i );
@@ -143,15 +143,15 @@ class QgsExpressionSorter
143143

144144
QgsIndexedFeature indexedFeature;
145145

146-
Q_FOREACH ( const QgsFeature &f, features )
146+
for ( const QgsFeature &f : qgis::as_const( features ) )
147147
{
148148
indexedFeature.mIndexes.resize( mPreparedOrderBys.size() );
149149
indexedFeature.mFeature = f;
150150

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

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

165165
features.clear();
166166

167-
Q_FOREACH ( const QgsIndexedFeature &indexedFeature, indexedFeatures )
167+
for ( const QgsIndexedFeature &indexedFeature : qgis::as_const( indexedFeatures ) )
168168
features.append( indexedFeature.mFeature );
169169
}
170170

‎src/core/qgsmaplayerlistutils.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline QList<QgsMapLayer *> _qgis_listQPointerToRaw( const QgsWeakMapLayerPointe
3535
{
3636
QList<QgsMapLayer *> lst;
3737
lst.reserve( layers.count() );
38-
Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, layers )
38+
for ( const QgsWeakMapLayerPointer &layerPtr : layers )
3939
{
4040
if ( layerPtr )
4141
lst.append( layerPtr.data() );
@@ -47,7 +47,7 @@ inline QgsWeakMapLayerPointerList _qgis_listRawToQPointer( const QList<QgsMapLay
4747
{
4848
QgsWeakMapLayerPointerList lst;
4949
lst.reserve( layers.count() );
50-
Q_FOREACH ( QgsMapLayer *layer, layers )
50+
for ( QgsMapLayer *layer : layers )
5151
{
5252
lst.append( layer );
5353
}
@@ -58,7 +58,7 @@ inline QList<QgsMapLayer *> _qgis_listRefToRaw( const QList< QgsMapLayerRef > &l
5858
{
5959
QList<QgsMapLayer *> lst;
6060
lst.reserve( layers.count() );
61-
Q_FOREACH ( const QgsMapLayerRef &layer, layers )
61+
for ( const QgsMapLayerRef &layer : layers )
6262
{
6363
if ( layer )
6464
lst.append( layer.get() );
@@ -70,7 +70,7 @@ inline QList< QgsMapLayerRef > _qgis_listRawToRef( const QList<QgsMapLayer *> &l
7070
{
7171
QList< QgsMapLayerRef > lst;
7272
lst.reserve( layers.count() );
73-
Q_FOREACH ( QgsMapLayer *layer, layers )
73+
for ( QgsMapLayer *layer : layers )
7474
{
7575
lst.append( QgsMapLayerRef( layer ) );
7676
}
@@ -92,7 +92,7 @@ inline QStringList _qgis_listQPointerToIDs( const QgsWeakMapLayerPointerList &la
9292
{
9393
QStringList lst;
9494
lst.reserve( layers.count() );
95-
Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, layers )
95+
for ( const QgsWeakMapLayerPointer &layerPtr : layers )
9696
{
9797
if ( layerPtr )
9898
lst << layerPtr->id();
@@ -107,7 +107,7 @@ inline static QgsMapLayer *_qgis_findLayer( const QList< QgsMapLayer *> &layers,
107107
QgsMapLayer *matchNameInsensitive = nullptr;
108108

109109
// Look for match against layer IDs
110-
Q_FOREACH ( QgsMapLayer *layer, layers )
110+
for ( QgsMapLayer *layer : layers )
111111
{
112112
if ( !matchId && layer->id() == identifier )
113113
{

‎src/core/qgsmaplayerref.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ struct _LayerRef
171171

172172
if ( project && !name.isEmpty() )
173173
{
174-
Q_FOREACH ( QgsMapLayer *l, project->mapLayersByName( name ) )
174+
const QList<QgsMapLayer *> layers = project->mapLayersByName( name );
175+
for ( QgsMapLayer *l : layers )
175176
{
176177
if ( TYPE *tl = qobject_cast< TYPE *>( l ) )
177178
{

‎src/core/qgsrelation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class CORE_EXPORT QgsRelation
296296
% MethodCode
297297
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
298298
sipRes = new QMap< QString, QString >();
299-
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs )
299+
for ( const QgsRelation::FieldPair &pair : pairs )
300300
{
301301
sipRes->insert( pair.first, pair.second );
302302
}

‎src/core/qgsrulebasedlabeling.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ void QgsRuleBasedLabeling::Rule::setSettings( QgsPalLayerSettings *settings )
8686
mSettings = settings;
8787
}
8888

89+
QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::Rule::descendants() const
90+
{
91+
RuleList l;
92+
for ( Rule *c : mChildren )
93+
{
94+
l += c;
95+
l += c->descendants();
96+
}
97+
return l;
98+
}
99+
89100
void QgsRuleBasedLabeling::Rule::initFilter()
90101
{
91102
if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 )

‎src/core/qgsrulebasedlabeling.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
203203
*
204204
* \returns A list of descendant rules
205205
*/
206-
QgsRuleBasedLabeling::RuleList descendants() const { RuleList l; Q_FOREACH ( Rule *c, mChildren ) { l += c; l += c->descendants(); } return l; }
206+
QgsRuleBasedLabeling::RuleList descendants() const;
207207

208208
/**
209209
* The parent rule

‎src/core/qgssqlstatement.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
251251
///////////////////////////////////////////////
252252
// nodes
253253

254+
void QgsSQLStatement::NodeList::accept( QgsSQLStatement::Visitor &v ) const
255+
{
256+
for ( QgsSQLStatement::Node *node : mList )
257+
{
258+
node->accept( v );
259+
}
260+
}
261+
254262
QgsSQLStatement::NodeList *QgsSQLStatement::NodeList::clone() const
255263
{
256264
NodeList *nl = new NodeList;

‎src/core/qgssqlstatement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class CORE_EXPORT QgsSQLStatement
301301
int count() const { return mList.count(); }
302302

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

306306
//! Creates a deep copy of this list. Ownership is transferred to the caller
307307
QgsSQLStatement::NodeList *clone() const SIP_FACTORY;

‎src/core/symbology/qgscolorbrewerpalette.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,56 @@ const char *QgsColorBrewerPalette::BREWER_STRING =
291291
"PuBuGn-7-246,239,247 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n"
292292
"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"
293293
"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";
294+
295+
QList<QColor> QgsColorBrewerPalette::listSchemeColors( const QString &schemeName, int colors )
296+
{
297+
QList<QColor> pal;
298+
QString palette( BREWER_STRING );
299+
const QStringList list = palette.split( QChar( '\n' ) );
300+
for ( const QString &entry : list )
301+
{
302+
QStringList items = entry.split( QChar( '-' ) );
303+
if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
304+
continue;
305+
const QStringList colors = items[2].split( QChar( ' ' ) );
306+
for ( const QString &clr : colors )
307+
{
308+
pal << QgsSymbolLayerUtils::parseColor( clr );
309+
}
310+
}
311+
return pal;
312+
}
313+
314+
QStringList QgsColorBrewerPalette::listSchemes()
315+
{
316+
QStringList schemes;
317+
318+
QString palette( BREWER_STRING );
319+
const QStringList list = palette.split( QChar( '\n' ) );
320+
for ( const QString &entry : list )
321+
{
322+
QStringList items = entry.split( QChar( '-' ) );
323+
if ( items.count() != 3 )
324+
continue;
325+
if ( !schemes.contains( items[0] ) )
326+
schemes << items[0];
327+
}
328+
return schemes;
329+
}
330+
331+
QList<int> QgsColorBrewerPalette::listSchemeVariants( const QString &schemeName )
332+
{
333+
QList<int> variants;
334+
335+
QString palette( BREWER_STRING );
336+
const QStringList list = palette.split( QChar( '\n' ) );
337+
for ( const QString &entry : list )
338+
{
339+
QStringList items = entry.split( QChar( '-' ) );
340+
if ( items.count() != 3 || items[0] != schemeName )
341+
continue;
342+
variants << items[1].toInt();
343+
}
344+
345+
return variants;
346+
}

‎src/core/symbology/qgscolorbrewerpalette.h

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,11 @@
2828
class CORE_EXPORT QgsColorBrewerPalette
2929
{
3030
public:
31-
static QList<QColor> listSchemeColors( const QString &schemeName, int colors )
32-
{
33-
QList<QColor> pal;
34-
QString palette( BREWER_STRING );
35-
QStringList list = palette.split( QChar( '\n' ) );
36-
Q_FOREACH ( const QString &entry, list )
37-
{
38-
QStringList items = entry.split( QChar( '-' ) );
39-
if ( items.count() != 3 || items[0] != schemeName || items[1].toInt() != colors )
40-
continue;
41-
QStringList colors = items[2].split( QChar( ' ' ) );
42-
Q_FOREACH ( const QString &clr, colors )
43-
{
44-
pal << QgsSymbolLayerUtils::parseColor( clr );
45-
}
46-
}
47-
return pal;
48-
}
31+
static QList<QColor> listSchemeColors( const QString &schemeName, int colors );
4932

50-
static QStringList listSchemes()
51-
{
52-
QStringList schemes;
33+
static QStringList listSchemes();
5334

54-
QString palette( BREWER_STRING );
55-
QStringList list = palette.split( QChar( '\n' ) );
56-
Q_FOREACH ( const QString &entry, list )
57-
{
58-
QStringList items = entry.split( QChar( '-' ) );
59-
if ( items.count() != 3 )
60-
continue;
61-
if ( !schemes.contains( items[0] ) )
62-
schemes << items[0];
63-
}
64-
return schemes;
65-
}
66-
67-
static QList<int> listSchemeVariants( const QString &schemeName )
68-
{
69-
QList<int> variants;
70-
71-
QString palette( BREWER_STRING );
72-
QStringList list = palette.split( QChar( '\n' ) );
73-
Q_FOREACH ( const QString &entry, list )
74-
{
75-
QStringList items = entry.split( QChar( '-' ) );
76-
if ( items.count() != 3 || items[0] != schemeName )
77-
continue;
78-
variants << items[1].toInt();
79-
}
80-
81-
return variants;
82-
}
35+
static QList<int> listSchemeVariants( const QString &schemeName );
8336

8437
// extracted ColorBrewer data
8538
static const char *BREWER_STRING;

‎src/core/symbology/qgsrulebasedrenderer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,17 @@ QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::create( QDomElement &rul
701701
return rule;
702702
}
703703

704+
QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::descendants() const
705+
{
706+
RuleList l;
707+
for ( QgsRuleBasedRenderer::Rule *c : mChildren )
708+
{
709+
l += c;
710+
l += c->descendants();
711+
}
712+
return l;
713+
}
714+
704715
QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::createFromSld( QDomElement &ruleElem, QgsWkbTypes::GeometryType geomType )
705716
{
706717
if ( ruleElem.localName() != QLatin1String( "Rule" ) )

‎src/core/symbology/qgsrulebasedrenderer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
8484
struct RenderLevel
8585
{
8686
explicit RenderLevel( int z ): zIndex( z ) {}
87-
~RenderLevel() { Q_FOREACH ( RenderJob *j, jobs ) delete j; }
87+
~RenderLevel() { qDeleteAll( jobs ); }
8888
int zIndex;
8989

9090
//! List of jobs to render, owned by this object.
@@ -95,7 +95,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
9595
zIndex = rh.zIndex;
9696
qDeleteAll( jobs );
9797
jobs.clear();
98-
Q_FOREACH ( RenderJob *job, rh.jobs )
98+
for ( RenderJob *job : qgis::as_const( rh.jobs ) )
9999
{
100100
jobs << new RenderJob( *job );
101101
}
@@ -105,7 +105,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
105105
RenderLevel( const QgsRuleBasedRenderer::RenderLevel &other )
106106
: zIndex( other.zIndex )
107107
{
108-
Q_FOREACH ( RenderJob *job, other.jobs )
108+
for ( RenderJob *job : qgis::as_const( other.jobs ) )
109109
{
110110
jobs << new RenderJob( *job );
111111
}
@@ -381,7 +381,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
381381
*
382382
* \returns A list of descendant rules
383383
*/
384-
QgsRuleBasedRenderer::RuleList descendants() const { RuleList l; Q_FOREACH ( QgsRuleBasedRenderer::Rule *c, mChildren ) { l += c; l += c->descendants(); } return l; }
384+
QgsRuleBasedRenderer::RuleList descendants() const;
385385

386386
/**
387387
* The parent rule

0 commit comments

Comments
 (0)
Please sign in to comment.