Skip to content
Permalink
Browse files

Rewrite all core header usages of Q_FOREACH

  • Loading branch information
m-kuhn committed Apr 26, 2018
1 parent b64a958 commit 2d5ec75acf8aaf723175bac7977b737458e890dd
@@ -238,7 +238,7 @@ The second element of each pair are the field names of the matching primary key.
%MethodCode
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
sipRes = new QMap< QString, QString >();
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs )
for ( const QgsRelation::FieldPair &pair : pairs )
{
sipRes->insert( pair.first, pair.second );
}
@@ -36,7 +36,7 @@ class QgsExpressionSorter
bool operator()( const QgsIndexedFeature &f1, const QgsIndexedFeature &f2 ) const
{
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 &v2 = f2.mIndexes.at( i );
@@ -143,15 +143,15 @@ class QgsExpressionSorter

QgsIndexedFeature indexedFeature;

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

expressionContext->setFeature( indexedFeature.mFeature );

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 ) );
}
@@ -164,7 +164,7 @@ class QgsExpressionSorter

features.clear();

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

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

// Look for match against layer IDs
Q_FOREACH ( QgsMapLayer *layer, layers )
for ( QgsMapLayer *layer : layers )
{
if ( !matchId && layer->id() == identifier )
{
@@ -171,7 +171,8 @@ struct _LayerRef

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 ) )
{
@@ -296,7 +296,7 @@ class CORE_EXPORT QgsRelation
% MethodCode
const QList< QgsRelation::FieldPair > &pairs = sipCpp->fieldPairs();
sipRes = new QMap< QString, QString >();
Q_FOREACH ( const QgsRelation::FieldPair &pair, pairs )
for ( const QgsRelation::FieldPair &pair : pairs )
{
sipRes->insert( pair.first, pair.second );
}
@@ -86,6 +86,17 @@ void QgsRuleBasedLabeling::Rule::setSettings( QgsPalLayerSettings *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()
{
if ( mElseRule || mFilterExp.compare( QLatin1String( "ELSE" ), Qt::CaseInsensitive ) == 0 )
@@ -203,7 +203,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
*
* \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
@@ -251,6 +251,14 @@ bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
///////////////////////////////////////////////
// nodes

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

QgsSQLStatement::NodeList *QgsSQLStatement::NodeList::clone() const
{
NodeList *nl = new NodeList;
@@ -301,7 +301,7 @@ class CORE_EXPORT QgsSQLStatement
int count() const { return mList.count(); }

//! 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
QgsSQLStatement::NodeList *clone() const SIP_FACTORY;
@@ -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-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";

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;
}
@@ -28,58 +28,11 @@
class CORE_EXPORT QgsColorBrewerPalette
{
public:
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 QList<QColor> listSchemeColors( const QString &schemeName, int colors );

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

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 )
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;
}
static QList<int> listSchemeVariants( const QString &schemeName );

// extracted ColorBrewer data
static const char *BREWER_STRING;
@@ -701,6 +701,17 @@ QgsRuleBasedRenderer::Rule *QgsRuleBasedRenderer::Rule::create( QDomElement &rul
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 )
{
if ( ruleElem.localName() != QLatin1String( "Rule" ) )
@@ -84,7 +84,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
struct RenderLevel
{
explicit RenderLevel( int z ): zIndex( z ) {}
~RenderLevel() { Q_FOREACH ( RenderJob *j, jobs ) delete j; }
~RenderLevel() { qDeleteAll( jobs ); }
int zIndex;

//! List of jobs to render, owned by this object.
@@ -95,7 +95,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
zIndex = rh.zIndex;
qDeleteAll( jobs );
jobs.clear();
Q_FOREACH ( RenderJob *job, rh.jobs )
for ( RenderJob *job : qgis::as_const( rh.jobs ) )
{
jobs << new RenderJob( *job );
}
@@ -105,7 +105,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
RenderLevel( const QgsRuleBasedRenderer::RenderLevel &other )
: zIndex( other.zIndex )
{
Q_FOREACH ( RenderJob *job, other.jobs )
for ( RenderJob *job : qgis::as_const( other.jobs ) )
{
jobs << new RenderJob( *job );
}
@@ -381,7 +381,7 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
*
* \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

0 comments on commit 2d5ec75

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