Skip to content

Commit

Permalink
Merge pull request #6862 from m-kuhn/core-headers-no-qforeach
Browse files Browse the repository at this point in the history
Rewrite all core header usages of Q_FOREACH
  • Loading branch information
m-kuhn committed Apr 26, 2018
2 parents c3b6990 + f5099db commit f816588
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 105 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
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 );
}
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
{
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 );
Expand Down Expand Up @@ -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 ) );
}
Expand All @@ -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 );
}

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;
lst.reserve( layers.count() );
Q_FOREACH ( const QgsWeakMapLayerPointer &layerPtr, layers )
for ( const QgsWeakMapLayerPointer &layerPtr : layers )
{
if ( layerPtr )
lst.append( layerPtr.data() );
Expand All @@ -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 );
}
Expand All @@ -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() );
Expand All @@ -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 ) );
}
Expand All @@ -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();
Expand All @@ -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 )
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayerref.h
Expand Up @@ -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 ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrelation.h
Expand Up @@ -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 );
}
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;
}

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 )
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
*/
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
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

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;
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(); }

//! 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;
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-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;
}
53 changes: 3 additions & 50 deletions src/core/symbology/qgscolorbrewerpalette.h
Expand Up @@ -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;
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;
}

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" ) )
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
{
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.
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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
Expand Down
37 changes: 36 additions & 1 deletion src/gui/raster/qgspalettedrendererwidget.cpp
Expand Up @@ -803,5 +803,40 @@ void QgsPalettedRendererModel::deleteAll()
emit classesChanged();
}

///@endcond PRIVATE
void QgsPalettedRendererClassGatherer::run()
{
mWasCanceled = false;

// allow responsive cancelation
mFeedback = new QgsRasterBlockFeedback();
connect( mFeedback, &QgsRasterBlockFeedback::progressChanged, this, &QgsPalettedRendererClassGatherer::progressChanged );

QgsPalettedRasterRenderer::ClassData newClasses = QgsPalettedRasterRenderer::classDataFromRaster( mLayer->dataProvider(), mBandNumber, mRamp.get(), mFeedback );

// combine existing classes with new classes
QgsPalettedRasterRenderer::ClassData::iterator classIt = newClasses.begin();
for ( ; classIt != newClasses.end(); ++classIt )
{
// check if existing classes contains this same class
for ( const QgsPalettedRasterRenderer::Class &existingClass : qgis::as_const( mClasses ) )
{
if ( existingClass.value == classIt->value )
{
classIt->color = existingClass.color;
classIt->label = existingClass.label;
break;
}
}
}
mClasses = newClasses;

// be overly cautious - it's *possible* stop() might be called between deleting mFeedback and nulling it
mFeedbackMutex.lock();
delete mFeedback;
mFeedback = nullptr;
mFeedbackMutex.unlock();

emit collectedClasses();
}

///@endcond PRIVATE

0 comments on commit f816588

Please sign in to comment.