23 const char *QgsExpressionNodeBinaryOperator::BINARY_OPERATOR_TEXT[] =
27 "=",
"<>",
"<=",
">=",
"<",
">",
"~",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
28 "+",
"-",
"*",
"/",
"//",
"%",
"^",
32 const char *QgsExpressionNodeUnaryOperator::UNARY_OPERATOR_TEXT[] =
41 const QList< QgsExpressionNode * > nodeList = mList->
list();
43 needs |= n->needsGeometry();
55 mNameList.append( node->
name.toLower() );
56 mHasNamedNodes =
true;
67 nl->mNameList = mNameList;
78 if ( !first ) msg += QLatin1String(
", " );
90 QVariant val = mOperand->eval( parent, context );
97 QgsExpressionUtils::TVL tvl = QgsExpressionUtils::getTVLValue( val, parent );
99 return QgsExpressionUtils::tvl2variant( QgsExpressionUtils::NOT[tvl] );
103 if ( QgsExpressionUtils::isIntSafe( val ) )
104 return QVariant( - QgsExpressionUtils::getIntValue( val, parent ) );
105 else if ( QgsExpressionUtils::isDoubleSafe( val ) )
106 return QVariant( - QgsExpressionUtils::getDoubleValue( val, parent ) );
110 Q_ASSERT(
false &&
"unknown unary operation" );
122 return mOperand->prepare( parent, context );
127 return QStringLiteral(
"%1 %2" ).arg( UNARY_OPERATOR_TEXT[mOp], mOperand->dump() );
132 return mOperand->referencedColumns();
137 return mOperand->referencedVariables();
142 return mOperand->referencedFunctions();
147 QList<const QgsExpressionNode *> lst;
149 lst += mOperand->nodes();
155 return mOperand->needsGeometry();
167 return mOperand->isStatic( parent, context );
172 return UNARY_OPERATOR_TEXT[mOp];
179 QVariant vL = mOpLeft->eval( parent, context );
181 QVariant vR = mOpRight->eval( parent, context );
187 if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
189 QString sL = QgsExpressionUtils::isNull( vL ) ? QString() : QgsExpressionUtils::getStringValue( vL, parent );
191 QString sR = QgsExpressionUtils::isNull( vR ) ? QString() : QgsExpressionUtils::getStringValue( vR, parent );
193 return QVariant( sL + sR );
202 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
204 else if ( mOp != boDiv && QgsExpressionUtils::isIntSafe( vL ) && QgsExpressionUtils::isIntSafe( vR ) )
207 qlonglong iL = QgsExpressionUtils::getIntValue( vL, parent );
209 qlonglong iR = QgsExpressionUtils::getIntValue( vR, parent );
212 if ( mOp == boMod && iR == 0 )
215 return QVariant( computeInt( iL, iR ) );
217 else if ( QgsExpressionUtils::isDateTimeSafe( vL ) && QgsExpressionUtils::isIntervalSafe( vR ) )
219 QDateTime dL = QgsExpressionUtils::getDateTimeValue( vL, parent );
221 QgsInterval iL = QgsExpressionUtils::getInterval( vR, parent );
223 if ( mOp == boDiv || mOp == boMul || mOp == boMod )
225 parent->
setEvalErrorString( tr(
"Can't perform /, *, or % on DateTime and Interval" ) );
228 return QVariant( computeDateTimeFromInterval( dL, &iL ) );
230 else if ( mOp == boPlus && ( ( vL.type() == QVariant::Date && vR.type() == QVariant::Time ) ||
231 ( vR.type() == QVariant::Date && vL.type() == QVariant::Time ) ) )
233 QDate date = QgsExpressionUtils::getDateValue( vL.type() == QVariant::Date ? vL : vR, parent );
235 QTime time = QgsExpressionUtils::getTimeValue( vR.type() == QVariant::Time ? vR : vL, parent );
237 QDateTime dt = QDateTime( date, time );
238 return QVariant( dt );
240 else if ( mOp == boMinus && vL.type() == QVariant::Date && vR.type() == QVariant::Date )
242 QDate date1 = QgsExpressionUtils::getDateValue( vL, parent );
244 QDate date2 = QgsExpressionUtils::getDateValue( vR, parent );
246 return date1 - date2;
248 else if ( mOp == boMinus && vL.type() == QVariant::Time && vR.type() == QVariant::Time )
250 QTime time1 = QgsExpressionUtils::getTimeValue( vL, parent );
252 QTime time2 = QgsExpressionUtils::getTimeValue( vR, parent );
254 return time1 - time2;
256 else if ( mOp == boMinus && vL.type() == QVariant::DateTime && vR.type() == QVariant::DateTime )
258 QDateTime datetime1 = QgsExpressionUtils::getDateTimeValue( vL, parent );
260 QDateTime datetime2 = QgsExpressionUtils::getDateTimeValue( vR, parent );
262 return datetime1 - datetime2;
267 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
269 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
271 if ( ( mOp == boDiv || mOp == boMod ) && fR == 0. )
273 return QVariant( computeDouble( fL, fR ) );
279 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
281 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
285 return QVariant( qlonglong( std::floor( fL / fR ) ) );
288 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
292 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
294 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
296 return QVariant( std::pow( fL, fR ) );
301 QgsExpressionUtils::TVL tvlL = QgsExpressionUtils::getTVLValue( vL, parent ), tvlR = QgsExpressionUtils::getTVLValue( vR, parent );
303 return QgsExpressionUtils::tvl2variant( QgsExpressionUtils::AND[tvlL][tvlR] );
308 QgsExpressionUtils::TVL tvlL = QgsExpressionUtils::getTVLValue( vL, parent ), tvlR = QgsExpressionUtils::getTVLValue( vR, parent );
310 return QgsExpressionUtils::tvl2variant( QgsExpressionUtils::OR[tvlL][tvlR] );
319 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
323 else if ( QgsExpressionUtils::isList( vL ) || QgsExpressionUtils::isList( vR ) )
326 if ( !QgsExpressionUtils::isList( vL ) || !QgsExpressionUtils::isList( vR ) )
330 QVariantList lL = vL.toList();
331 QVariantList lR = vR.toList();
332 for (
int i = 0; i < lL.length() && i < lR.length(); i++ )
334 if ( QgsExpressionUtils::isNull( lL.at( i ) ) && QgsExpressionUtils::isNull( lR.at( i ) ) )
337 if ( QgsExpressionUtils::isNull( lL.at( i ) ) || QgsExpressionUtils::isNull( lR.at( i ) ) )
347 return QgsExpressionUtils::isNull( lR.at( i ) );
350 return QgsExpressionUtils::isNull( lL.at( i ) );
360 QVariant eq = eqNode.
eval( parent, context );
362 if ( eq == TVL_False )
366 QVariant v =
node.
eval( parent, context );
376 return lL.length() == lR.length();
378 return lL.length() != lR.length();
380 return lL.length() < lR.length();
382 return lL.length() > lR.length();
384 return lL.length() <= lR.length();
386 return lL.length() >= lR.length();
392 else if ( ( vL.type() != QVariant::String || vR.type() != QVariant::String ) &&
393 QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) )
397 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
399 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
401 return compare( fL - fR ) ? TVL_True : TVL_False;
406 double fL = QgsExpressionUtils::getInterval( vL, parent ).seconds();
408 double fR = QgsExpressionUtils::getInterval( vR, parent ).seconds();
410 return compare( fL - fR ) ? TVL_True : TVL_False;
415 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
417 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
419 int diff = QString::compare( sL, sR );
420 return compare( diff ) ? TVL_True : TVL_False;
425 if ( QgsExpressionUtils::isNull( vL ) && QgsExpressionUtils::isNull( vR ) )
426 return ( mOp == boIs ? TVL_True : TVL_False );
427 else if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
428 return ( mOp == boIs ? TVL_False : TVL_True );
432 if ( QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) &&
433 ( vL.type() != QVariant::String || vR.type() != QVariant::String ) )
435 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
437 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
443 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
445 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
447 equal = QString::compare( sL, sR ) == 0;
450 return mOp == boIs ? TVL_True : TVL_False;
452 return mOp == boIs ? TVL_False : TVL_True;
460 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
464 QString str = QgsExpressionUtils::getStringValue( vL, parent );
466 QString regexp = QgsExpressionUtils::getStringValue( vR, parent );
470 if ( mOp == boLike || mOp == boILike || mOp == boNotLike || mOp == boNotILike )
472 QString esc_regexp = QRegExp::escape( regexp );
474 if ( esc_regexp.startsWith(
'%' ) )
476 esc_regexp.replace( 0, 1, QStringLiteral(
".*" ) );
478 QRegExp rx(
"[^\\\\](%)" );
480 while ( ( pos = rx.indexIn( esc_regexp, pos ) ) != -1 )
482 esc_regexp.replace( pos + 1, 1, QStringLiteral(
".*" ) );
485 rx.setPattern( QStringLiteral(
"\\\\%" ) );
486 esc_regexp.replace( rx, QStringLiteral(
"%" ) );
487 if ( esc_regexp.startsWith(
'_' ) )
489 esc_regexp.replace( 0, 1, QStringLiteral(
"." ) );
491 rx.setPattern( QStringLiteral(
"[^\\\\](_)" ) );
493 while ( ( pos = rx.indexIn( esc_regexp, pos ) ) != -1 )
495 esc_regexp.replace( pos + 1, 1,
'.' );
498 rx.setPattern( QStringLiteral(
"\\\\_" ) );
499 esc_regexp.replace( rx, QStringLiteral(
"_" ) );
500 matches = QRegExp( esc_regexp, mOp == boLike || mOp == boNotLike ? Qt::CaseSensitive : Qt::CaseInsensitive ).exactMatch( str );
504 matches = QRegExp( regexp ).indexIn( str ) != -1;
507 if ( mOp == boNotLike || mOp == boNotILike )
512 return matches ? TVL_True : TVL_False;
516 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
520 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
522 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
524 return QVariant( sL + sR );
534 bool QgsExpressionNodeBinaryOperator::compare(
double diff )
556 qlonglong QgsExpressionNodeBinaryOperator::computeInt( qlonglong x, qlonglong y )
576 QDateTime QgsExpressionNodeBinaryOperator::computeDateTimeFromInterval(
const QDateTime &d,
QgsInterval *i )
581 return d.addSecs( i->
seconds() );
583 return d.addSecs( -i->
seconds() );
590 double QgsExpressionNodeBinaryOperator::computeDouble(
double x,
double y )
603 return std::fmod( x, y );
617 bool resL = mOpLeft->prepare( parent, context );
618 bool resR = mOpRight->prepare( parent, context );
664 Q_ASSERT(
false &&
"unexpected binary operator" );
700 Q_ASSERT(
false &&
"unexpected binary operator" );
710 QString rdump( mOpRight->dump() );
715 rdump.prepend(
'(' ).append(
')' );
719 if ( leftAssociative() )
721 fmt += lOp && ( lOp->
precedence() < precedence() ) ? QStringLiteral(
"(%1)" ) : QStringLiteral(
"%1" );
722 fmt += QLatin1String(
" %2 " );
723 fmt += rOp && ( rOp->
precedence() <= precedence() ) ? QStringLiteral(
"(%3)" ) : QStringLiteral(
"%3" );
727 fmt += lOp && ( lOp->
precedence() <= precedence() ) ? QStringLiteral(
"(%1)" ) : QStringLiteral(
"%1" );
728 fmt += QLatin1String(
" %2 " );
729 fmt += rOp && ( rOp->
precedence() < precedence() ) ? QStringLiteral(
"(%3)" ) : QStringLiteral(
"%3" );
732 return fmt.arg( mOpLeft->dump(), BINARY_OPERATOR_TEXT[mOp], rdump );
737 return mOpLeft->referencedColumns() + mOpRight->referencedColumns();
742 return mOpLeft->referencedVariables() + mOpRight->referencedVariables();
747 return mOpLeft->referencedFunctions() + mOpRight->referencedFunctions();
752 QList<const QgsExpressionNode *> lst;
754 lst += mOpLeft->nodes() + mOpRight->nodes();
760 return mOpLeft->needsGeometry() || mOpRight->needsGeometry();
772 return mOpLeft->isStatic( parent, context ) && mOpRight->isStatic( parent, context );
779 if ( mList->
count() == 0 )
780 return mNotIn ? TVL_True : TVL_False;
781 QVariant v1 = mNode->
eval( parent, context );
783 if ( QgsExpressionUtils::isNull( v1 ) )
786 bool listHasNull =
false;
788 const QList< QgsExpressionNode * > nodeList = mList->
list();
791 QVariant v2 = n->eval( parent, context );
793 if ( QgsExpressionUtils::isNull( v2 ) )
799 if ( QgsExpressionUtils::isDoubleSafe( v1 ) && QgsExpressionUtils::isDoubleSafe( v2 ) )
801 double f1 = QgsExpressionUtils::getDoubleValue( v1, parent );
803 double f2 = QgsExpressionUtils::getDoubleValue( v2, parent );
809 QString s1 = QgsExpressionUtils::getStringValue( v1, parent );
811 QString s2 = QgsExpressionUtils::getStringValue( v2, parent );
813 equal = QString::compare( s1, s2 ) == 0;
817 return mNotIn ? TVL_False : TVL_True;
825 return mNotIn ? TVL_True : TVL_False;
841 bool res = mNode->
prepare( parent, context );
842 const QList< QgsExpressionNode * > nodeList = mList->
list();
845 res = res && n->prepare( parent, context );
852 return QStringLiteral(
"%1 %2 IN (%3)" ).arg( mNode->
dump(), mNotIn ?
"NOT" :
"", mList->
dump() );
864 if ( !mNode->
isStatic( parent, context ) )
867 const QList< QgsExpressionNode * > nodeList = mList->
list();
870 if ( !n->isStatic( parent, context ) )
881 QString name = QgsExpression::QgsExpression::Functions()[mFnIndex]->name();
884 QVariant res = fd->
run( mArgs, context, parent,
this );
892 : mFnIndex( fnIndex )
895 if ( !args || functionParams.isEmpty() )
906 while ( idx < args->names().size() && args->
names().at( idx ).isEmpty() )
908 mArgs->
append( args->
list().at( idx )->clone() );
913 for ( ; idx < functionParams.count(); ++idx )
915 int nodeIdx = args->
names().indexOf( functionParams.at( idx ).name().toLower() );
923 mArgs->
append( args->
list().at( nodeIdx )->clone() );
945 bool res = fd->
prepare(
this, parent, context );
948 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
951 res = res && n->prepare( parent, context );
961 return QStringLiteral(
"%1%2" ).arg( fd->
name(), fd->
name().startsWith(
'$' ) ?
"" :
"()" );
963 return QStringLiteral(
"%1(%2)" ).arg( fd->
name(), mArgs ? mArgs->
dump() : QString() );
974 return functionColumns;
978 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
981 if ( fd->
parameters().count() <= paramIndex || !fd->
parameters().at( paramIndex ).isSubExpression() )
982 functionColumns.unite( n->referencedColumns() );
986 return functionColumns;
992 if ( fd->
name() == QLatin1String(
"var" ) )
994 if ( !mArgs->
list().isEmpty() )
998 return QSet<QString>() << var->
value().toString();
1000 return QSet<QString>() << QString();
1004 QSet<QString> functionVariables = QSet<QString>();
1007 return functionVariables;
1009 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1012 functionVariables.unite( n->referencedVariables() );
1015 return functionVariables;
1022 QSet<QString> functions = QSet<QString>();
1023 functions.insert( fd->
name() );
1028 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1031 functions.unite( n->referencedFunctions() );
1038 QList<const QgsExpressionNode *> lst;
1043 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1053 bool needs = QgsExpression::QgsExpression::Functions()[mFnIndex]->usesGeometry(
this );
1056 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1058 needs |= n->needsGeometry();
1081 if ( functionParams.isEmpty() )
1083 error = QStringLiteral(
"%1 does not support named QgsExpressionFunction::Parameters" ).arg(
QgsExpression::Functions()[fnIndex]->name() );
1088 QSet< int > providedArgs;
1089 QSet< int > handledArgs;
1092 while ( args->
names().at( idx ).isEmpty() )
1094 providedArgs << idx;
1100 for ( ; idx < functionParams.count(); ++idx )
1102 int nodeIdx = args->
names().indexOf( functionParams.at( idx ).name().toLower() );
1105 if ( !functionParams.at( idx ).optional() )
1107 error = QStringLiteral(
"No value specified for QgsExpressionFunction::Parameter '%1' for %2" ).arg( functionParams.at( idx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1113 if ( providedArgs.contains( idx ) )
1115 error = QStringLiteral(
"Duplicate QgsExpressionFunction::Parameter specified for '%1' for %2" ).arg( functionParams.at( idx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1119 providedArgs << idx;
1120 handledArgs << nodeIdx;
1125 const QStringList nameList = args->
names();
1126 for (
const QString &name : nameList )
1128 if ( !name.isEmpty() && !functionParams.contains( name ) )
1130 error = QStringLiteral(
"Invalid QgsExpressionFunction::Parameter name '%1' for %2" ).arg( name,
QgsExpression::Functions()[fnIndex]->name() );
1133 if ( !name.isEmpty() && !handledArgs.contains( idx ) )
1135 int functionIdx = functionParams.indexOf( name );
1136 if ( providedArgs.contains( functionIdx ) )
1138 error = QStringLiteral(
"Duplicate QgsExpressionFunction::Parameter specified for '%1' for %2" ).arg( functionParams.at( functionIdx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1173 if ( mValue.isNull() )
1174 return QStringLiteral(
"NULL" );
1176 switch ( mValue.type() )
1179 return QString::number( mValue.toInt() );
1180 case QVariant::Double:
1181 return QString::number( mValue.toDouble() );
1182 case QVariant::LongLong:
1183 return QString::number( mValue.toLongLong() );
1184 case QVariant::String:
1186 case QVariant::Bool:
1187 return mValue.toBool() ? QStringLiteral(
"TRUE" ) : QStringLiteral(
"FALSE" );
1189 return tr(
"[unsupported type: %1; value: %2]" ).arg( mValue.typeName(), mValue.toString() );
1195 return QSet<QString>();
1200 return QSet<QString>();
1205 return QSet<QString>();
1210 QList<const QgsExpressionNode *> lst;
1262 return QVariant(
'[' + mName +
']' );
1299 return QSet<QString>() << mName;
1304 return QSet<QString>();
1309 return QSet<QString>();
1314 QList<const QgsExpressionNode *> result;
1341 : mConditions( *conditions )
1342 , mElseExp( elseExp )
1350 qDeleteAll( mConditions );
1360 for (
WhenThen *cond : qgis::as_const( mConditions ) )
1362 QVariant vWhen = cond->mWhenExp->eval( parent, context );
1363 QgsExpressionUtils::TVL tvl = QgsExpressionUtils::getTVLValue( vWhen, parent );
1365 if ( tvl == QgsExpressionUtils::True )
1367 QVariant vRes = cond->mThenExp->eval( parent, context );
1375 QVariant vElse = mElseExp->
eval( parent, context );
1387 for (
WhenThen *cond : qgis::as_const( mConditions ) )
1389 res = cond->mWhenExp->prepare( parent, context )
1390 & cond->mThenExp->prepare( parent, context );
1396 return mElseExp->
prepare( parent, context );
1403 QString msg( QStringLiteral(
"CASE" ) );
1404 for (
WhenThen *cond : mConditions )
1406 msg += QStringLiteral(
" WHEN %1 THEN %2" ).arg( cond->mWhenExp->dump(), cond->mThenExp->dump() );
1409 msg += QStringLiteral(
" ELSE %1" ).arg( mElseExp->
dump() );
1410 msg += QStringLiteral(
" END" );
1417 for (
WhenThen *cond : mConditions )
1419 lst += cond->mWhenExp->referencedColumns() + cond->mThenExp->referencedColumns();
1431 for (
WhenThen *cond : mConditions )
1433 lst += cond->mWhenExp->referencedVariables() + cond->mThenExp->referencedVariables();
1445 for (
WhenThen *cond : mConditions )
1447 lst += cond->mWhenExp->referencedFunctions() + cond->mThenExp->referencedFunctions();
1458 QList<const QgsExpressionNode *> lst;
1460 for (
WhenThen *cond : mConditions )
1462 lst += cond->mWhenExp->nodes() + cond->mThenExp->nodes();
1466 lst += mElseExp->
nodes();
1473 for (
WhenThen *cond : mConditions )
1475 if ( cond->mWhenExp->needsGeometry() ||
1476 cond->mThenExp->needsGeometry() )
1487 conditions.append( wt->clone() );
1498 if ( !wt->mWhenExp->isStatic( parent, context ) || !wt->mThenExp->isStatic( parent, context ) )
1503 return mElseExp->
isStatic( parent, context );
1510 QSet<QString> lst( mNode->referencedColumns() );
1511 const QList< QgsExpressionNode * > nodeList = mList->list();
1513 lst.unite( n->referencedColumns() );
1519 QSet<QString> lst( mNode->referencedVariables() );
1520 const QList< QgsExpressionNode * > nodeList = mList->list();
1522 lst.unite( n->referencedVariables() );
1528 QSet<QString> lst( mNode->referencedFunctions() );
1529 const QList< QgsExpressionNode * > nodeList = mList->list();
1531 lst.unite( n->referencedFunctions() );
1537 QList<const QgsExpressionNode *> lst;
1539 const QList< QgsExpressionNode * > nodeList = mList->list();
1546 : mWhenExp( whenExp )
1547 , mThenExp( thenExp )
1564 return BINARY_OPERATOR_TEXT[mOp];
1571 const QVariant container = mContainer->eval( parent, context );
1573 const QVariant index = mIndex->eval( parent, context );
1576 switch ( container.type() )
1579 return QgsExpressionUtils::getMapValue( container, parent ).value( index.toString() );
1581 case QVariant::List:
1582 case QVariant::StringList:
1584 const QVariantList list = QgsExpressionUtils::getListValue( container, parent );
1585 qlonglong pos = QgsExpressionUtils::getIntValue( index, parent );
1586 if ( pos >= list.length() || pos < -list.length() )
1593 pos += list.length();
1596 return list.at( pos );
1612 bool resC = mContainer->prepare( parent, context );
1613 bool resV = mIndex->prepare( parent, context );
1614 return resC && resV;
1619 return QStringLiteral(
"%1[%2]" ).arg( mContainer->dump(), mIndex->dump() );
1624 return mContainer->referencedColumns() + mIndex->referencedColumns();
1629 return mContainer->referencedVariables() + mIndex->referencedVariables();
1634 return mContainer->referencedFunctions() + mIndex->referencedFunctions();
1639 QList<const QgsExpressionNode *> lst;
1641 lst += mContainer->nodes() + mIndex->nodes();
1647 return mContainer->needsGeometry() || mIndex->needsGeometry();
1659 return mContainer->isStatic( parent, context ) && mIndex->isStatic( parent, context );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
void cloneTo(QgsExpressionNode *target) const
Copies the members of this node to the node provided in target.
bool isValid() const
Returns the validity of this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
QStringList names() const
Returns a list of names for nodes.
QgsExpressionNode * node
Node.
virtual QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
QgsExpressionNodeFunction(int fnIndex, QgsExpressionNode::NodeList *args)
A function node consists of an index of the function in the global function array and a list of argum...
virtual QString dump() const =0
Dump this node into a serialized (part) of an expression.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QgsExpressionNodeCondition(QgsExpressionNodeCondition::WhenThenList *conditions, QgsExpressionNode *elseExp=nullptr)
Create a new node with the given list of conditions and an optional elseExp expression.
int params() const
The number of parameters this function takes.
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
int precedence() const
Returns the precedence index for the operator.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
WhenThenList conditions() const
The list of WHEN THEN expression parts of the expression.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
NodeType
Known node types.
QgsExpressionNodeInOperator(QgsExpressionNode *node, QgsExpressionNode::NodeList *list, bool notin=false)
This node tests if the result of node is in the result of list.
An expression node for CASE WHEN clauses.
double seconds() const
Returns the interval duration in seconds.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
Container of fields for a vector layer.
~QgsExpressionNodeInOperator() override
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
virtual QgsExpressionNode * clone() const =0
Generate a clone of this node.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
void setEvalErrorString(const QString &str)
Sets evaluation error (used internally by evaluation functions)
bool hasFeature() const
Returns true if the context has a feature associated with it.
QString dump() const override
Dump this node into a serialized (part) of an expression.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
QgsExpressionNode * clone() const override
Generate a clone of this node.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
#define ENSURE_NO_EVAL_ERROR
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
QString text() const
Returns a the name of this operator without the operands.
#define SET_EVAL_ERROR(x)
virtual QSet< QString > referencedColumns() const =0
Abstract virtual method which returns a list of columns required to evaluate this node...
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
virtual QSet< QString > referencedVariables() const =0
Returns a set of all variables which are used in this expression.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
const QgsExpressionFunction::ParameterList & parameters() const
Returns the list of named parameters for the function, if set.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
~QgsExpressionNodeFunction() override
An expression node for value IN or NOT IN clauses.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
QgsExpressionNode * clone() const override
Generate a clone of this node.
QgsExpressionNode * clone() const override
Generate a clone of this node.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
An expression node which takes it value from a feature's field.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
virtual QSet< QString > referencedFunctions() const =0
Returns a set of all functions which are used in this expression.
QString dump() const override
Dump this node into a serialized (part) of an expression.
Abstract base class for all nodes that can appear in an expression.
virtual QString dump() const
Returns a string dump of the expression node.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QgsExpressionNode * clone() const override
Generate a clone of this node.
~QgsExpressionNodeCondition() override
An expression node for expression functions.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
static const QList< QgsExpressionFunction * > & Functions()
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
bool lazyEval() const
true if this function should use lazy evaluation.
QString dump() const override
Dump this node into a serialized (part) of an expression.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
QList< QgsExpressionNodeCondition::WhenThen * > WhenThenList
QgsExpressionNode * clone() const override
Generate a clone of this node.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
QgsExpressionNode::NodeList * clone() const
Creates a deep copy of this list. Ownership is transferred to the caller.
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QgsExpressionNode * clone() const override
Generate a clone of this node.
QString name() const
The name of the function.
A representation of the interval between two datetime values.
virtual bool needsGeometry() const =0
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QString dump() const override
Dump this node into a serialized (part) of an expression.
int fieldNameIndex(const QString &fieldName) const
Utility method to get attribute index from name.
A abstract base class for defining QgsExpression functions.
A list of expression nodes.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
QgsExpressionNodeUnaryOperator::UnaryOperator op() const
Returns the unary operator.
QgsExpressionNode * clone() const override
Generate a clone of this node.
A indexing expression operator, which allows use of square brackets [] to reference map and array ite...
An expression node for literal values.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
A unary node is either negative as in boolean (not) or as in numbers (minus).
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
A binary expression operator, which operates on two values.
QString dump() const override
Dump this node into a serialized (part) of an expression.
WhenThen(QgsExpressionNode *whenExp, QgsExpressionNode *thenExp)
A combination of when and then.
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
QString text() const
Returns a the name of this operator without the operands.
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes)
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
QString dump() const override
Dump this node into a serialized (part) of an expression.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QgsExpressionNodeCondition::WhenThen * clone() const
Gets a deep copy of this WhenThen combination.
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
QList< const QgsExpressionNode * > nodes() const override
Returns a list of all nodes which are used in this expression.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
bool leftAssociative() const
Returns true if the operator is left-associative.
int count() const
Returns the number of nodes in the list.
bool prepareNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
void append(QgsExpressionNode *node)
Takes ownership of the provided node.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
virtual QList< const QgsExpressionNode * > nodes() const =0
Returns a list of all nodes which are used in this expression.
QgsExpressionNode * node() const
Returns the expression node.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString dump() const override
Dump this node into a serialized (part) of an expression.
QVariant evalNode(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
Represents a "WHEN... THEN..." portation of a CASE WHEN clause in an expression.
virtual bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
This will be called during the prepare step() of an expression if it is not static.
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.
bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
QgsExpressionNode * clone() const override
Generate a clone of this node.
QSet< QString > referencedFunctions() const override
Returns a set of all functions which are used in this expression.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
QSet< QString > referencedVariables() const override
Returns a set of all variables which are used in this expression.
QVariant value() const
The value of the literal.
bool hasNamedNodes() const
Returns true if list contains any named nodes.
QSet< QString > referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
int fnIndex() const
Returns the index of the node's function.
QgsExpressionNode::NodeType nodeType() const override
Gets the type of this node.
bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const override
Returns true if this node can be evaluated for a static value.
QString dump() const override
Dump this node into a serialized (part) of an expression.
static bool validateParams(int fnIndex, QgsExpressionNode::NodeList *args, QString &error)
Tests whether the provided argument list is valid for the matching function.