Skip to content

Commit

Permalink
Daily Q_FOREACH -> for conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 5, 2017
1 parent ddb3198 commit b0f71e5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
37 changes: 21 additions & 16 deletions src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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() )
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
53 changes: 32 additions & 21 deletions src/core/expression/qgsexpressionnodeimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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() );
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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() );
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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() );
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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() )
Expand All @@ -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 );
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit b0f71e5

Please sign in to comment.