Skip to content
Permalink
Browse files

Daily Q_FOREACH -> for conversion

  • Loading branch information
nyalldawson committed Sep 5, 2017
1 parent ddb3198 commit b0f71e5c43a8658ac94a7538217428b4f5bebcf7
Showing with 53 additions and 37 deletions.
  1. +21 −16 src/core/expression/qgsexpressionfunction.cpp
  2. +32 −21 src/core/expression/qgsexpressionnodeimpl.cpp
@@ -54,7 +54,8 @@ QVariant QgsExpressionFunction::run( QgsExpressionNode::NodeList *args, const Qg
if ( args )
{
int arg = 0;
Q_FOREACH ( QgsExpressionNode *n, args->list() )
const QList< QgsExpressionNode * > argList = args->list();
for ( QgsExpressionNode *n : argList )
{
QVariant v;
if ( lazyEval() )
@@ -201,7 +202,8 @@ bool QgsExpressionFunction::allParamsStatic( const QgsExpressionNodeFunction *no
{
if ( node && node->args() )
{
Q_FOREACH ( QgsExpressionNode *argNode, node->args()->list() )
const QList< QgsExpressionNode * > argList = node->args()->list();
for ( QgsExpressionNode *argNode : argList )
{
if ( !argNode->isStatic( parent, context ) )
return false;
@@ -891,7 +893,7 @@ static QVariant fcnToDateTime( const QVariantList &values, const QgsExpressionCo

static QVariant fcnCoalesce( const QVariantList &values, const QgsExpressionContext *, QgsExpression * )
{
Q_FOREACH ( const QVariant &value, values )
for ( const QVariant &value : values )
{
if ( value.isNull() )
continue;
@@ -1329,7 +1331,7 @@ static QVariant fcnNumSelected( const QVariantList &values, const QgsExpressionC
static QVariant fcnConcat( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
QString concat;
Q_FOREACH ( const QVariant &value, values )
for ( const QVariant &value : values )
{
concat += QgsExpressionUtils::getStringValue( value, parent );
}
@@ -1718,9 +1720,10 @@ static QVariant fcnNodesToPoints( const QVariantList &values, const QgsExpressio

QgsMultiPointV2 *mp = new QgsMultiPointV2();

Q_FOREACH ( const QgsRingSequence &part, geom.geometry()->coordinateSequence() )
const QgsCoordinateSequence sequence = geom.geometry()->coordinateSequence();
for ( const QgsRingSequence &part : sequence )
{
Q_FOREACH ( const QgsPointSequence &ring, part )
for ( const QgsPointSequence &ring : part )
{
bool skipLast = false;
if ( ignoreClosing && ring.count() > 2 && ring.first() == ring.last() )
@@ -1745,11 +1748,11 @@ static QVariant fcnSegmentsToLines( const QVariantList &values, const QgsExpress
if ( geom.isNull() )
return QVariant();

QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.geometry() );
const QList< QgsLineString * > linesToProcess = QgsGeometryUtils::extractLineStrings( geom.geometry() );

//OK, now we have a complete list of segmentized lines from the geometry
QgsMultiLineString *ml = new QgsMultiLineString();
Q_FOREACH ( QgsLineString *line, linesToProcess )
for ( QgsLineString *line : linesToProcess )
{
for ( int i = 0; i < line->numPoints() - 1; ++i )
{
@@ -1932,7 +1935,7 @@ static QVariant fcnMakeLine( const QVariantList &values, const QgsExpressionCont
QgsLineString *lineString = new QgsLineString();
lineString->clear();

Q_FOREACH ( const QVariant &value, values )
for ( const QVariant &value : values )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( value, parent );
if ( geom.isNull() )
@@ -1987,7 +1990,7 @@ static QVariant fcnMakeTriangle( const QVariantList &values, const QgsExpression
std::unique_ptr<QgsLineString> lineString( new QgsLineString() );
lineString->clear();

Q_FOREACH ( const QVariant &value, values )
for ( const QVariant &value : values )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( value, parent );
if ( geom.isNull() )
@@ -2822,7 +2825,7 @@ static QVariant fcnOrderParts( const QVariantList &values, const QgsExpressionCo
while ( orderedGeom->partCount() )
orderedGeom->removeGeometry( 0 );

Q_FOREACH ( const QgsFeature &feature, partFeatures )
for ( const QgsFeature &feature : qgsAsConst( partFeatures ) )
{
orderedGeom->addGeometry( feature.geometry().geometry()->clone() );
}
@@ -3624,7 +3627,7 @@ static QVariant fcnArrayRemoveAll( const QVariantList &values, const QgsExpressi
static QVariant fcnArrayCat( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
QVariantList list;
Q_FOREACH ( const QVariant &cur, values )
for ( const QVariant &cur : values )
{
list += QgsExpressionUtils::getListValue( cur, parent );
}
@@ -3669,7 +3672,8 @@ static QVariant fcnArrayReverse( const QVariantList &values, const QgsExpression
static QVariant fcnArrayIntersect( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
const QVariantList array1 = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
Q_FOREACH ( const QVariant &cur, QgsExpressionUtils::getListValue( values.at( 1 ), parent ) )
const QVariantList array2 = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
for ( const QVariant &cur : array2 )
{
if ( array1.contains( cur ) )
return QVariant( true );
@@ -3768,7 +3772,7 @@ static QVariant fcnMapInsert( const QVariantList &values, const QgsExpressionCon
static QVariant fcnMapConcat( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
QVariantMap result;
Q_FOREACH ( const QVariant &cur, values )
for ( const QVariant &cur : values )
{
const QVariantMap curMap = QgsExpressionUtils::getMapValue( cur, parent );
for ( QVariantMap::const_iterator it = curMap.constBegin(); it != curMap.constEnd(); ++it )
@@ -4153,7 +4157,8 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
orderPartsFunc->setIsStaticFunction(
[]( const QgsExpressionNodeFunction * node, QgsExpression * parent, const QgsExpressionContext * context )
{
Q_FOREACH ( QgsExpressionNode *argNode, node->args()->list() )
const QList< QgsExpressionNode *> argList = node->args()->list();
for ( QgsExpressionNode *argNode : argList )
{
if ( !argNode->isStatic( parent, context ) )
return false;
@@ -4344,7 +4349,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
QgsExpressionContextUtils::registerContextFunctions();

//QgsExpression has ownership of all built-in functions
Q_FOREACH ( QgsExpressionFunction *func, sFunctions )
for ( QgsExpressionFunction *func : qgsAsConst( sFunctions ) )
{
sOwnedFunctions << func;
sBuiltinFunctions << func->name();
@@ -38,7 +38,8 @@ const char *QgsExpressionNodeUnaryOperator::UNARY_OPERATOR_TEXT[] =
bool QgsExpressionNodeInOperator::needsGeometry() const
{
bool needs = false;
Q_FOREACH ( QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( QgsExpressionNode *n : nodeList )
needs |= n->needsGeometry();
return needs;
}
@@ -59,7 +60,7 @@ void QgsExpressionNode::NodeList::append( QgsExpressionNode::NamedNode *node )
QgsExpressionNode::NodeList *QgsExpressionNode::NodeList::clone() const
{
NodeList *nl = new NodeList;
Q_FOREACH ( QgsExpressionNode *node, mList )
for ( QgsExpressionNode *node : mList )
{
nl->mList.append( node->clone() );
}
@@ -72,7 +73,7 @@ QString QgsExpressionNode::NodeList::dump() const
{
QString msg;
bool first = true;
Q_FOREACH ( QgsExpressionNode *n, mList )
for ( QgsExpressionNode *n : mList )
{
if ( !first ) msg += QLatin1String( ", " );
else first = false;
@@ -749,7 +750,8 @@ QVariant QgsExpressionNodeInOperator::evalNode( QgsExpression *parent, const Qgs

bool listHasNull = false;

Q_FOREACH ( QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( QgsExpressionNode *n : nodeList )
{
QVariant v2 = n->eval( parent, context );
ENSURE_NO_EVAL_ERROR;
@@ -802,7 +804,8 @@ QgsExpressionNode::NodeType QgsExpressionNodeInOperator::nodeType() const
bool QgsExpressionNodeInOperator::prepareNode( QgsExpression *parent, const QgsExpressionContext *context )
{
bool res = mNode->prepare( parent, context );
Q_FOREACH ( QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( QgsExpressionNode *n : nodeList )
{
res = res && n->prepare( parent, context );
}
@@ -826,7 +829,8 @@ bool QgsExpressionNodeInOperator::isStatic( QgsExpression *parent, const QgsExpr
if ( !mNode->isStatic( parent, context ) )
return false;

Q_FOREACH ( QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( QgsExpressionNode *n : nodeList )
{
if ( !n->isStatic( parent, context ) )
return false;
@@ -906,7 +910,8 @@ bool QgsExpressionNodeFunction::prepareNode( QgsExpression *parent, const QgsExp
bool res = fd->prepare( this, parent, context );
if ( mArgs && !fd->lazyEval() )
{
Q_FOREACH ( QgsExpressionNode *n, mArgs->list() )
const QList< QgsExpressionNode * > nodeList = mArgs->list();
for ( QgsExpressionNode *n : nodeList )
{
res = res && n->prepare( parent, context );
}
@@ -934,7 +939,8 @@ QSet<QString> QgsExpressionNodeFunction::referencedColumns() const
return functionColumns;
}

Q_FOREACH ( QgsExpressionNode *n, mArgs->list() )
const QList< QgsExpressionNode * > nodeList = mArgs->list();
for ( QgsExpressionNode *n : nodeList )
{
functionColumns.unite( n->referencedColumns() );
}
@@ -962,7 +968,8 @@ QSet<QString> QgsExpressionNodeFunction::referencedVariables() const
if ( !mArgs )
return functionVariables;

Q_FOREACH ( QgsExpressionNode *n, mArgs->list() )
const QList< QgsExpressionNode * > nodeList = mArgs->list();
for ( QgsExpressionNode *n : nodeList )
{
functionVariables.unite( n->referencedVariables() );
}
@@ -976,7 +983,8 @@ bool QgsExpressionNodeFunction::needsGeometry() const
bool needs = QgsExpression::QgsExpression::Functions()[mFnIndex]->usesGeometry( this );
if ( mArgs )
{
Q_FOREACH ( QgsExpressionNode *n, mArgs->list() )
const QList< QgsExpressionNode * > nodeList = mArgs->list();
for ( QgsExpressionNode *n : nodeList )
needs |= n->needsGeometry();
}
return needs;
@@ -1044,7 +1052,8 @@ bool QgsExpressionNodeFunction::validateParams( int fnIndex, QgsExpressionNode::

//last check for bad names
idx = 0;
Q_FOREACH ( const QString &name, args->names() )
const QStringList nameList = args->names();
for ( const QString &name : nameList )
{
if ( !name.isEmpty() && !functionParams.contains( name ) )
{
@@ -1247,7 +1256,7 @@ QgsExpressionNode::NodeType QgsExpressionNodeCondition::nodeType() const

QVariant QgsExpressionNodeCondition::evalNode( QgsExpression *parent, const QgsExpressionContext *context )
{
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : qgsAsConst( mConditions ) )
{
QVariant vWhen = cond->mWhenExp->eval( parent, context );
QgsExpressionUtils::TVL tvl = QgsExpressionUtils::getTVLValue( vWhen, parent );
@@ -1274,7 +1283,7 @@ QVariant QgsExpressionNodeCondition::evalNode( QgsExpression *parent, const QgsE
bool QgsExpressionNodeCondition::prepareNode( QgsExpression *parent, const QgsExpressionContext *context )
{
bool res;
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : qgsAsConst( mConditions ) )
{
res = cond->mWhenExp->prepare( parent, context )
& cond->mThenExp->prepare( parent, context );
@@ -1291,7 +1300,7 @@ bool QgsExpressionNodeCondition::prepareNode( QgsExpression *parent, const QgsEx
QString QgsExpressionNodeCondition::dump() const
{
QString msg( QStringLiteral( "CASE" ) );
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : mConditions )
{
msg += QStringLiteral( " WHEN %1 THEN %2" ).arg( cond->mWhenExp->dump(), cond->mThenExp->dump() );
}
@@ -1304,7 +1313,7 @@ QString QgsExpressionNodeCondition::dump() const
QSet<QString> QgsExpressionNodeCondition::referencedColumns() const
{
QSet<QString> lst;
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : mConditions )
{
lst += cond->mWhenExp->referencedColumns() + cond->mThenExp->referencedColumns();
}
@@ -1318,7 +1327,7 @@ QSet<QString> QgsExpressionNodeCondition::referencedColumns() const
QSet<QString> QgsExpressionNodeCondition::referencedVariables() const
{
QSet<QString> lst;
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : mConditions )
{
lst += cond->mWhenExp->referencedVariables() + cond->mThenExp->referencedVariables();
}
@@ -1331,7 +1340,7 @@ QSet<QString> QgsExpressionNodeCondition::referencedVariables() const

bool QgsExpressionNodeCondition::needsGeometry() const
{
Q_FOREACH ( WhenThen *cond, mConditions )
for ( WhenThen *cond : mConditions )
{
if ( cond->mWhenExp->needsGeometry() ||
cond->mThenExp->needsGeometry() )
@@ -1347,7 +1356,7 @@ bool QgsExpressionNodeCondition::needsGeometry() const
QgsExpressionNode *QgsExpressionNodeCondition::clone() const
{
WhenThenList conditions;
Q_FOREACH ( WhenThen *wt, mConditions )
for ( WhenThen *wt : mConditions )
conditions.append( wt->clone() );

QgsExpressionNodeCondition *copy = new QgsExpressionNodeCondition( conditions, mElseExp ? mElseExp->clone() : nullptr );
@@ -1357,7 +1366,7 @@ QgsExpressionNode *QgsExpressionNodeCondition::clone() const

bool QgsExpressionNodeCondition::isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const
{
Q_FOREACH ( WhenThen *wt, mConditions )
for ( WhenThen *wt : mConditions )
{
if ( !wt->mWhenExp->isStatic( parent, context ) || !wt->mThenExp->isStatic( parent, context ) )
return false;
@@ -1372,15 +1381,17 @@ bool QgsExpressionNodeCondition::isStatic( QgsExpression *parent, const QgsExpre
QSet<QString> QgsExpressionNodeInOperator::referencedColumns() const
{
QSet<QString> lst( mNode->referencedColumns() );
Q_FOREACH ( const QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( const QgsExpressionNode *n : nodeList )
lst.unite( n->referencedColumns() );
return lst;
}

QSet<QString> QgsExpressionNodeInOperator::referencedVariables() const
{
QSet<QString> lst( mNode->referencedVariables() );
Q_FOREACH ( const QgsExpressionNode *n, mList->list() )
const QList< QgsExpressionNode * > nodeList = mList->list();
for ( const QgsExpressionNode *n : nodeList )
lst.unite( n->referencedVariables() );
return lst;
}

0 comments on commit b0f71e5

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