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 ( QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) &&
393 ( vL.type() != QVariant::String || vR.type() != QVariant::String ) )
397 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
399 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
401 return compare( fL - fR ) ? TVL_True : TVL_False;
406 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
408 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
410 int diff = QString::compare( sL, sR );
411 return compare( diff ) ? TVL_True : TVL_False;
416 if ( QgsExpressionUtils::isNull( vL ) && QgsExpressionUtils::isNull( vR ) )
417 return ( mOp == boIs ? TVL_True : TVL_False );
418 else if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
419 return ( mOp == boIs ? TVL_False : TVL_True );
423 if ( QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) &&
424 ( vL.type() != QVariant::String || vR.type() != QVariant::String ) )
426 double fL = QgsExpressionUtils::getDoubleValue( vL, parent );
428 double fR = QgsExpressionUtils::getDoubleValue( vR, parent );
434 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
436 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
438 equal = QString::compare( sL, sR ) == 0;
441 return mOp == boIs ? TVL_True : TVL_False;
443 return mOp == boIs ? TVL_False : TVL_True;
451 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
455 QString str = QgsExpressionUtils::getStringValue( vL, parent );
457 QString regexp = QgsExpressionUtils::getStringValue( vR, parent );
461 if ( mOp == boLike || mOp == boILike || mOp == boNotLike || mOp == boNotILike )
463 QString esc_regexp = QRegExp::escape( regexp );
465 if ( esc_regexp.startsWith(
'%' ) )
467 esc_regexp.replace( 0, 1, QStringLiteral(
".*" ) );
469 QRegExp rx(
"[^\\\\](%)" );
471 while ( ( pos = rx.indexIn( esc_regexp, pos ) ) != -1 )
473 esc_regexp.replace( pos + 1, 1, QStringLiteral(
".*" ) );
476 rx.setPattern( QStringLiteral(
"\\\\%" ) );
477 esc_regexp.replace( rx, QStringLiteral(
"%" ) );
478 if ( esc_regexp.startsWith(
'_' ) )
480 esc_regexp.replace( 0, 1, QStringLiteral(
"." ) );
482 rx.setPattern( QStringLiteral(
"[^\\\\](_)" ) );
484 while ( ( pos = rx.indexIn( esc_regexp, pos ) ) != -1 )
486 esc_regexp.replace( pos + 1, 1,
'.' );
489 rx.setPattern( QStringLiteral(
"\\\\_" ) );
490 esc_regexp.replace( rx, QStringLiteral(
"_" ) );
491 matches = QRegExp( esc_regexp, mOp == boLike || mOp == boNotLike ? Qt::CaseSensitive : Qt::CaseInsensitive ).exactMatch( str );
495 matches = QRegExp( regexp ).indexIn( str ) != -1;
498 if ( mOp == boNotLike || mOp == boNotILike )
503 return matches ? TVL_True : TVL_False;
507 if ( QgsExpressionUtils::isNull( vL ) || QgsExpressionUtils::isNull( vR ) )
511 QString sL = QgsExpressionUtils::getStringValue( vL, parent );
513 QString sR = QgsExpressionUtils::getStringValue( vR, parent );
515 return QVariant( sL + sR );
525 bool QgsExpressionNodeBinaryOperator::compare(
double diff )
547 qlonglong QgsExpressionNodeBinaryOperator::computeInt( qlonglong x, qlonglong y )
567 QDateTime QgsExpressionNodeBinaryOperator::computeDateTimeFromInterval(
const QDateTime &d,
QgsInterval *i )
572 return d.addSecs( i->
seconds() );
574 return d.addSecs( -i->
seconds() );
581 double QgsExpressionNodeBinaryOperator::computeDouble(
double x,
double y )
594 return std::fmod( x, y );
608 bool resL = mOpLeft->prepare( parent, context );
609 bool resR = mOpRight->prepare( parent, context );
655 Q_ASSERT(
false &&
"unexpected binary operator" );
691 Q_ASSERT(
false &&
"unexpected binary operator" );
701 QString rdump( mOpRight->dump() );
706 rdump.prepend(
'(' ).append(
')' );
710 if ( leftAssociative() )
712 fmt += lOp && ( lOp->
precedence() < precedence() ) ? QStringLiteral(
"(%1)" ) : QStringLiteral(
"%1" );
713 fmt += QLatin1String(
" %2 " );
714 fmt += rOp && ( rOp->
precedence() <= precedence() ) ? QStringLiteral(
"(%3)" ) : QStringLiteral(
"%3" );
718 fmt += lOp && ( lOp->
precedence() <= precedence() ) ? QStringLiteral(
"(%1)" ) : QStringLiteral(
"%1" );
719 fmt += QLatin1String(
" %2 " );
720 fmt += rOp && ( rOp->
precedence() < precedence() ) ? QStringLiteral(
"(%3)" ) : QStringLiteral(
"%3" );
723 return fmt.arg( mOpLeft->dump(), BINARY_OPERATOR_TEXT[mOp], rdump );
728 return mOpLeft->referencedColumns() + mOpRight->referencedColumns();
733 return mOpLeft->referencedVariables() + mOpRight->referencedVariables();
738 return mOpLeft->referencedFunctions() + mOpRight->referencedFunctions();
743 QList<const QgsExpressionNode *> lst;
745 lst += mOpLeft->nodes() + mOpRight->nodes();
751 return mOpLeft->needsGeometry() || mOpRight->needsGeometry();
763 return mOpLeft->isStatic( parent, context ) && mOpRight->isStatic( parent, context );
770 if ( mList->
count() == 0 )
771 return mNotIn ? TVL_True : TVL_False;
772 QVariant v1 = mNode->
eval( parent, context );
774 if ( QgsExpressionUtils::isNull( v1 ) )
777 bool listHasNull =
false;
779 const QList< QgsExpressionNode * > nodeList = mList->
list();
782 QVariant v2 = n->eval( parent, context );
784 if ( QgsExpressionUtils::isNull( v2 ) )
790 if ( QgsExpressionUtils::isDoubleSafe( v1 ) && QgsExpressionUtils::isDoubleSafe( v2 ) )
792 double f1 = QgsExpressionUtils::getDoubleValue( v1, parent );
794 double f2 = QgsExpressionUtils::getDoubleValue( v2, parent );
800 QString s1 = QgsExpressionUtils::getStringValue( v1, parent );
802 QString s2 = QgsExpressionUtils::getStringValue( v2, parent );
804 equal = QString::compare( s1, s2 ) == 0;
808 return mNotIn ? TVL_False : TVL_True;
816 return mNotIn ? TVL_True : TVL_False;
832 bool res = mNode->
prepare( parent, context );
833 const QList< QgsExpressionNode * > nodeList = mList->
list();
836 res = res && n->prepare( parent, context );
843 return QStringLiteral(
"%1 %2 IN (%3)" ).arg( mNode->
dump(), mNotIn ?
"NOT" :
"", mList->
dump() );
855 if ( !mNode->
isStatic( parent, context ) )
858 const QList< QgsExpressionNode * > nodeList = mList->
list();
861 if ( !n->isStatic( parent, context ) )
872 QString name = QgsExpression::QgsExpression::Functions()[mFnIndex]->name();
875 QVariant res = fd->
run( mArgs, context, parent,
this );
883 : mFnIndex( fnIndex )
886 if ( !args || functionParams.isEmpty() )
897 while ( idx < args->names().size() && args->
names().at( idx ).isEmpty() )
899 mArgs->
append( args->
list().at( idx )->clone() );
904 for ( ; idx < functionParams.count(); ++idx )
906 int nodeIdx = args->
names().indexOf( functionParams.at( idx ).name().toLower() );
914 mArgs->
append( args->
list().at( nodeIdx )->clone() );
936 bool res = fd->
prepare(
this, parent, context );
939 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
942 res = res && n->prepare( parent, context );
952 return QStringLiteral(
"%1%2" ).arg( fd->
name(), fd->
name().startsWith(
'$' ) ?
"" :
"()" );
954 return QStringLiteral(
"%1(%2)" ).arg( fd->
name(), mArgs ? mArgs->
dump() : QString() );
965 return functionColumns;
969 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
972 if ( fd->
parameters().count() <= paramIndex || !fd->
parameters().at( paramIndex ).isSubExpression() )
973 functionColumns.unite( n->referencedColumns() );
977 return functionColumns;
983 if ( fd->
name() == QLatin1String(
"var" ) )
985 if ( !mArgs->
list().isEmpty() )
989 return QSet<QString>() << var->
value().toString();
991 return QSet<QString>() << QString();
995 QSet<QString> functionVariables = QSet<QString>();
998 return functionVariables;
1000 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1003 functionVariables.unite( n->referencedVariables() );
1006 return functionVariables;
1013 QSet<QString> functions = QSet<QString>();
1014 functions.insert( fd->
name() );
1019 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1022 functions.unite( n->referencedFunctions() );
1029 QList<const QgsExpressionNode *> lst;
1034 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1044 bool needs = QgsExpression::QgsExpression::Functions()[mFnIndex]->usesGeometry(
this );
1047 const QList< QgsExpressionNode * > nodeList = mArgs->
list();
1049 needs |= n->needsGeometry();
1072 if ( functionParams.isEmpty() )
1074 error = QStringLiteral(
"%1 does not support named QgsExpressionFunction::Parameters" ).arg(
QgsExpression::Functions()[fnIndex]->name() );
1079 QSet< int > providedArgs;
1080 QSet< int > handledArgs;
1083 while ( args->
names().at( idx ).isEmpty() )
1085 providedArgs << idx;
1091 for ( ; idx < functionParams.count(); ++idx )
1093 int nodeIdx = args->
names().indexOf( functionParams.at( idx ).name().toLower() );
1096 if ( !functionParams.at( idx ).optional() )
1098 error = QStringLiteral(
"No value specified for QgsExpressionFunction::Parameter '%1' for %2" ).arg( functionParams.at( idx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1104 if ( providedArgs.contains( idx ) )
1106 error = QStringLiteral(
"Duplicate QgsExpressionFunction::Parameter specified for '%1' for %2" ).arg( functionParams.at( idx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1110 providedArgs << idx;
1111 handledArgs << nodeIdx;
1116 const QStringList nameList = args->
names();
1117 for (
const QString &name : nameList )
1119 if ( !name.isEmpty() && !functionParams.contains( name ) )
1121 error = QStringLiteral(
"Invalid QgsExpressionFunction::Parameter name '%1' for %2" ).arg( name,
QgsExpression::Functions()[fnIndex]->name() );
1124 if ( !name.isEmpty() && !handledArgs.contains( idx ) )
1126 int functionIdx = functionParams.indexOf( name );
1127 if ( providedArgs.contains( functionIdx ) )
1129 error = QStringLiteral(
"Duplicate QgsExpressionFunction::Parameter specified for '%1' for %2" ).arg( functionParams.at( functionIdx ).name(),
QgsExpression::Functions()[
fnIndex]->name() );
1164 if ( mValue.isNull() )
1165 return QStringLiteral(
"NULL" );
1167 switch ( mValue.type() )
1170 return QString::number( mValue.toInt() );
1171 case QVariant::Double:
1172 return QString::number( mValue.toDouble() );
1173 case QVariant::LongLong:
1174 return QString::number( mValue.toLongLong() );
1175 case QVariant::String:
1177 case QVariant::Bool:
1178 return mValue.toBool() ? QStringLiteral(
"TRUE" ) : QStringLiteral(
"FALSE" );
1180 return tr(
"[unsupported type: %1; value: %2]" ).arg( mValue.typeName(), mValue.toString() );
1186 return QSet<QString>();
1191 return QSet<QString>();
1196 return QSet<QString>();
1201 QList<const QgsExpressionNode *> lst;
1253 return QVariant(
'[' + mName +
']' );
1290 return QSet<QString>() << mName;
1295 return QSet<QString>();
1300 return QSet<QString>();
1305 QList<const QgsExpressionNode *> result;
1332 : mConditions( *conditions )
1333 , mElseExp( elseExp )
1341 qDeleteAll( mConditions );
1351 for (
WhenThen *cond : qgis::as_const( mConditions ) )
1353 QVariant vWhen = cond->mWhenExp->eval( parent, context );
1354 QgsExpressionUtils::TVL tvl = QgsExpressionUtils::getTVLValue( vWhen, parent );
1356 if ( tvl == QgsExpressionUtils::True )
1358 QVariant vRes = cond->mThenExp->eval( parent, context );
1366 QVariant vElse = mElseExp->
eval( parent, context );
1378 for (
WhenThen *cond : qgis::as_const( mConditions ) )
1380 res = cond->mWhenExp->prepare( parent, context )
1381 & cond->mThenExp->prepare( parent, context );
1387 return mElseExp->
prepare( parent, context );
1394 QString msg( QStringLiteral(
"CASE" ) );
1395 for (
WhenThen *cond : mConditions )
1397 msg += QStringLiteral(
" WHEN %1 THEN %2" ).arg( cond->mWhenExp->dump(), cond->mThenExp->dump() );
1400 msg += QStringLiteral(
" ELSE %1" ).arg( mElseExp->
dump() );
1401 msg += QStringLiteral(
" END" );
1408 for (
WhenThen *cond : mConditions )
1410 lst += cond->mWhenExp->referencedColumns() + cond->mThenExp->referencedColumns();
1422 for (
WhenThen *cond : mConditions )
1424 lst += cond->mWhenExp->referencedVariables() + cond->mThenExp->referencedVariables();
1436 for (
WhenThen *cond : mConditions )
1438 lst += cond->mWhenExp->referencedFunctions() + cond->mThenExp->referencedFunctions();
1449 QList<const QgsExpressionNode *> lst;
1451 for (
WhenThen *cond : mConditions )
1453 lst += cond->mWhenExp->nodes() + cond->mThenExp->nodes();
1457 lst += mElseExp->
nodes();
1464 for (
WhenThen *cond : mConditions )
1466 if ( cond->mWhenExp->needsGeometry() ||
1467 cond->mThenExp->needsGeometry() )
1478 conditions.append( wt->clone() );
1489 if ( !wt->mWhenExp->isStatic( parent, context ) || !wt->mThenExp->isStatic( parent, context ) )
1494 return mElseExp->
isStatic( parent, context );
1501 QSet<QString> lst( mNode->referencedColumns() );
1502 const QList< QgsExpressionNode * > nodeList = mList->list();
1504 lst.unite( n->referencedColumns() );
1510 QSet<QString> lst( mNode->referencedVariables() );
1511 const QList< QgsExpressionNode * > nodeList = mList->list();
1513 lst.unite( n->referencedVariables() );
1519 QSet<QString> lst( mNode->referencedFunctions() );
1520 const QList< QgsExpressionNode * > nodeList = mList->list();
1522 lst.unite( n->referencedFunctions() );
1528 QList<const QgsExpressionNode *> lst;
1530 const QList< QgsExpressionNode * > nodeList = mList->list();
1537 : mWhenExp( whenExp )
1538 , mThenExp( thenExp )
1555 return BINARY_OPERATOR_TEXT[mOp];
1562 const QVariant container = mContainer->eval( parent, context );
1564 const QVariant index = mIndex->eval( parent, context );
1567 switch ( container.type() )
1570 return QgsExpressionUtils::getMapValue( container, parent ).value( index.toString() );
1572 case QVariant::List:
1573 case QVariant::StringList:
1575 const QVariantList list = QgsExpressionUtils::getListValue( container, parent );
1576 qlonglong pos = QgsExpressionUtils::getIntValue( index, parent );
1577 if ( pos >= list.length() || pos < -list.length() )
1584 pos += list.length();
1587 return list.at( pos );
1603 bool resC = mContainer->prepare( parent, context );
1604 bool resV = mIndex->prepare( parent, context );
1605 return resC && resV;
1610 return QStringLiteral(
"%1[%2]" ).arg( mContainer->dump(), mIndex->dump() );
1615 return mContainer->referencedColumns() + mIndex->referencedColumns();
1620 return mContainer->referencedVariables() + mIndex->referencedVariables();
1625 return mContainer->referencedFunctions() + mIndex->referencedFunctions();
1630 QList<const QgsExpressionNode *> lst;
1632 lst += mContainer->nodes() + mIndex->nodes();
1638 return mContainer->needsGeometry() || mIndex->needsGeometry();
1650 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.