83 QVariantList argValues;
87 const QList< QgsExpressionNode * > argList = args->
list();
94 v = QVariant::fromValue( n );
98 v = n->eval( parent, context );
100 bool defaultParamIsNull = mParameterList.count() > arg && mParameterList.at( arg ).optional() && !mParameterList.at( arg ).defaultValue().isValid();
101 if ( QgsExpressionUtils::isNull( v ) && !defaultParamIsNull && !
handlesNull() )
104 argValues.append( v );
109 return func( argValues, context, parent, node );
120 return QStringList();
147 return mGroups.isEmpty() ? false : mGroups.contains( QStringLiteral(
"deprecated" ) );
152 return ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 );
164 const QString &group,
165 const QString &helpText,
169 const QStringList &aliases,
173 , mAliases( aliases )
174 , mUsesGeometry( false )
175 , mUsesGeometryFunc( usesGeometry )
176 , mReferencedColumnsFunc( referencedColumns )
188 if ( mUsesGeometryFunc )
189 return mUsesGeometryFunc( node );
191 return mUsesGeometry;
196 if ( mReferencedColumnsFunc )
197 return mReferencedColumnsFunc( node );
199 return mReferencedColumns;
205 return mIsStaticFunc( node, parent, context );
213 return mPrepareFunc( node, parent, context );
225 mIsStaticFunc =
nullptr;
231 mPrepareFunc = prepareFunc;
236 if ( node && node->
args() )
238 const QList< QgsExpressionNode * > argList = node->
args()->
list();
241 if ( !argNode->isStatic( parent, context ) )
251 double start = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
252 double stop = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
253 double step = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
255 if ( step == 0.0 || ( step > 0.0 && start > stop ) || ( step < 0.0 && start < stop ) )
262 double current = start + step;
263 while ( ( ( step > 0.0 && current <= stop ) || ( step < 0.0 && current >= stop ) ) && length <= 1000000 )
278 QString name = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
284 QString templateString = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
293 QString expString = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
295 return expression.evaluate( context );
300 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
301 return QVariant( std::sqrt( x ) );
306 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
307 return QVariant( std::fabs( val ) );
312 double deg = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
313 return ( deg * M_PI ) / 180;
317 double rad = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
318 return ( 180 * rad ) / M_PI;
322 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
323 return QVariant( std::sin( x ) );
327 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
328 return QVariant( std::cos( x ) );
332 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
333 return QVariant( std::tan( x ) );
337 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
338 return QVariant( std::asin( x ) );
342 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
343 return QVariant( std::acos( x ) );
347 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
348 return QVariant( std::atan( x ) );
352 double y = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
353 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
354 return QVariant( std::atan2( y, x ) );
358 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
359 return QVariant( std::exp( x ) );
363 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
366 return QVariant( std::log( x ) );
370 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
373 return QVariant( log10( x ) );
377 double b = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
378 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
379 if ( x <= 0 || b <= 0 )
381 return QVariant( std::log( x ) / std::log( b ) );
385 double min = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
386 double max = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
390 std::random_device rd;
391 std::mt19937_64 generator( rd() );
393 if ( !QgsExpressionUtils::isNull( values.at( 2 ) ) )
396 if ( QgsExpressionUtils::isIntSafe( values.at( 2 ) ) )
399 seed = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
404 QString seedStr = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
405 std::hash<std::string> hasher;
406 seed = hasher( seedStr.toStdString() );
408 generator.seed( seed );
412 double f =
static_cast< double >( generator() ) /
static_cast< double >( generator.max() );
413 return QVariant( min + f * ( max - min ) );
417 qlonglong min = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
418 qlonglong max = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
422 std::random_device rd;
423 std::mt19937_64 generator( rd() );
425 if ( !QgsExpressionUtils::isNull( values.at( 2 ) ) )
428 if ( QgsExpressionUtils::isIntSafe( values.at( 2 ) ) )
431 seed = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
436 QString seedStr = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
437 std::hash<std::string> hasher;
438 seed = hasher( seedStr.toStdString() );
440 generator.seed( seed );
443 qint64 randomInteger = min + ( generator() % ( max - min + 1 ) );
444 if ( randomInteger > std::numeric_limits<int>::max() || randomInteger < -std::numeric_limits<int>::max() )
445 return QVariant( randomInteger );
448 return QVariant(
int( randomInteger ) );
453 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
454 double domainMin = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
455 double domainMax = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
456 double rangeMin = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
457 double rangeMax = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
459 if ( domainMin >= domainMax )
461 parent->
setEvalErrorString( QObject::tr(
"Domain max must be greater than domain min" ) );
466 if ( val >= domainMax )
470 else if ( val <= domainMin )
476 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
477 double c = rangeMin - ( domainMin * m );
480 return QVariant( m * val +
c );
485 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
486 double domainMin = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
487 double domainMax = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
488 double rangeMin = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
489 double rangeMax = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
490 double exponent = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
492 if ( domainMin >= domainMax )
494 parent->
setEvalErrorString( QObject::tr(
"Domain max must be greater than domain min" ) );
504 if ( val >= domainMax )
508 else if ( val <= domainMin )
514 return QVariant( ( ( rangeMax - rangeMin ) / std::pow( domainMax - domainMin, exponent ) ) * std::pow( val - domainMin, exponent ) + rangeMin );
519 QVariant result( QVariant::Double );
520 double maxVal = std::numeric_limits<double>::quiet_NaN();
521 for (
const QVariant &val : values )
523 double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
524 if ( std::isnan( maxVal ) )
528 else if ( !std::isnan( testVal ) )
530 maxVal = std::max( maxVal, testVal );
534 if ( !std::isnan( maxVal ) )
536 result = QVariant( maxVal );
543 QVariant result( QVariant::Double );
544 double minVal = std::numeric_limits<double>::quiet_NaN();
545 for (
const QVariant &val : values )
547 double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
548 if ( std::isnan( minVal ) )
552 else if ( !std::isnan( testVal ) )
554 minVal = std::min( minVal, testVal );
558 if ( !std::isnan( minVal ) )
560 result = QVariant( minVal );
572 QVariant value = node->
eval( parent, context );
574 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( value, parent );
577 parent->
setEvalErrorString( QObject::tr(
"Cannot find layer with name or ID '%1'" ).arg( value.toString() ) );
582 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
584 value = node->
eval( parent, context );
590 parent->
setEvalErrorString( QObject::tr(
"No such aggregate '%1'" ).arg( value.toString() ) );
595 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
597 QString subExpression = node->
dump();
601 if ( values.count() > 3 )
603 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
606 if ( !nl || nl->value().isValid() )
611 if ( values.count() > 4 )
613 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
615 value = node->
eval( parent, context );
622 if ( values.count() > 5 )
624 node = QgsExpressionUtils::getNode( values.at( 5 ), parent );
627 if ( !nl || nl->value().isValid() )
629 orderBy = node->
dump();
641 bool isStatic =
true;
642 if ( filterExp.referencedVariables().contains( QStringLiteral(
"parent" ) )
643 || filterExp.referencedVariables().contains( QString() )
644 || subExp.referencedVariables().contains( QStringLiteral(
"parent" ) )
645 || subExp.referencedVariables().contains( QString() ) )
651 const QSet<QString> refVars = filterExp.referencedVariables() + subExp.referencedVariables();
652 for (
const QString &varName : refVars )
655 if ( scope && !scope->
isStatic( varName ) )
665 cacheKey = QStringLiteral(
"aggfcn:%1:%2:%3:%4:%5%6:%7" ).arg( vl->id(), QString::number( aggregate ), subExpression, parameters.
filter,
670 cacheKey = QStringLiteral(
"aggfcn:%1:%2:%3:%4:%5" ).arg( vl->id(), QString::number( aggregate ), subExpression, parameters.
filter, orderBy );
681 subContext.appendScope( subScope );
682 result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok );
688 result = vl->aggregate( aggregate, subExpression, parameters,
nullptr, &ok );
692 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
703 parent->
setEvalErrorString( QObject::tr(
"Cannot use relation aggregate function in this context" ) );
708 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
711 parent->
setEvalErrorString( QObject::tr(
"Cannot use relation aggregate function in this context" ) );
720 QVariant value = node->
eval( parent, context );
722 QString relationId = value.toString();
729 if ( relations.isEmpty() || relations.at( 0 ).referencedLayer() != vl )
731 parent->
setEvalErrorString( QObject::tr(
"Cannot find relation with id '%1'" ).arg( relationId ) );
736 relation = relations.at( 0 );
743 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
745 value = node->
eval( parent, context );
751 parent->
setEvalErrorString( QObject::tr(
"No such aggregate '%1'" ).arg( value.toString() ) );
756 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
758 QString subExpression = node->
dump();
762 if ( values.count() > 3 )
764 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
766 value = node->
eval( parent, context );
773 if ( values.count() > 4 )
775 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
778 if ( !nl || nl->value().isValid() )
780 orderBy = node->
dump();
791 QString cacheKey = QStringLiteral(
"relagg:%1:%2:%3:%4:%5" ).arg( vl->
id(),
792 QString::number(
static_cast< int >( aggregate ) ),
804 result = childLayer->
aggregate( aggregate, subExpression, parameters, &subContext, &ok );
808 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
822 parent->
setEvalErrorString( QObject::tr(
"Cannot use aggregate function in this context" ) );
827 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
830 parent->
setEvalErrorString( QObject::tr(
"Cannot use aggregate function in this context" ) );
839 QString subExpression = node->
dump();
843 if ( values.count() > 1 )
845 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
848 if ( !nl || nl->value().isValid() )
849 groupBy = node->
dump();
853 if ( values.count() > 2 )
855 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
858 if ( !nl || nl->value().isValid() )
864 if ( orderByPos >= 0 && values.count() > orderByPos )
866 node = QgsExpressionUtils::getNode( values.at( orderByPos ), parent );
869 if ( !nl || nl->value().isValid() )
871 orderBy = node->
dump();
879 if ( !groupBy.isEmpty() )
882 QVariant groupByValue = groupByExp.evaluate( context );
883 QString groupByClause = QStringLiteral(
"%1 %2 %3" ).arg( groupBy,
884 groupByValue.isNull() ? QStringLiteral(
"is" ) : QStringLiteral(
"=" ),
886 if ( !parameters.
filter.isEmpty() )
887 parameters.
filter = QStringLiteral(
"(%1) AND (%2)" ).arg( parameters.
filter, groupByClause );
889 parameters.
filter = groupByClause;
895 bool isStatic =
true;
896 const QSet<QString> refVars = filterExp.referencedVariables() + subExp.referencedVariables();
897 for (
const QString &varName : refVars )
900 if ( scope && !scope->
isStatic( varName ) )
910 cacheKey = QStringLiteral(
"agg:%1:%2:%3:%4:%5%6:%7" ).arg( vl->
id(), QString::number( aggregate ), subExpression, parameters.
filter,
915 cacheKey = QStringLiteral(
"agg:%1:%2:%3:%4:%5" ).arg( vl->
id(), QString::number( aggregate ), subExpression, parameters.
filter, orderBy );
927 subContext.appendScope( subScope );
928 result = vl->
aggregate( aggregate, subExpression, parameters, &subContext, &ok );
932 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
1037 if ( values.count() > 3 )
1039 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
1041 QVariant value = node->
eval( parent, context );
1043 parameters.
delimiter = value.toString();
1054 if ( values.count() > 3 )
1056 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
1058 QVariant value = node->
eval( parent, context );
1060 parameters.
delimiter = value.toString();
1076 QVariant scale = context->
variable( QStringLiteral(
"map_scale" ) );
1078 if ( !scale.isValid() || scale.isNull() )
1081 const double v = scale.toDouble( &ok );
1089 double minValue = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1090 double testValue = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
1091 double maxValue = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1094 if ( testValue <= minValue )
1096 return QVariant( minValue );
1098 else if ( testValue >= maxValue )
1100 return QVariant( maxValue );
1104 return QVariant( testValue );
1110 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1111 return QVariant( std::floor( x ) );
1116 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1117 return QVariant( std::ceil( x ) );
1122 return QVariant( QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) );
1126 return QVariant( QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent ) );
1130 return QVariant( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ) );
1135 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1136 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1137 if ( format.isEmpty() && !language.isEmpty() )
1139 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to DateTime when the language is specified" ) );
1140 return QVariant( QDateTime() );
1143 if ( format.isEmpty() && language.isEmpty() )
1144 return QVariant( QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent ) );
1146 QString datetimestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1147 QLocale locale = QLocale();
1148 if ( !language.isEmpty() )
1150 locale = QLocale( language );
1153 QDateTime datetime = locale.toDateTime( datetimestring, format );
1154 if ( !datetime.isValid() )
1156 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to DateTime" ).arg( datetimestring ) );
1157 datetime = QDateTime();
1159 return QVariant( datetime );
1164 const int year = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1165 const int month = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1166 const int day = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
1168 const QDate date( year, month, day );
1169 if ( !date.isValid() )
1171 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid date" ).arg( year ).arg( month ).arg( day ) );
1174 return QVariant( date );
1179 const int hours = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1180 const int minutes = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1181 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1183 const QTime time( hours, minutes, std::floor( seconds ), ( seconds - std::floor( seconds ) ) * 1000 );
1184 if ( !time.isValid() )
1186 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid time" ).arg( hours ).arg( minutes ).arg( seconds ) );
1189 return QVariant( time );
1194 const int year = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1195 const int month = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1196 const int day = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
1197 const int hours = QgsExpressionUtils::getIntValue( values.at( 3 ), parent );
1198 const int minutes = QgsExpressionUtils::getIntValue( values.at( 4 ), parent );
1199 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
1201 const QDate date( year, month, day );
1202 if ( !date.isValid() )
1204 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid date" ).arg( year ).arg( month ).arg( day ) );
1207 const QTime time( hours, minutes, std::floor( seconds ), ( seconds - std::floor( seconds ) ) * 1000 );
1208 if ( !time.isValid() )
1210 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid time" ).arg( hours ).arg( minutes ).arg( seconds ) );
1213 return QVariant( QDateTime( date, time ) );
1218 const double years = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1219 const double months = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
1220 const double weeks = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1221 const double days = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
1222 const double hours = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
1223 const double minutes = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
1224 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 6 ), parent );
1226 return QVariant::fromValue(
QgsInterval( years, months, weeks, days, hours, minutes, seconds ) );
1231 for (
const QVariant &value : values )
1233 if ( value.isNull() )
1242 const QVariant val1 = values.at( 0 );
1243 const QVariant val2 = values.at( 1 );
1253 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1254 return QVariant( str.toLower() );
1258 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1259 return QVariant( str.toUpper() );
1263 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1264 QStringList elems = str.split(
' ' );
1265 for (
int i = 0; i < elems.size(); i++ )
1267 if ( elems[i].size() > 1 )
1268 elems[i] = elems[i].at( 0 ).toUpper() + elems[i].mid( 1 ).toLower();
1270 return QVariant( elems.join( QLatin1Char(
' ' ) ) );
1275 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1276 return QVariant( str.trimmed() );
1281 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1282 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1288 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1289 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1295 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1296 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1303 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1309 QChar character = QChar( QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent ) );
1310 return QVariant( QString( character ) );
1315 QString value = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1317 if ( value.isEmpty() )
1322 int res = value.at( 0 ).unicode();
1323 return QVariant( res );
1328 if ( values.length() == 2 || values.length() == 3 )
1330 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1331 qlonglong wrap = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1333 QString customdelimiter = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1347 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
1351 return QVariant( geom.
length() );
1355 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1356 return QVariant( str.length() );
1361 if ( values.count() == 2 && values.at( 1 ).type() == QVariant::Map )
1363 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1364 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 1 ), parent );
1366 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
1368 str = str.replace( it.key(), it.value().toString() );
1371 return QVariant( str );
1373 else if ( values.count() == 3 )
1375 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1376 QVariantList before;
1378 bool isSingleReplacement =
false;
1380 if ( values.at( 1 ).type() != QVariant::List && values.at( 2 ).type() != QVariant::StringList )
1382 before = QVariantList() << QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1386 before = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
1389 if ( values.at( 2 ).type() != QVariant::List && values.at( 2 ).type() != QVariant::StringList )
1391 after = QVariantList() << QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1392 isSingleReplacement =
true;
1396 after = QgsExpressionUtils::getListValue( values.at( 2 ), parent );
1399 if ( !isSingleReplacement && before.length() != after.length() )
1401 parent->
setEvalErrorString( QObject::tr(
"Invalid pair of array, length not identical" ) );
1405 for (
int i = 0; i < before.length(); i++ )
1407 str = str.replace( before.at( i ).toString(), after.at( isSingleReplacement ? 0 : i ).toString() );
1410 return QVariant( str );
1414 parent->
setEvalErrorString( QObject::tr(
"Function replace requires 2 or 3 arguments" ) );
1420 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1421 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1422 QString after = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1424 QRegularExpression re( regexp );
1425 if ( !re.isValid() )
1427 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1430 return QVariant( str.replace( re, after ) );
1435 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1436 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1438 QRegularExpression re( regexp );
1439 if ( !re.isValid() )
1441 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1444 return QVariant( ( str.indexOf( re ) + 1 ) );
1449 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1450 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1451 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1453 QRegularExpression re( regexp );
1454 if ( !re.isValid() )
1456 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1460 QRegularExpressionMatch matches = re.match( str );
1461 if ( matches.hasMatch() )
1464 QStringList list = matches.capturedTexts();
1467 for ( QStringList::const_iterator it = ++list.constBegin(); it != list.constEnd(); ++it )
1469 array += ( !( *it ).isEmpty() ) ? *it : empty;
1472 return QVariant( array );
1482 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1483 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1485 QRegularExpression re( regexp );
1486 if ( !re.isValid() )
1488 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1493 QRegularExpressionMatch match = re.match( str );
1494 if ( match.hasMatch() )
1497 if ( match.lastCapturedIndex() > 0 )
1500 return QVariant( match.captured( 1 ) );
1505 return QVariant( match.captured( 0 ) );
1510 return QVariant(
"" );
1516 return QUuid::createUuid().toString();
1521 if ( !values.at( 0 ).isValid() || !values.at( 1 ).isValid() )
1524 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1525 int from = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1528 if ( values.at( 2 ).isValid() )
1529 len = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
1535 from = str.size() + from;
1541 else if ( from > 0 )
1549 len = str.size() + len - from;
1556 return QVariant( str.mid( from, len ) );
1562 return QVariant(
static_cast< int >( f.
id() ) );
1567 QgsRasterLayer *layer = QgsExpressionUtils::getRasterLayer( values.at( 0 ), parent );
1570 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid raster layer." ) );
1574 int bandNb = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1575 if ( bandNb < 1 || bandNb > layer->
bandCount() )
1577 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid raster band number." ) );
1581 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 2 ), parent );
1584 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid point geometry." ) );
1592 if ( multiPoint.count() == 1 )
1594 point = multiPoint[0];
1604 return std::isnan( value ) ? QVariant() : value;
1619 if ( values.size() == 1 )
1621 attr = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1624 else if ( values.size() == 2 )
1626 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1627 attr = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1631 parent->
setEvalErrorString( QObject::tr(
"Function `attribute` requires one or two parameters. %1 given." ).arg( values.length() ) );
1641 if ( values.size() == 0 || values.at( 0 ).isNull() )
1647 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1652 for (
int i = 0; i < fields.
count(); ++i )
1663 bool evaluate =
true;
1665 if ( values.isEmpty() )
1668 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1670 else if ( values.size() == 1 )
1672 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1673 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1675 else if ( values.size() == 2 )
1677 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1678 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1680 else if ( values.size() == 3 )
1682 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1683 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1684 evaluate = values.value( 2 ).toBool();
1690 parent->
setEvalErrorString( QObject::tr(
"Function `maptip` requires no more than three parameters. %1 given." ).arg( values.length() ) );
1694 parent->
setEvalErrorString( QObject::tr(
"Function `display` requires no more than three parameters. %1 given." ).arg( values.length() ) );
1725 subContext.setFeature( feature );
1734 exp.prepare( &subContext );
1735 return exp.evaluate( &subContext ).toString();
1741 return fcnCoreFeatureMaptipDisplay( values, context, parent,
false );
1746 return fcnCoreFeatureMaptipDisplay( values, context, parent,
true );
1754 if ( values.isEmpty() )
1757 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1759 else if ( values.size() == 1 )
1761 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1762 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1764 else if ( values.size() == 2 )
1766 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1767 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1771 parent->
setEvalErrorString( QObject::tr(
"Function `is_selected` requires no more than two parameters. %1 given." ).arg( values.length() ) );
1775 if ( !layer || !feature.
isValid() )
1777 return QVariant( QVariant::Bool );
1787 if ( values.isEmpty() )
1788 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1789 else if ( values.count() == 1 )
1790 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1793 parent->
setEvalErrorString( QObject::tr(
"Function `num_selected` requires no more than one parameter. %1 given." ).arg( values.length() ) );
1799 return QVariant( QVariant::LongLong );
1807 static QMap<QString, qlonglong> counterCache;
1808 QVariant functionResult;
1810 std::function<void()> fetchAndIncrementFunc = [ =, &functionResult ]()
1813 const QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1818 database = decodedUri.value( QStringLiteral(
"path" ) ).toString();
1819 if ( database.isEmpty() )
1821 parent->
setEvalErrorString( QObject::tr(
"Could not extract file path from layer `%1`." ).arg( layer->
name() ) );
1826 database = values.at( 0 ).toString();
1829 const QString table = values.at( 1 ).toString();
1830 const QString idColumn = values.at( 2 ).toString();
1831 const QString filterAttribute = values.at( 3 ).toString();
1832 const QVariant filterValue = values.at( 4 ).toString();
1833 const QVariantMap defaultValues = values.at( 5 ).toMap();
1839 if ( sqliteDb.
open_v2( database, SQLITE_OPEN_READWRITE,
nullptr ) != SQLITE_OK )
1842 functionResult = QVariant();
1846 QString errorMessage;
1847 QString currentValSql;
1849 qlonglong nextId = 0;
1850 bool cachedMode =
false;
1851 bool valueRetrieved =
false;
1853 QString cacheString = QStringLiteral(
"%1:%2:%3:%4:%5" ).arg( database, table, idColumn, filterAttribute, filterValue.toString() );
1860 auto cachedCounter = counterCache.find( cacheString );
1862 if ( cachedCounter != counterCache.end() )
1864 qlonglong &cachedValue = cachedCounter.value();
1865 nextId = cachedValue;
1867 cachedValue = nextId;
1868 valueRetrieved =
true;
1873 if ( !cachedMode || !valueRetrieved )
1875 int result = SQLITE_ERROR;
1878 if ( !filterAttribute.isNull() )
1883 sqliteStatement = sqliteDb.
prepare( currentValSql, result );
1885 if ( result == SQLITE_OK )
1888 if ( sqliteStatement.
step() == SQLITE_ROW )
1894 if ( cachedMode && result == SQLITE_OK )
1896 counterCache.insert( cacheString, nextId );
1900 counterCache.remove( cacheString );
1903 valueRetrieved =
true;
1907 if ( valueRetrieved )
1916 if ( !filterAttribute.isNull() )
1922 for ( QVariantMap::const_iterator iter = defaultValues.constBegin(); iter != defaultValues.constEnd(); ++iter )
1925 vals << iter.value().toString();
1928 upsertSql += QLatin1String(
" (" ) + cols.join(
',' ) +
')';
1929 upsertSql += QLatin1String(
" VALUES " );
1930 upsertSql +=
'(' + vals.join(
',' ) +
')';
1932 int result = SQLITE_ERROR;
1936 if ( transaction->
executeSql( upsertSql, errorMessage ) )
1943 result = sqliteDb.
exec( upsertSql, errorMessage );
1945 if ( result == SQLITE_OK )
1947 functionResult = QVariant( nextId );
1952 parent->
setEvalErrorString( QStringLiteral(
"Could not increment value: SQLite error: \"%1\" (%2)." ).arg( errorMessage, QString::number( result ) ) );
1953 functionResult = QVariant();
1958 functionResult = QVariant();
1963 return functionResult;
1969 for (
const QVariant &value : values )
1971 if ( !value.isNull() )
1972 concat += QgsExpressionUtils::getStringValue( value, parent );
1979 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1980 return string.indexOf( QgsExpressionUtils::getStringValue( values.at( 1 ), parent ) ) + 1;
1985 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1986 int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1987 return string.right( pos );
1992 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1993 int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1994 return string.left( pos );
1999 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2000 int length = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2001 QString fill = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2002 return string.leftJustified( length, fill.at( 0 ),
true );
2007 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2008 int length = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2009 QString fill = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2010 return string.rightJustified( length, fill.at( 0 ),
true );
2015 if ( values.size() < 1 )
2017 parent->
setEvalErrorString( QObject::tr(
"Function format requires at least 1 argument" ) );
2021 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2022 for (
int n = 1; n < values.length(); n++ )
2024 string =
string.arg( QgsExpressionUtils::getStringValue( values.at( n ), parent ) );
2032 return QVariant( QDateTime::currentDateTime() );
2037 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2038 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2039 if ( format.isEmpty() && !language.isEmpty() )
2041 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to Date when the language is specified" ) );
2042 return QVariant( QDate() );
2045 if ( format.isEmpty() && language.isEmpty() )
2046 return QVariant( QgsExpressionUtils::getDateValue( values.at( 0 ), parent ) );
2048 QString datestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2049 QLocale locale = QLocale();
2050 if ( !language.isEmpty() )
2052 locale = QLocale( language );
2055 QDate date = locale.toDate( datestring, format );
2056 if ( !date.isValid() )
2058 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to Date" ).arg( datestring ) );
2061 return QVariant( date );
2066 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2067 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2068 if ( format.isEmpty() && !language.isEmpty() )
2070 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to Time when the language is specified" ) );
2071 return QVariant( QTime() );
2074 if ( format.isEmpty() && language.isEmpty() )
2075 return QVariant( QgsExpressionUtils::getTimeValue( values.at( 0 ), parent ) );
2077 QString timestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2078 QLocale locale = QLocale();
2079 if ( !language.isEmpty() )
2081 locale = QLocale( language );
2084 QTime time = locale.toTime( timestring, format );
2085 if ( !time.isValid() )
2087 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to Time" ).arg( timestring ) );
2090 return QVariant( time );
2095 return QVariant::fromValue( QgsExpressionUtils::getInterval( values.at( 0 ), parent ) );
2104 double value = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2105 QString axis = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2106 int precision = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
2108 QString formatString;
2109 if ( values.count() > 3 )
2110 formatString = QgsExpressionUtils::getStringValue( values.at( 3 ), parent );
2112 QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FormatFlags();
2113 if ( formatString.compare( QLatin1String(
"suffix" ), Qt::CaseInsensitive ) == 0 )
2117 else if ( formatString.compare( QLatin1String(
"aligned" ), Qt::CaseInsensitive ) == 0 )
2121 else if ( ! formatString.isEmpty() )
2123 parent->
setEvalErrorString( QObject::tr(
"Invalid formatting parameter: '%1'. It must be empty, or 'suffix' or 'aligned'." ).arg( formatString ) );
2127 if ( axis.compare( QLatin1String(
"x" ), Qt::CaseInsensitive ) == 0 )
2131 else if ( axis.compare( QLatin1String(
"y" ), Qt::CaseInsensitive ) == 0 )
2137 parent->
setEvalErrorString( QObject::tr(
"Invalid axis name: '%1'. It must be either 'x' or 'y'." ).arg( axis ) );
2145 return floatToDegreeFormat( format, values, context, parent, node );
2152 value = QgsCoordinateUtils::dmsToDecimal( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), &ok );
2154 return ok ? QVariant( value ) : QVariant();
2160 return floatToDegreeFormat( format, values, context, parent, node );
2165 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
2166 QDateTime d2 = QgsExpressionUtils::getDateTimeValue( values.at( 1 ), parent );
2167 qint64 seconds = d2.secsTo( d1 );
2168 return QVariant::fromValue(
QgsInterval( seconds ) );
2173 if ( !values.at( 0 ).canConvert<QDate>() )
2176 QDate date = QgsExpressionUtils::getDateValue( values.at( 0 ), parent );
2177 if ( !date.isValid() )
2182 return date.dayOfWeek() % 7;
2187 QVariant value = values.at( 0 );
2188 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2191 return QVariant( inter.
days() );
2195 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2196 return QVariant( d1.date().day() );
2202 QVariant value = values.at( 0 );
2203 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2206 return QVariant( inter.
years() );
2210 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2211 return QVariant( d1.date().year() );
2217 QVariant value = values.at( 0 );
2218 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2221 return QVariant( inter.
months() );
2225 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2226 return QVariant( d1.date().month() );
2232 QVariant value = values.at( 0 );
2233 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2236 return QVariant( inter.
weeks() );
2240 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2241 return QVariant( d1.date().weekNumber() );
2247 QVariant value = values.at( 0 );
2248 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2251 return QVariant( inter.
hours() );
2255 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2256 return QVariant( t1.hour() );
2262 QVariant value = values.at( 0 );
2263 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2266 return QVariant( inter.
minutes() );
2270 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2271 return QVariant( t1.minute() );
2277 QVariant value = values.at( 0 );
2278 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2281 return QVariant( inter.
seconds() );
2285 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2286 return QVariant( t1.second() );
2292 QDateTime dt = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
2295 return QVariant( dt.toMSecsSinceEpoch() );
2305 long long millisecs_since_epoch = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
2307 return QVariant( QDateTime::fromMSecsSinceEpoch( millisecs_since_epoch ) );
2310 #define ENSURE_GEOM_TYPE(f, g, geomtype) \
2311 if ( !(f).hasGeometry() ) \
2312 return QVariant(); \
2313 QgsGeometry g = (f).geometry(); \
2314 if ( (g).type() != (geomtype) ) \
2321 if ( g.isMultipart() )
2323 return g.asMultiPoint().at( 0 ).x();
2327 return g.asPoint().x();
2335 if ( g.isMultipart() )
2337 return g.asMultiPoint().at( 0 ).y();
2341 return g.asPoint().y();
2347 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2353 return QVariant( isValid );
2358 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2370 QVariant result( centroid.
asPoint().
x() );
2376 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2388 QVariant result( centroid.
asPoint().
y() );
2394 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2404 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2412 if ( collection->numGeometries() == 1 )
2414 if (
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN( 0 ) ) )
2425 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2435 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2443 if ( collection->numGeometries() == 1 )
2445 if (
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN( 0 ) ) )
2456 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2461 int idx = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2488 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2505 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2522 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2527 bool ignoreClosing =
false;
2528 if ( values.length() > 1 )
2530 ignoreClosing = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
2540 bool skipLast =
false;
2541 if ( ignoreClosing && ring.count() > 2 && ring.first() == ring.last() )
2546 for (
int i = 0; i < ( skipLast ? ring.count() - 1 : ring.count() ); ++ i )
2558 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2569 for (
int i = 0; i < line->numPoints() - 1; ++i )
2573 << line->pointN( i )
2574 << line->pointN( i + 1 ) );
2585 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2595 if ( collection->numGeometries() == 1 )
2597 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->geometryN( 0 ) );
2602 if ( !curvePolygon )
2606 qlonglong idx = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) - 1;
2612 QVariant result = curve ? QVariant::fromValue(
QgsGeometry( curve ) ) : QVariant();
2618 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2628 qlonglong idx = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) - 1;
2634 QVariant result = part ? QVariant::fromValue(
QgsGeometry( part ) ) : QVariant();
2640 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2649 return QVariant::fromValue(
QgsGeometry( boundary ) );
2654 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2663 return QVariant::fromValue( merged );
2668 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2673 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2676 if ( simplified.
isNull() )
2684 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2689 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2694 if ( simplified.
isNull() )
2702 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2707 int iterations = std::min( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ), 10 );
2708 double offset = qBound( 0.0, QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent ), 0.5 );
2709 double minLength = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
2710 double maxAngle = qBound( 0.0, QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent ), 180.0 );
2712 QgsGeometry smoothed = geom.
smooth(
static_cast<unsigned int>( iterations ), offset, minLength, maxAngle );
2722 if ( values.size() == 1 && ( values.at( 0 ).type() == QVariant::List || values.at( 0 ).type() == QVariant::StringList ) )
2724 list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
2731 QVector< QgsGeometry > parts;
2732 parts.reserve( list.size() );
2733 for (
const QVariant &value : qgis::as_const( list ) )
2751 if ( values.count() < 2 || values.count() > 4 )
2753 parent->
setEvalErrorString( QObject::tr(
"Function make_point requires 2-4 arguments" ) );
2757 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2758 double y = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2759 double z = values.count() >= 3 ? QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent ) : 0.0;
2760 double m = values.count() >= 4 ? QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent ) : 0.0;
2761 switch ( values.count() )
2775 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2776 double y = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2777 double m = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
2783 if ( values.empty() )
2788 QVector<QgsPoint> points;
2789 points.reserve( values.count() );
2791 auto addPoint = [&points](
const QgsGeometry & geom )
2799 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2806 for (
const QVariant &value : values )
2808 if ( value.type() == QVariant::List )
2810 const QVariantList list = value.toList();
2811 for (
const QVariant &v : list )
2813 addPoint( QgsExpressionUtils::getGeometry( v, parent ) );
2818 addPoint( QgsExpressionUtils::getGeometry( value, parent ) );
2822 if ( points.count() < 2 )
2830 if ( values.count() < 1 )
2832 parent->
setEvalErrorString( QObject::tr(
"Function make_polygon requires an argument" ) );
2836 QgsGeometry outerRing = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2840 std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
2842 const QgsCurve *exteriorRing = qgsgeometry_cast< QgsCurve * >( outerRing.
constGet() );
2849 exteriorRing = qgsgeometry_cast< QgsCurve * >( collection->
geometryN( 0 ) );
2854 if ( !exteriorRing )
2857 polygon->setExteriorRing( exteriorRing->
segmentize() );
2860 for (
int i = 1; i < values.count(); ++i )
2862 QgsGeometry ringGeom = QgsExpressionUtils::getGeometry( values.at( i ), parent );
2869 const QgsCurve *ring = qgsgeometry_cast< QgsCurve * >( ringGeom.
constGet() );
2876 ring = qgsgeometry_cast< QgsCurve * >( collection->
geometryN( 0 ) );
2884 polygon->addInteriorRing( ring->
segmentize() );
2887 return QVariant::fromValue(
QgsGeometry( std::move( polygon ) ) );
2892 std::unique_ptr<QgsTriangle> tr(
new QgsTriangle() );
2893 std::unique_ptr<QgsLineString> lineString(
new QgsLineString() );
2894 lineString->clear();
2896 for (
const QVariant &value : values )
2898 QgsGeometry geom = QgsExpressionUtils::getGeometry( value, parent );
2905 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2912 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
2920 lineString->addVertex( *point );
2923 tr->setExteriorRing( lineString.release() );
2925 return QVariant::fromValue(
QgsGeometry( tr.release() ) );
2930 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2937 double radius = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2938 int segment = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
2945 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2952 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
2960 return QVariant::fromValue(
QgsGeometry( circ.toPolygon(
static_cast<unsigned int>( segment ) ) ) );
2965 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2972 double majorAxis = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2973 double minorAxis = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
2974 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
2975 int segment = QgsExpressionUtils::getNativeIntValue( values.at( 4 ), parent );
2981 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2988 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
2995 QgsEllipse elp( *point, majorAxis, minorAxis, azimuth );
2996 return QVariant::fromValue(
QgsGeometry( elp.toPolygon(
static_cast<unsigned int>( segment ) ) ) );
3002 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3009 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3016 unsigned int nbEdges =
static_cast<unsigned int>( QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) );
3019 parent->
setEvalErrorString( QObject::tr(
"Number of edges/sides must be greater than 2" ) );
3026 parent->
setEvalErrorString( QObject::tr(
"Option can be 0 (inscribed) or 1 (circumscribed)" ) );
3030 const QgsPoint *center = qgsgeometry_cast< const QgsPoint * >( pt1.
constGet() );
3037 center = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3044 const QgsPoint *corner = qgsgeometry_cast< const QgsPoint * >( pt2.
constGet() );
3051 corner = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3066 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3072 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3078 const QgsPoint *point1 = qgsgeometry_cast< const QgsPoint *>( pt1.
constGet() );
3079 const QgsPoint *point2 = qgsgeometry_cast< const QgsPoint *>( pt2.
constGet() );
3087 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3093 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3099 QgsGeometry pt3 = QgsExpressionUtils::getGeometry( values.at( 2 ), parent );
3108 parent->
setEvalErrorString( QObject::tr(
"Option can be 0 (distance) or 1 (projected)" ) );
3111 const QgsPoint *point1 = qgsgeometry_cast< const QgsPoint *>( pt1.
constGet() );
3112 const QgsPoint *point2 = qgsgeometry_cast< const QgsPoint *>( pt2.
constGet() );
3113 const QgsPoint *point3 = qgsgeometry_cast< const QgsPoint *>( pt3.
constGet() );
3121 int idx = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
3137 return QVariant( QPointF( p.
x(), p.
y() ) );
3142 QVariant v = pointAt( values, f, parent );
3143 if ( v.type() == QVariant::PointF )
3144 return QVariant( v.toPointF().x() );
3150 QVariant v = pointAt( values, f, parent );
3151 if ( v.type() == QVariant::PointF )
3152 return QVariant( v.toPointF().y() );
3161 return QVariant::fromValue( geom );
3163 return QVariant( QVariant::UserType );
3168 QString wkt = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
3170 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3176 const QByteArray wkb = QgsExpressionUtils::getBinaryValue( values.at( 0 ), parent );
3182 return !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3187 QString gml = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
3194 ogcContext.
layer = mapLayerPtr.data();
3195 ogcContext.
transformContext = context->
variable( QStringLiteral(
"_project_transform_context" ) ).value<QgsCoordinateTransformContext>();
3199 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3212 return QVariant( area );
3216 return QVariant( f.geometry().area() );
3222 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3227 return QVariant( geom.
area() );
3239 return QVariant( len );
3243 return QVariant( f.geometry().length() );
3256 return QVariant( len );
3260 return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().constGet()->perimeter() );
3266 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3272 return QVariant( geom.
length() );
3277 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3283 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3292 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3301 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3316 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon *>( collection->
geometryN( i ) );
3317 if ( !curvePolygon )
3329 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3336 return QVariant( curvePolygon->
ringCount() );
3338 bool foundPoly =
false;
3346 curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->
geometryN( i ) );
3347 if ( !curvePolygon )
3358 return QVariant( ringCount );
3363 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3365 QVariant result = !geomBounds.
isNull() ? QVariant::fromValue( geomBounds ) : QVariant();
3371 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3377 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3383 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3389 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3395 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3401 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3407 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3415 double max = std::numeric_limits< double >::lowest();
3419 double z = ( *it ).z();
3425 if ( max == std::numeric_limits< double >::lowest() )
3426 return QVariant( QVariant::Double );
3428 return QVariant( max );
3433 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3441 double min = std::numeric_limits< double >::max();
3445 double z = ( *it ).z();
3451 if ( min == std::numeric_limits< double >::max() )
3452 return QVariant( QVariant::Double );
3454 return QVariant( min );
3459 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3467 double min = std::numeric_limits< double >::max();
3471 double m = ( *it ).m();
3477 if ( min == std::numeric_limits< double >::max() )
3478 return QVariant( QVariant::Double );
3480 return QVariant( min );
3485 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3493 double max = std::numeric_limits< double >::lowest();
3497 double m = ( *it ).m();
3503 if ( max == std::numeric_limits< double >::lowest() )
3504 return QVariant( QVariant::Double );
3506 return QVariant( max );
3511 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3515 std::unique_ptr< QgsAbstractGeometry > flipped( geom.
constGet()->
clone() );
3517 return QVariant::fromValue(
QgsGeometry( std::move( flipped ) ) );
3522 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3526 const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( fGeom.
constGet() );
3533 curve = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( 0 ) );
3541 return QVariant::fromValue( curve->
isClosed() );
3546 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3559 std::unique_ptr< QgsLineString > closedLine( line->
clone() );
3560 closedLine->close();
3562 result = QVariant::fromValue(
QgsGeometry( std::move( closedLine ) ) );
3572 if (
const QgsLineString *line = qgsgeometry_cast<const QgsLineString * >( collection->
geometryN( i ) ) )
3574 std::unique_ptr< QgsLineString > closedLine( line->
clone() );
3575 closedLine->close();
3577 closed->addGeometry( closedLine.release() );
3580 result = QVariant::fromValue(
QgsGeometry( std::move( closed ) ) );
3588 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3592 return QVariant::fromValue( fGeom.
isEmpty() );
3597 if ( values.at( 0 ).isNull() )
3598 return QVariant::fromValue(
true );
3600 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3601 return QVariant::fromValue( fGeom.
isNull() || fGeom.
isEmpty() );
3606 if ( values.length() < 2 || values.length() > 3 )
3609 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3610 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3617 if ( values.length() == 2 )
3620 QString result = engine->relate( sGeom.
constGet() );
3621 return QVariant::fromValue( result );
3626 QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
3627 bool result = engine->relatePattern( sGeom.
constGet(), pattern );
3628 return QVariant::fromValue( result );
3634 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3635 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3640 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3641 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3642 return fGeom.
disjoint( sGeom ) ? TVL_True : TVL_False;
3646 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3647 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3648 return fGeom.
intersects( sGeom ) ? TVL_True : TVL_False;
3652 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3653 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3654 return fGeom.
touches( sGeom ) ? TVL_True : TVL_False;
3658 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3659 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3660 return fGeom.
crosses( sGeom ) ? TVL_True : TVL_False;
3664 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3665 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3666 return fGeom.
contains( sGeom ) ? TVL_True : TVL_False;
3670 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3671 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3672 return fGeom.
overlaps( sGeom ) ? TVL_True : TVL_False;
3676 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3677 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3678 return fGeom.
within( sGeom ) ? TVL_True : TVL_False;
3682 if ( values.length() < 2 || values.length() > 3 )
3685 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3686 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3688 if ( values.length() == 3 )
3689 seg = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3692 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3698 const QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3700 return !reoriented.
isNull() ? QVariant::fromValue( reoriented ) : QVariant();
3705 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3706 const QgsPoint *pt = qgsgeometry_cast<const QgsPoint *>( fGeom.
constGet() );
3713 pt = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3720 parent->
setEvalErrorString( QObject::tr(
"Function `wedge_buffer` requires a point value for the center." ) );
3724 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3725 double width = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3726 double outerRadius = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3727 double innerRadius = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
3730 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3736 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3739 parent->
setEvalErrorString( QObject::tr(
"Function `tapered_buffer` requires a line geometry." ) );
3743 double startWidth = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3744 double endWidth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3745 int segments =
static_cast< int >( QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) );
3748 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3754 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3757 parent->
setEvalErrorString( QObject::tr(
"Function `buffer_by_m` requires a line geometry." ) );
3761 int segments =
static_cast< int >( QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) );
3764 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3770 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3771 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3772 int segments = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3776 double miterLimit = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3779 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3785 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3786 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3787 int segments = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3791 double miterLimit = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3794 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3800 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3801 double distStart = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3802 double distEnd = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3805 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3811 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3812 double dx = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3813 double dy = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3815 return QVariant::fromValue( fGeom );
3820 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3821 const double rotation = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3822 const QgsGeometry center = values.at( 2 ).
isValid() ? QgsExpressionUtils::getGeometry( values.at( 2 ), parent )
3833 parent->
setEvalErrorString( QObject::tr(
"Function 'rotate' requires a point value for the center" ) );
3839 if ( multiPoint.count() == 1 )
3845 parent->
setEvalErrorString( QObject::tr(
"Function 'rotate' requires a point value for the center" ) );
3854 fGeom.
rotate( rotation, pt );
3855 return QVariant::fromValue( fGeom );
3860 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3862 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3867 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3869 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3875 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3876 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3878 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3884 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3886 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3893 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3895 if ( values.length() == 2 )
3896 segments = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
3904 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3910 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3912 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3918 const QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3924 double area,
angle, width, height;
3937 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3938 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3940 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3946 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3953 const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( fGeom.
constGet() );
3958 result = reversed ? QVariant::fromValue(
QgsGeometry( reversed ) ) : QVariant();
3966 if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( collection->
geometryN( i ) ) )
3968 reversed->addGeometry( curve->
reversed() );
3975 result = reversed ? QVariant::fromValue(
QgsGeometry( std::move( reversed ) ) ) : QVariant();
3982 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3993 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->
geometryN( 0 ) );
4002 QVariant result = exterior ? QVariant::fromValue(
QgsGeometry( exterior ) ) : QVariant();
4008 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4009 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4010 return QVariant( fGeom.
distance( sGeom ) );
4015 QgsGeometry g1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4016 QgsGeometry g2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4019 if ( values.length() == 3 && values.at( 2 ).isValid() )
4021 double densify = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4022 densify = qBound( 0.0, densify, 1.0 );
4030 return res > -1 ? QVariant( res ) : QVariant();
4035 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4036 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4038 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4043 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4044 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4046 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4051 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4052 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4054 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4060 if ( values.length() < 1 || values.length() > 2 )
4063 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4065 if ( values.length() == 2 )
4066 prec = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4067 QString wkt = fGeom.
asWkt( prec );
4068 return QVariant( wkt );
4073 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4074 return fGeom.
isNull() ? QVariant() : QVariant( fGeom.asWkb() );
4079 if ( values.length() != 2 )
4081 parent->
setEvalErrorString( QObject::tr(
"Function `azimuth` requires exactly two parameters. %1 given." ).arg( values.length() ) );
4085 QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4086 QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4088 const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.
constGet() );
4095 pt1 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4100 const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.
constGet() );
4107 pt2 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4114 parent->
setEvalErrorString( QObject::tr(
"Function `azimuth` requires two points as arguments." ) );
4121 if ( pt1->
y() < pt2->
y() )
4123 else if ( pt1->
y() > pt2->
y() )
4131 if ( pt1->
x() < pt2->
x() )
4133 else if ( pt1->
x() > pt2->
x() )
4134 return M_PI + ( M_PI_2 );
4139 if ( pt1->
x() < pt2->
x() )
4141 if ( pt1->
y() < pt2->
y() )
4143 return std::atan( std::fabs( pt1->
x() - pt2->
x() ) / std::fabs( pt1->
y() - pt2->
y() ) );
4147 return std::atan( std::fabs( pt1->
y() - pt2->
y() ) / std::fabs( pt1->
x() - pt2->
x() ) )
4154 if ( pt1->
y() > pt2->
y() )
4156 return std::atan( std::fabs( pt1->
x() - pt2->
x() ) / std::fabs( pt1->
y() - pt2->
y() ) )
4161 return std::atan( std::fabs( pt1->
y() - pt2->
y() ) / std::fabs( pt1->
x() - pt2->
x() ) )
4162 + ( M_PI + ( M_PI_2 ) );
4169 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4173 parent->
setEvalErrorString( QStringLiteral(
"'project' requires a point geometry" ) );
4177 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4178 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4179 double inclination = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
4182 QgsPoint newPoint = p->
project( distance, 180.0 * azimuth / M_PI, 180.0 * inclination / M_PI );
4189 QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4190 QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4192 const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.
constGet() );
4199 pt1 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4203 const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.
constGet() );
4210 pt2 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4218 parent->
setEvalErrorString( QStringLiteral(
"Function 'inclination' requires two points as arguments." ) );
4228 if ( values.length() != 3 )
4231 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4232 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4233 double y = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4237 QVariant result = geom.
constGet() ? QVariant::fromValue( geom ) : QVariant();
4243 if ( values.length() < 2 )
4246 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4249 return values.at( 0 );
4251 QString expString = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4252 QVariant cachedExpression;
4257 if ( cachedExpression.isValid() )
4264 bool asc = values.value( 2 ).toBool();
4282 Q_ASSERT( collection );
4286 QgsExpressionSorter sorter( orderBy );
4288 QList<QgsFeature> partFeatures;
4289 partFeatures.reserve( collection->
partCount() );
4290 for (
int i = 0; i < collection->
partCount(); ++i )
4296 sorter.sortFeatures( partFeatures, unconstedContext );
4300 Q_ASSERT( orderedGeom );
4305 for (
const QgsFeature &feature : qgis::as_const( partFeatures ) )
4310 QVariant result = QVariant::fromValue(
QgsGeometry( orderedGeom ) );
4313 delete unconstedContext;
4320 QgsGeometry fromGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4321 QgsGeometry toGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4325 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4331 QgsGeometry fromGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4332 QgsGeometry toGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4336 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4342 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4343 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4347 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4353 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4356 parent->
setEvalErrorString( QObject::tr(
"line_substring requires a curve geometry input" ) );
4362 curve = qgsgeometry_cast< const QgsCurve * >( lineGeom.
constGet() );
4369 curve = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( 0 ) );
4376 double startDistance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4377 double endDistance = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4379 std::unique_ptr< QgsCurve > substring( curve->
curveSubstring( startDistance, endDistance ) );
4381 return !result.isNull() ? QVariant::fromValue( result ) : QVariant();
4386 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4387 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4394 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4395 int vertex = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4400 vertex = count + vertex;
4408 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4409 int vertex = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4414 vertex = count + vertex;
4422 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4423 QgsGeometry pointGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4427 return distance >= 0 ? distance : QVariant();
4432 if ( values.length() == 2 && values.at( 1 ).toInt() != 0 )
4434 double number = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
4435 return qgsRound( number, QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4438 if ( values.length() >= 1 )
4440 double number = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
4441 return QVariant( qlonglong( std::round( number ) ) );
4456 const double value = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
4457 const int places = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4458 const QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4465 QLocale locale = !language.isEmpty() ? QLocale( language ) : QLocale();
4466 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
4467 return locale.toString( value,
'f', places );
4472 const QDateTime datetime = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
4473 const QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4474 const QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4476 QLocale locale = !language.isEmpty() ? QLocale( language ) : QLocale();
4477 return locale.toString( datetime, format );
4483 int avg = ( color.red() + color.green() + color.blue() ) / 3;
4484 int alpha = color.alpha();
4486 color.setRgb( avg, avg, avg, alpha );
4495 double ratio = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4500 else if ( ratio < 0 )
4505 int red =
static_cast<int>( color1.red() * ( 1 - ratio ) + color2.red() * ratio );
4506 int green =
static_cast<int>( color1.green() * ( 1 - ratio ) + color2.green() * ratio );
4507 int blue =
static_cast<int>( color1.blue() * ( 1 - ratio ) + color2.blue() * ratio );
4508 int alpha =
static_cast<int>( color1.alpha() * ( 1 - ratio ) + color2.alpha() * ratio );
4510 QColor newColor( red, green, blue, alpha );
4517 int red = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
4518 int green = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4519 int blue = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4520 QColor color = QColor( red, green, blue );
4521 if ( ! color.isValid() )
4523 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( red ).arg( green ).arg( blue ) );
4524 color = QColor( 0, 0, 0 );
4527 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4532 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
4533 QVariant value = node->
eval( parent, context );
4537 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
4539 value = node->
eval( parent, context );
4547 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
4549 QVariant value = node->
eval( parent, context );
4551 if ( value.toBool() )
4553 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
4555 value = node->
eval( parent, context );
4560 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
4562 value = node->
eval( parent, context );
4570 int red = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
4571 int green = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4572 int blue = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4573 int alpha = QgsExpressionUtils::getNativeIntValue( values.at( 3 ), parent );
4574 QColor color = QColor( red, green, blue, alpha );
4575 if ( ! color.isValid() )
4577 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( red ).arg( green ).arg( blue ).arg( alpha ) );
4578 color = QColor( 0, 0, 0 );
4589 expRamp = QgsExpressionUtils::getRamp( values.at( 0 ), parent );
4594 QString rampName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
4598 parent->
setEvalErrorString( QObject::tr(
"\"%1\" is not a valid color ramp" ).arg( rampName ) );
4603 double value = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4604 QColor color = ramp->
color( value );
4611 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4613 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4615 double lightness = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4617 QColor color = QColor::fromHslF( hue, saturation, lightness );
4619 if ( ! color.isValid() )
4621 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( hue ).arg( saturation ).arg( lightness ) );
4622 color = QColor( 0, 0, 0 );
4625 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4631 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4633 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4635 double lightness = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4637 double alpha = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 255.0;
4639 QColor color = QColor::fromHslF( hue, saturation, lightness, alpha );
4640 if ( ! color.isValid() )
4642 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
4643 color = QColor( 0, 0, 0 );
4651 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4653 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4655 double value = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4657 QColor color = QColor::fromHsvF( hue, saturation, value );
4659 if ( ! color.isValid() )
4661 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( hue ).arg( saturation ).arg( value ) );
4662 color = QColor( 0, 0, 0 );
4665 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4671 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4673 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4675 double value = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4677 double alpha = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 255.0;
4679 QColor color = QColor::fromHsvF( hue, saturation, value, alpha );
4680 if ( ! color.isValid() )
4682 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
4683 color = QColor( 0, 0, 0 );
4691 double cyan = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 100.0;
4693 double magenta = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4695 double yellow = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4697 double black = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 100.0;
4699 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black );
4701 if ( ! color.isValid() )
4703 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ) );
4704 color = QColor( 0, 0, 0 );
4707 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4713 double cyan = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 100.0;
4715 double magenta = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4717 double yellow = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4719 double black = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 100.0;
4721 double alpha = QgsExpressionUtils::getIntValue( values.at( 4 ), parent ) / 255.0;
4723 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black, alpha );
4724 if ( ! color.isValid() )
4726 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
4727 color = QColor( 0, 0, 0 );
4735 if ( ! color.isValid() )
4737 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4741 QString part = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4742 if ( part.compare( QLatin1String(
"red" ), Qt::CaseInsensitive ) == 0 )
4744 else if ( part.compare( QLatin1String(
"green" ), Qt::CaseInsensitive ) == 0 )
4745 return color.green();
4746 else if ( part.compare( QLatin1String(
"blue" ), Qt::CaseInsensitive ) == 0 )
4747 return color.blue();
4748 else if ( part.compare( QLatin1String(
"alpha" ), Qt::CaseInsensitive ) == 0 )
4749 return color.alpha();
4750 else if ( part.compare( QLatin1String(
"hue" ), Qt::CaseInsensitive ) == 0 )
4751 return color.hsvHueF() * 360;
4752 else if ( part.compare( QLatin1String(
"saturation" ), Qt::CaseInsensitive ) == 0 )
4753 return color.hsvSaturationF() * 100;
4754 else if ( part.compare( QLatin1String(
"value" ), Qt::CaseInsensitive ) == 0 )
4755 return color.valueF() * 100;
4756 else if ( part.compare( QLatin1String(
"hsl_hue" ), Qt::CaseInsensitive ) == 0 )
4757 return color.hslHueF() * 360;
4758 else if ( part.compare( QLatin1String(
"hsl_saturation" ), Qt::CaseInsensitive ) == 0 )
4759 return color.hslSaturationF() * 100;
4760 else if ( part.compare( QLatin1String(
"lightness" ), Qt::CaseInsensitive ) == 0 )
4761 return color.lightnessF() * 100;
4762 else if ( part.compare( QLatin1String(
"cyan" ), Qt::CaseInsensitive ) == 0 )
4763 return color.cyanF() * 100;
4764 else if ( part.compare( QLatin1String(
"magenta" ), Qt::CaseInsensitive ) == 0 )
4765 return color.magentaF() * 100;
4766 else if ( part.compare( QLatin1String(
"yellow" ), Qt::CaseInsensitive ) == 0 )
4767 return color.yellowF() * 100;
4768 else if ( part.compare( QLatin1String(
"black" ), Qt::CaseInsensitive ) == 0 )
4769 return color.blackF() * 100;
4771 parent->
setEvalErrorString( QObject::tr(
"Unknown color component '%1'" ).arg( part ) );
4777 const QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
4778 if ( map.count() < 1 )
4780 parent->
setEvalErrorString( QObject::tr(
"A minimum of two colors is required to create a ramp" ) );
4784 QList< QColor > colors;
4786 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
4789 if ( !colors.last().isValid() )
4791 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( it.value().toString() ) );
4795 double step = it.key().toDouble();
4796 if ( it == map.constBegin() )
4801 else if ( it == map.constEnd() )
4811 bool discrete = values.at( 1 ).toBool();
4813 return QVariant::fromValue(
QgsGradientColorRamp( colors.first(), colors.last(), discrete, stops ) );
4819 if ( ! color.isValid() )
4821 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4825 QString part = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4826 int value = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4827 if ( part.compare( QLatin1String(
"red" ), Qt::CaseInsensitive ) == 0 )
4828 color.setRed( value );
4829 else if ( part.compare( QLatin1String(
"green" ), Qt::CaseInsensitive ) == 0 )
4830 color.setGreen( value );
4831 else if ( part.compare( QLatin1String(
"blue" ), Qt::CaseInsensitive ) == 0 )
4832 color.setBlue( value );
4833 else if ( part.compare( QLatin1String(
"alpha" ), Qt::CaseInsensitive ) == 0 )
4834 color.setAlpha( value );
4835 else if ( part.compare( QLatin1String(
"hue" ), Qt::CaseInsensitive ) == 0 )
4836 color.setHsv( value, color.hsvSaturation(), color.value(), color.alpha() );
4837 else if ( part.compare( QLatin1String(
"saturation" ), Qt::CaseInsensitive ) == 0 )
4838 color.setHsvF( color.hsvHueF(), value / 100.0, color.valueF(), color.alphaF() );
4839 else if ( part.compare( QLatin1String(
"value" ), Qt::CaseInsensitive ) == 0 )
4840 color.setHsvF( color.hsvHueF(), color.hsvSaturationF(), value / 100.0, color.alphaF() );
4841 else if ( part.compare( QLatin1String(
"hsl_hue" ), Qt::CaseInsensitive ) == 0 )
4842 color.setHsl( value, color.hslSaturation(), color.lightness(), color.alpha() );
4843 else if ( part.compare( QLatin1String(
"hsl_saturation" ), Qt::CaseInsensitive ) == 0 )
4844 color.setHslF( color.hslHueF(), value / 100.0, color.lightnessF(), color.alphaF() );
4845 else if ( part.compare( QLatin1String(
"lightness" ), Qt::CaseInsensitive ) == 0 )
4846 color.setHslF( color.hslHueF(), color.hslSaturationF(), value / 100.0, color.alphaF() );
4847 else if ( part.compare( QLatin1String(
"cyan" ), Qt::CaseInsensitive ) == 0 )
4848 color.setCmykF( value / 100.0, color.magentaF(), color.yellowF(), color.blackF(), color.alphaF() );
4849 else if ( part.compare( QLatin1String(
"magenta" ), Qt::CaseInsensitive ) == 0 )
4850 color.setCmykF( color.cyanF(), value / 100.0, color.yellowF(), color.blackF(), color.alphaF() );
4851 else if ( part.compare( QLatin1String(
"yellow" ), Qt::CaseInsensitive ) == 0 )
4852 color.setCmykF( color.cyanF(), color.magentaF(), value / 100.0, color.blackF(), color.alphaF() );
4853 else if ( part.compare( QLatin1String(
"black" ), Qt::CaseInsensitive ) == 0 )
4854 color.setCmykF( color.cyanF(), color.magentaF(), color.yellowF(), value / 100.0, color.alphaF() );
4857 parent->
setEvalErrorString( QObject::tr(
"Unknown color component '%1'" ).arg( part ) );
4866 if ( ! color.isValid() )
4868 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4872 color = color.darker( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4880 if ( ! color.isValid() )
4882 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4886 color = color.lighter( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4893 QgsFeature feat = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
4896 return QVariant::fromValue( geom );
4902 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4903 QString sAuthId = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4904 QString dAuthId = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4908 return QVariant::fromValue( fGeom );
4911 return QVariant::fromValue( fGeom );
4920 return QVariant::fromValue( fGeom );
4934 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
4937 QgsFeatureId fid = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
4947 result = QVariant::fromValue( fet );
4957 std::unique_ptr<QgsVectorLayerFeatureSource> featureSource = QgsExpressionUtils::getFeatureSource( values.at( 0 ), parent );
4960 if ( !featureSource )
4965 QString attribute = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4966 int attributeId = featureSource->fields().lookupField( attribute );
4967 if ( attributeId == -1 )
4972 const QVariant &attVal = values.at( 2 );
4974 const QString cacheValueKey = QStringLiteral(
"getfeature:%1:%2:%3" ).arg( featureSource->id(), QString::number( attributeId ), attVal.toString() );
4996 res = QVariant::fromValue( fet );
5011 if ( !values.isEmpty() )
5014 if ( col && ( values.size() == 1 || !values.at( 1 ).isValid() ) )
5015 fieldName = col->
name();
5016 else if ( values.size() == 2 )
5017 fieldName = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5020 QVariant value = values.at( 0 );
5025 if ( fieldIndex == -1 )
5027 parent->
setEvalErrorString( QCoreApplication::translate(
"expression",
"%1: Field not found %2" ).arg( QStringLiteral(
"represent_value" ), fieldName ) );
5031 QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
5033 const QString cacheValueKey = QStringLiteral(
"repvalfcnval:%1:%2:%3" ).arg( layer ? layer->
id() : QStringLiteral(
"[None]" ), fieldName, value.toString() );
5042 const QString cacheKey = QStringLiteral(
"repvalfcn:%1:%2" ).arg( layer ? layer->
id() : QStringLiteral(
"[None]" ), fieldName );
5053 result =
formatter->representValue( layer, fieldIndex, setup.
config(), cache, value );
5060 parent->
setEvalErrorString( QCoreApplication::translate(
"expression",
"%1: function cannot be evaluated without a context." ).arg( QStringLiteral(
"represent_value" ), fieldName ) );
5068 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
5074 QString layerProperty = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5075 if ( QString::compare( layerProperty, QStringLiteral(
"name" ), Qt::CaseInsensitive ) == 0 )
5076 return layer->
name();
5077 else if ( QString::compare( layerProperty, QStringLiteral(
"id" ), Qt::CaseInsensitive ) == 0 )
5079 else if ( QString::compare( layerProperty, QStringLiteral(
"title" ), Qt::CaseInsensitive ) == 0 )
5081 else if ( QString::compare( layerProperty, QStringLiteral(
"abstract" ), Qt::CaseInsensitive ) == 0 )
5083 else if ( QString::compare( layerProperty, QStringLiteral(
"keywords" ), Qt::CaseInsensitive ) == 0 )
5085 QStringList keywords;
5087 for (
auto it = keywordMap.constBegin(); it != keywordMap.constEnd(); ++it )
5089 keywords.append( it.value() );
5091 if ( !keywords.isEmpty() )
5095 else if ( QString::compare( layerProperty, QStringLiteral(
"data_url" ), Qt::CaseInsensitive ) == 0 )
5097 else if ( QString::compare( layerProperty, QStringLiteral(
"attribution" ), Qt::CaseInsensitive ) == 0 )
5101 else if ( QString::compare( layerProperty, QStringLiteral(
"attribution_url" ), Qt::CaseInsensitive ) == 0 )
5103 else if ( QString::compare( layerProperty, QStringLiteral(
"source" ), Qt::CaseInsensitive ) == 0 )
5105 else if ( QString::compare( layerProperty, QStringLiteral(
"min_scale" ), Qt::CaseInsensitive ) == 0 )
5107 else if ( QString::compare( layerProperty, QStringLiteral(
"max_scale" ), Qt::CaseInsensitive ) == 0 )
5109 else if ( QString::compare( layerProperty, QStringLiteral(
"is_editable" ), Qt::CaseInsensitive ) == 0 )
5111 else if ( QString::compare( layerProperty, QStringLiteral(
"crs" ), Qt::CaseInsensitive ) == 0 )
5113 else if ( QString::compare( layerProperty, QStringLiteral(
"crs_definition" ), Qt::CaseInsensitive ) == 0 )
5115 else if ( QString::compare( layerProperty, QStringLiteral(
"crs_description" ), Qt::CaseInsensitive ) == 0 )
5117 else if ( QString::compare( layerProperty, QStringLiteral(
"extent" ), Qt::CaseInsensitive ) == 0 )
5120 QVariant result = QVariant::fromValue( extentGeom );
5123 else if ( QString::compare( layerProperty, QStringLiteral(
"distance_units" ), Qt::CaseInsensitive ) == 0 )
5125 else if ( QString::compare( layerProperty, QStringLiteral(
"type" ), Qt::CaseInsensitive ) == 0 )
5127 switch ( layer->
type() )
5130 return QCoreApplication::translate(
"expressions",
"Vector" );
5132 return QCoreApplication::translate(
"expressions",
"Raster" );
5134 return QCoreApplication::translate(
"expressions",
"Mesh" );
5136 return QCoreApplication::translate(
"expressions",
"Vector Tile" );
5138 return QCoreApplication::translate(
"expressions",
"Plugin" );
5140 return QCoreApplication::translate(
"expressions",
"Annotation" );
5146 QgsVectorLayer *vLayer = qobject_cast< QgsVectorLayer * >( layer );
5149 if ( QString::compare( layerProperty, QStringLiteral(
"storage_type" ), Qt::CaseInsensitive ) == 0 )
5151 else if ( QString::compare( layerProperty, QStringLiteral(
"geometry_type" ), Qt::CaseInsensitive ) == 0 )
5153 else if ( QString::compare( layerProperty, QStringLiteral(
"feature_count" ), Qt::CaseInsensitive ) == 0 )
5155 else if ( QString::compare( layerProperty, QStringLiteral(
"path" ), Qt::CaseInsensitive ) == 0 )
5160 return decodedUri.value( QStringLiteral(
"path" ) );
5171 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
5174 parent->
setEvalErrorString( QObject::tr(
"Cannot find layer %1" ).arg( values.at( 0 ).toString() ) );
5184 const QString uriPart = values.at( 1 ).toString();
5188 if ( !uriPart.isNull() )
5190 return decodedUri.value( values.at( 1 ).toString() );
5200 QString layerIdOrName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5207 if ( !layersByName.isEmpty() )
5209 layer = layersByName.at( 0 );
5220 int band = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5221 if ( band < 1 || band > rl->
bandCount() )
5223 parent->
setEvalErrorString( QObject::tr(
"Invalid band number %1 for layer %2" ).arg( band ).arg( layerIdOrName ) );
5227 QString layerProperty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5230 if ( QString::compare( layerProperty, QStringLiteral(
"avg" ), Qt::CaseInsensitive ) == 0 )
5232 else if ( QString::compare( layerProperty, QStringLiteral(
"stdev" ), Qt::CaseInsensitive ) == 0 )
5234 else if ( QString::compare( layerProperty, QStringLiteral(
"min" ), Qt::CaseInsensitive ) == 0 )
5236 else if ( QString::compare( layerProperty, QStringLiteral(
"max" ), Qt::CaseInsensitive ) == 0 )
5238 else if ( QString::compare( layerProperty, QStringLiteral(
"range" ), Qt::CaseInsensitive ) == 0 )
5240 else if ( QString::compare( layerProperty, QStringLiteral(
"sum" ), Qt::CaseInsensitive ) == 0 )
5244 parent->
setEvalErrorString( QObject::tr(
"Invalid raster statistic: '%1'" ).arg( layerProperty ) );
5274 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5275 bool ascending = values.value( 1 ).toBool();
5276 std::sort( list.begin(), list.end(), [ascending]( QVariant a, QVariant b ) ->
bool { return ( !ascending ? qgsVariantLessThan( b, a ) : qgsVariantLessThan( a, b ) ); } );
5282 return QgsExpressionUtils::getListValue( values.at( 0 ), parent ).length();
5287 return QVariant( QgsExpressionUtils::getListValue( values.at( 0 ), parent ).contains( values.at( 1 ) ) );
5292 QVariantList listA = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5293 QVariantList listB = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
5295 for (
const auto &item : listB )
5297 if ( listA.contains( item ) )
5301 return QVariant( match == listB.count() );
5306 return QgsExpressionUtils::getListValue( values.at( 0 ), parent ).indexOf( values.at( 1 ) );
5311 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5312 const int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5313 if ( pos < 0 || pos >= list.length() )
return QVariant();
5314 return list.at( pos );
5319 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5320 return list.value( 0 );
5325 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5326 return list.value( list.size() - 1 );
5329 static QVariant convertToSameType(
const QVariant &value, QVariant::Type type )
5331 QVariant result = value;
5332 result.convert(
static_cast<int>( type ) );
5338 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5339 list.append( values.at( 1 ) );
5340 return convertToSameType( list, values.at( 0 ).type() );
5345 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5346 list.prepend( values.at( 1 ) );
5347 return convertToSameType( list, values.at( 0 ).type() );
5352 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5353 list.insert( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ), values.at( 2 ) );
5354 return convertToSameType( list, values.at( 0 ).type() );
5359 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5360 list.removeAt( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
5361 return convertToSameType( list, values.at( 0 ).type() );
5366 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5367 list.removeAll( values.at( 1 ) );
5368 return convertToSameType( list, values.at( 0 ).type() );
5374 for (
const QVariant &cur : values )
5376 list += QgsExpressionUtils::getListValue( cur, parent );
5378 return convertToSameType( list, values.at( 0 ).type() );
5383 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5384 int start_pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5385 const int end_pos = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
5386 int slice_length = 0;
5388 if ( start_pos < 0 )
5390 start_pos = list.length() + start_pos;
5394 slice_length = end_pos - start_pos + 1;
5398 slice_length = list.length() + end_pos - start_pos + 1;
5401 if ( slice_length < 0 )
5405 list = list.mid( start_pos, slice_length );
5411 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5412 std::reverse( list.begin(), list.end() );
5418 const QVariantList array1 = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5419 const QVariantList array2 = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
5420 for (
const QVariant &cur : array2 )
5422 if ( array1.contains( cur ) )
5423 return QVariant(
true );
5425 return QVariant(
false );
5430 QVariantList array = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5432 QVariantList distinct;
5434 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
5436 if ( !distinct.contains( *it ) )
5438 distinct += ( *it );
5447 QVariantList array = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5448 QString delimiter = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5449 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5453 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
5455 str += ( !( *it ).toString().isEmpty() ) ? ( *it ).toString() : empty;
5456 if ( it != ( array.constEnd() - 1 ) )
5462 return QVariant( str );
5467 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5468 QString delimiter = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5469 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5471 QStringList list = str.split( delimiter );
5474 for ( QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
5476 array += ( !( *it ).isEmpty() ) ? *it : empty;
5484 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5485 QJsonDocument document = QJsonDocument::fromJson( str.toUtf8() );
5486 if ( document.isNull() )
5489 return document.toVariant();
5495 QJsonDocument document = QJsonDocument::fromVariant( values.at( 0 ) );
5496 return document.toJson( QJsonDocument::Compact );
5501 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5502 if ( str.isEmpty() )
5503 return QVariantMap();
5504 str = str.trimmed();
5511 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5518 for (
int i = 0; i + 1 < values.length(); i += 2 )
5520 result.insert( QgsExpressionUtils::getStringValue( values.at( i ), parent ), values.at( i + 1 ) );
5527 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).value( values.at( 1 ).toString() );
5532 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).contains( values.at( 1 ).toString() );
5537 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5538 map.remove( values.at( 1 ).toString() );
5544 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5545 map.insert( values.at( 1 ).toString(), values.at( 2 ) );
5552 for (
const QVariant &cur : values )
5554 const QVariantMap curMap = QgsExpressionUtils::getMapValue( cur, parent );
5555 for ( QVariantMap::const_iterator it = curMap.constBegin(); it != curMap.constEnd(); ++it )
5556 result.insert( it.key(), it.value() );
5563 return QStringList( QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).keys() );
5568 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).values();
5573 QString envVarName = values.at( 0 ).toString();
5574 return QProcessEnvironment::systemEnvironment().value( envVarName );
5579 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5580 return QFileInfo( file ).completeBaseName();
5585 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5586 return QFileInfo( file ).completeSuffix();
5591 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5592 return QFileInfo::exists( file );
5597 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5598 return QFileInfo( file ).fileName();
5603 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5604 return QFileInfo( file ).isFile();
5609 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5610 return QFileInfo( file ).isDir();
5615 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5616 return QDir::toNativeSeparators( QFileInfo( file ).path() );
5621 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5622 return QFileInfo( file ).size();
5625 static QVariant fcnHash(
const QString str,
const QCryptographicHash::Algorithm
algorithm )
5627 return QString( QCryptographicHash::hash( str.toUtf8(),
algorithm ).toHex() );
5633 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5634 QString method = QgsExpressionUtils::getStringValue( values.at( 1 ), parent ).toLower();
5636 if ( method == QLatin1String(
"md4" ) )
5638 hash = fcnHash( str, QCryptographicHash::Md4 );
5640 else if ( method == QLatin1String(
"md5" ) )
5642 hash = fcnHash( str, QCryptographicHash::Md5 );
5644 else if ( method == QLatin1String(
"sha1" ) )
5646 hash = fcnHash( str, QCryptographicHash::Sha1 );
5648 else if ( method == QLatin1String(
"sha224" ) )
5650 hash = fcnHash( str, QCryptographicHash::Sha224 );
5652 else if ( method == QLatin1String(
"sha256" ) )
5654 hash = fcnHash( str, QCryptographicHash::Sha256 );
5656 else if ( method == QLatin1String(
"sha384" ) )
5658 hash = fcnHash( str, QCryptographicHash::Sha384 );
5660 else if ( method == QLatin1String(
"sha512" ) )
5662 hash = fcnHash( str, QCryptographicHash::Sha512 );
5664 else if ( method == QLatin1String(
"sha3_224" ) )
5666 hash = fcnHash( str, QCryptographicHash::Sha3_224 );
5668 else if ( method == QLatin1String(
"sha3_256" ) )
5670 hash = fcnHash( str, QCryptographicHash::Sha3_256 );
5672 else if ( method == QLatin1String(
"sha3_384" ) )
5674 hash = fcnHash( str, QCryptographicHash::Sha3_384 );
5676 else if ( method == QLatin1String(
"sha3_512" ) )
5678 hash = fcnHash( str, QCryptographicHash::Sha3_512 );
5680 #if QT_VERSION >= QT_VERSION_CHECK( 5, 9, 2 )
5681 else if ( method == QLatin1String(
"keccak_224" ) )
5683 hash = fcnHash( str, QCryptographicHash::Keccak_224 );
5685 else if ( method == QLatin1String(
"keccak_256" ) )
5687 hash = fcnHash( str, QCryptographicHash::Keccak_256 );
5689 else if ( method == QLatin1String(
"keccak_384" ) )
5691 hash = fcnHash( str, QCryptographicHash::Keccak_384 );
5693 else if ( method == QLatin1String(
"keccak_512" ) )
5695 hash = fcnHash( str, QCryptographicHash::Keccak_512 );
5700 parent->
setEvalErrorString( QObject::tr(
"Hash method %1 is not available on this system." ).arg( str ) );
5707 return fcnHash( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), QCryptographicHash::Md5 );
5712 return fcnHash( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), QCryptographicHash::Sha256 );
5717 const QByteArray input = values.at( 0 ).toByteArray();
5718 return QVariant( QString( input.toBase64() ) );
5723 const QString value = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5724 const QByteArray base64 = value.toLocal8Bit();
5725 const QByteArray decoded = QByteArray::fromBase64( base64 );
5726 return QVariant( decoded );
5734 const QVariant sourceLayerRef = context->
variable( QStringLiteral(
"layer" ) );
5735 QgsVectorLayer *sourceLayer = QgsExpressionUtils::getVectorLayer( sourceLayerRef, parent );
5742 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
5745 const bool layerCanBeCached = node->
isStatic( parent, context );
5746 QVariant targetLayerValue = node->
eval( parent, context );
5750 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
5752 QString subExpString = node->dump();
5754 bool testOnly = ( subExpString ==
"NULL" );
5755 QgsVectorLayer *targetLayer = QgsExpressionUtils::getVectorLayer( targetLayerValue, parent );
5758 parent->
setEvalErrorString( QObject::tr(
"Layer '%1' could not be loaded." ).arg( targetLayerValue.toString() ) );
5763 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
5765 QString filterString = node->dump();
5766 if ( filterString !=
"NULL" )
5772 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
5774 QVariant limitValue = node->eval( parent, context );
5776 qlonglong limit = QgsExpressionUtils::getIntValue( limitValue, parent );
5779 double max_distance = 0;
5780 if ( isNearestFunc )
5782 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
5784 QVariant distanceValue = node->eval( parent, context );
5786 max_distance = QgsExpressionUtils::getDoubleValue( distanceValue, parent );
5790 node = QgsExpressionUtils::getNode( values.at( isNearestFunc ? 5 : 4 ), parent );
5792 QVariant cacheValue = node->eval( parent, context );
5794 bool cacheEnabled = cacheValue.toBool();
5800 if ( sourceLayer && targetLayer->
crs() != sourceLayer->
crs() )
5806 bool sameLayers = ( sourceLayer && sourceLayer->
id() == targetLayer->
id() );
5809 if ( bboxGrow != 0 )
5811 intDomain.
grow( bboxGrow );
5814 const QString cacheBase { QStringLiteral(
"%1:%2" ).arg( targetLayer->
id(), subExpString ) };
5820 QList<QgsFeature> features;
5821 if ( isNearestFunc || ( layerCanBeCached && cacheEnabled ) )
5825 const QString cacheLayer { QStringLiteral(
"ovrlaylyr:%1" ).arg( cacheBase ) };
5826 const QString cacheIndex { QStringLiteral(
"ovrlayidx:%1" ).arg( cacheBase ) };
5830 cachedTarget = targetLayer->
materialize( request );
5831 if ( layerCanBeCached )
5832 context->
setCachedValue( cacheLayer, QVariant::fromValue( cachedTarget ) );
5842 if ( layerCanBeCached )
5843 context->
setCachedValue( cacheIndex, QVariant::fromValue( spatialIndex ) );
5850 QList<QgsFeatureId> fidsList;
5851 if ( isNearestFunc )
5853 fidsList = spatialIndex.
nearestNeighbor( geometry, sameLayers ? limit + 1 : limit, max_distance );
5857 fidsList = spatialIndex.
intersects( intDomain );
5860 QListIterator<QgsFeatureId> i( fidsList );
5861 while ( i.hasNext() )
5864 if ( sameLayers && feat.
id() == fId2 )
5866 features.append( cachedTarget->
getFeature( fId2 ) );
5879 if ( sameLayers && feat.
id() == feat2.
id() )
5881 features.append( feat2 );
5889 const QString expCacheKey { QStringLiteral(
"exp:%1" ).arg( cacheBase ) };
5890 const QString ctxCacheKey { QStringLiteral(
"ctx:%1" ).arg( cacheBase ) };
5896 subExpression.
prepare( &subContext );
5908 QVariantList results;
5910 QListIterator<QgsFeature> i( features );
5911 while ( i.hasNext() && ( limit == -1 || foundCount < limit ) )
5915 if ( ! relationFunction || ( geometry.*relationFunction )( feat2.
geometry() ) )
5928 results.append( subExpression.
evaluate( &subContext ) );
5933 results.append( feat2.
id() );
5949 QVariantList disjoint_results;
5956 if ( !results.contains( feat2.
id() ) )
5959 disjoint_results.append( subExpression.
evaluate( &subContext ) );
5962 return disjoint_results;
6005 return executeGeomOverlay( values, context, parent,
nullptr,
false, 0,
true );
6014 static QMutex sFunctionsMutex( QMutex::Recursive );
6015 QMutexLocker locker( &sFunctionsMutex );
6017 QList<QgsExpressionFunction *> &functions = *sFunctions();
6019 if ( functions.isEmpty() )
6056 functions << randFunc;
6060 functions << randfFunc;
6063 <<
new QgsStaticExpressionFunction( QStringLiteral(
"max" ), -1, fcnMax, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6064 <<
new QgsStaticExpressionFunction( QStringLiteral(
"min" ), -1, fcnMin, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6070 <<
new QgsStaticExpressionFunction( QStringLiteral(
"pi" ), 0, fcnPi, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"$pi" ) )
6074 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_datetime" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToDateTime, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"todatetime" ) )
6075 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_date" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToDate, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"todate" ) )
6076 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_time" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToTime, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"totime" ) )
6081 <<
new QgsStaticExpressionFunction( QStringLiteral(
"coalesce" ), -1, fcnCoalesce, QStringLiteral(
"Conditionals" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6095 QStringLiteral(
"Aggregates" ),
6104 if ( !node->
args() )
6107 QSet<QString> referencedVars;
6110 QgsExpressionNode *subExpressionNode = node->args()->at( 2 );
6111 referencedVars = subExpressionNode->referencedVariables();
6116 QgsExpressionNode *filterNode = node->args()->at( 3 );
6117 referencedVars.unite( filterNode->referencedVariables() );
6119 return referencedVars.contains( QStringLiteral(
"parent" ) ) || referencedVars.contains( QString() );
6128 if ( !node->
args() )
6129 return QSet<QString>();
6131 QSet<QString> referencedCols;
6132 QSet<QString> referencedVars;
6147 if ( referencedVars.contains( QStringLiteral(
"parent" ) ) || referencedVars.contains( QString() ) )
6150 return referencedCols;
6163 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count" ), aggParams, fcnAggregateCount, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6164 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count_distinct" ), aggParams, fcnAggregateCountDistinct, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6165 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count_missing" ), aggParams, fcnAggregateCountMissing, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6166 <<
new QgsStaticExpressionFunction( QStringLiteral(
"minimum" ), aggParams, fcnAggregateMin, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6167 <<
new QgsStaticExpressionFunction( QStringLiteral(
"maximum" ), aggParams, fcnAggregateMax, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6168 <<
new QgsStaticExpressionFunction( QStringLiteral(
"sum" ), aggParams, fcnAggregateSum, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6169 <<
new QgsStaticExpressionFunction( QStringLiteral(
"mean" ), aggParams, fcnAggregateMean, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6170 <<
new QgsStaticExpressionFunction( QStringLiteral(
"median" ), aggParams, fcnAggregateMedian, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6171 <<
new QgsStaticExpressionFunction( QStringLiteral(
"stdev" ), aggParams, fcnAggregateStdev, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6172 <<
new QgsStaticExpressionFunction( QStringLiteral(
"range" ), aggParams, fcnAggregateRange, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6173 <<
new QgsStaticExpressionFunction( QStringLiteral(
"minority" ), aggParams, fcnAggregateMinority, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6174 <<
new QgsStaticExpressionFunction( QStringLiteral(
"majority" ), aggParams, fcnAggregateMajority, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6175 <<
new QgsStaticExpressionFunction( QStringLiteral(
"q1" ), aggParams, fcnAggregateQ1, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6176 <<
new QgsStaticExpressionFunction( QStringLiteral(
"q3" ), aggParams, fcnAggregateQ3, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6177 <<
new QgsStaticExpressionFunction( QStringLiteral(
"iqr" ), aggParams, fcnAggregateIQR, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6178 <<
new QgsStaticExpressionFunction( QStringLiteral(
"min_length" ), aggParams, fcnAggregateMinLength, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6179 <<
new QgsStaticExpressionFunction( QStringLiteral(
"max_length" ), aggParams, fcnAggregateMaxLength, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6180 <<
new QgsStaticExpressionFunction( QStringLiteral(
"collect" ), aggParams, fcnAggregateCollectGeometry, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6181 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concatenate" ), aggParamsConcat, fcnAggregateStringConcat, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6182 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concatenate_unique" ), aggParamsConcat, fcnAggregateStringConcatUnique, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6183 <<
new QgsStaticExpressionFunction( QStringLiteral(
"array_agg" ), aggParamsArray, fcnAggregateArray, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6188 <<
new QgsStaticExpressionFunction( QStringLiteral(
"now" ), 0, fcnNow, QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"$now" ) )
6191 fcnAge, QStringLiteral(
"Date and Time" ) )
6205 fcnMakeDate, QStringLiteral(
"Date and Time" ) )
6209 fcnMakeTime, QStringLiteral(
"Date and Time" ) )
6216 fcnMakeDateTime, QStringLiteral(
"Date and Time" ) )
6224 fcnMakeInterval, QStringLiteral(
"Date and Time" ) )
6242 false, QSet< QString >(),
false, QStringList(), true )
6243 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concat" ), -1, fcnConcat, QStringLiteral(
"String" ), QString(),
false, QSet<QString>(),
false, QStringList(), true )
6256 fcnColorMixRgb, QStringLiteral(
"Color" ) )
6260 fcnColorRgb, QStringLiteral(
"Color" ) )
6265 fncColorRgba, QStringLiteral(
"Color" ) )
6271 fcnCreateRamp, QStringLiteral(
"Color" ) )
6275 fcnColorHsl, QStringLiteral(
"Color" ) )
6280 fncColorHsla, QStringLiteral(
"Color" ) )
6284 fcnColorHsv, QStringLiteral(
"Color" ) )
6289 fncColorHsva, QStringLiteral(
"Color" ) )
6294 fcnColorCmyk, QStringLiteral(
"Color" ) )
6300 fncColorCmyka, QStringLiteral(
"Color" ) )
6303 fncColorPart, QStringLiteral(
"Color" ) )
6306 fncDarker, QStringLiteral(
"Color" ) )
6309 fncLighter, QStringLiteral(
"Color" ) )
6314 fcnBaseFileName, QStringLiteral(
"Files and Paths" ) )
6316 fcnFileSuffix, QStringLiteral(
"Files and Paths" ) )
6318 fcnFileExists, QStringLiteral(
"Files and Paths" ) )
6320 fcnFileName, QStringLiteral(
"Files and Paths" ) )
6322 fcnPathIsFile, QStringLiteral(
"Files and Paths" ) )
6324 fcnPathIsDir, QStringLiteral(
"Files and Paths" ) )
6326 fcnFilePath, QStringLiteral(
"Files and Paths" ) )
6328 fcnFileSize, QStringLiteral(
"Files and Paths" ) )
6332 fcnGenericHash, QStringLiteral(
"Conversions" ) )
6334 fcnHashMd5, QStringLiteral(
"Conversions" ) )
6336 fcnHashSha256, QStringLiteral(
"Conversions" ) )
6340 fcnToBase64, QStringLiteral(
"Conversions" ) )
6342 fcnFromBase64, QStringLiteral(
"Conversions" ) )
6348 geomFunc->setIsStatic(
false );
6349 functions << geomFunc;
6353 functions << areaFunc;
6359 functions << lengthFunc;
6363 functions << perimeterFunc;
6375 QMap< QString, QgsExpressionFunction::FcnEval > geometry_overlay_definitions
6377 { QStringLiteral(
"overlay_intersects" ), fcnGeomOverlayIntersects },
6378 { QStringLiteral(
"overlay_contains" ), fcnGeomOverlayContains },
6379 { QStringLiteral(
"overlay_crosses" ), fcnGeomOverlayCrosses },
6380 { QStringLiteral(
"overlay_equals" ), fcnGeomOverlayEquals },
6381 { QStringLiteral(
"overlay_touches" ), fcnGeomOverlayTouches },
6382 { QStringLiteral(
"overlay_disjoint" ), fcnGeomOverlayDisjoint },
6383 { QStringLiteral(
"overlay_within" ), fcnGeomOverlayWithin },
6385 QMapIterator< QString, QgsExpressionFunction::FcnEval > i( geometry_overlay_definitions );
6386 while ( i.hasNext() )
6399 functions << fcnGeomOverlayFunc;
6412 functions << fcnGeomOverlayNearestFunc;
6425 fcnNodesToPoints, QStringLiteral(
"GeometryGroup" ) )
6427 <<
new QgsStaticExpressionFunction( QStringLiteral(
"collect_geometries" ), -1, fcnCollectGeometries, QStringLiteral(
"GeometryGroup" ) )
6432 fcnMakePointM, QStringLiteral(
"GeometryGroup" ) )
6438 fcnMakeTriangle, QStringLiteral(
"GeometryGroup" ) )
6443 fcnMakeCircle, QStringLiteral(
"GeometryGroup" ) )
6450 fcnMakeEllipse, QStringLiteral(
"GeometryGroup" ) )
6456 fcnMakeRegularPolygon, QStringLiteral(
"GeometryGroup" ) )
6460 fcnMakeSquare, QStringLiteral(
"GeometryGroup" ) )
6466 fcnMakeRectangleFrom3Points, QStringLiteral(
"GeometryGroup" ) );
6469 functions << xAtFunc;
6473 functions << yAtFunc;
6488 fcnDisjoint, QStringLiteral(
"GeometryGroup" ) )
6491 fcnIntersects, QStringLiteral(
"GeometryGroup" ) )
6494 fcnTouches, QStringLiteral(
"GeometryGroup" ) )
6497 fcnCrosses, QStringLiteral(
"GeometryGroup" ) )
6500 fcnContains, QStringLiteral(
"GeometryGroup" ) )
6503 fcnOverlaps, QStringLiteral(
"GeometryGroup" ) )
6506 fcnWithin, QStringLiteral(
"GeometryGroup" ) )
6510 fcnTranslate, QStringLiteral(
"GeometryGroup" ) )
6514 fcnRotate, QStringLiteral(
"GeometryGroup" ) )
6518 fcnBuffer, QStringLiteral(
"GeometryGroup" ) )
6520 fcnForceRHR, QStringLiteral(
"GeometryGroup" ) )
6530 , fcnTaperedBuffer, QStringLiteral(
"GeometryGroup" ) )
6533 , fcnBufferByM, QStringLiteral(
"GeometryGroup" ) )
6539 fcnOffsetCurve, QStringLiteral(
"GeometryGroup" ) )
6545 fcnSingleSidedBuffer, QStringLiteral(
"GeometryGroup" ) )
6549 fcnExtend, QStringLiteral(
"GeometryGroup" ) )
6558 fcnInteriorRingN, QStringLiteral(
"GeometryGroup" ) )
6561 fcnGeometryN, QStringLiteral(
"GeometryGroup" ) )
6584 fcnOrientedBBox, QStringLiteral(
"GeometryGroup" ) )
6587 fcnMainAngle, QStringLiteral(
"GeometryGroup" ) )
6591 fcnMinimalCircle, QStringLiteral(
"GeometryGroup" ) )
6594 fcnDifference, QStringLiteral(
"GeometryGroup" ) )
6597 fcnDistance, QStringLiteral(
"GeometryGroup" ) )
6600 fcnHausdorffDistance, QStringLiteral(
"GeometryGroup" ) )
6603 fcnIntersection, QStringLiteral(
"GeometryGroup" ) )
6606 fcnSymDifference, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"symDifference" ) )
6609 fcnCombine, QStringLiteral(
"GeometryGroup" ) )
6612 fcnCombine, QStringLiteral(
"GeometryGroup" ) )
6615 fcnGeomToWKT, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"geomToWKT" ) )
6617 fcnGeomToWKB, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false )
6622 fcnTransformGeometry, QStringLiteral(
"GeometryGroup" ) )
6626 fcnExtrude, QStringLiteral(
"GeometryGroup" ), QString() )
6628 fcnGeomIsMultipart, QStringLiteral(
"GeometryGroup" ) )
6630 fcnZMax, QStringLiteral(
"GeometryGroup" ) )
6632 fcnZMin, QStringLiteral(
"GeometryGroup" ) )
6634 fcnMMax, QStringLiteral(
"GeometryGroup" ) )
6636 fcnMMin, QStringLiteral(
"GeometryGroup" ) );
6642 fcnOrderParts, QStringLiteral(
"GeometryGroup" ), QString() );
6647 const QList< QgsExpressionNode *> argList = node->
args()->list();
6650 if ( !argNode->isStatic( parent, context ) )
6656 QgsExpressionNode *argNode = node->args()->at( 1 );
6658 QString expString = argNode->eval( parent, context ).toString();
6660 QgsExpression e( expString );
6662 if ( e.rootNode() && e.rootNode()->isStatic( parent, context ) )
6673 QgsExpressionNode *argNode = node->args()->at( 1 );
6674 QString expression = argNode->eval( parent, context ).toString();
6675 QgsExpression e( expression );
6676 e.prepare( context );
6677 context->setCachedValue( expression, QVariant::fromValue( e ) );
6682 functions << orderPartsFunc;
6687 fcnClosestPoint, QStringLiteral(
"GeometryGroup" ) )
6690 fcnShortestLine, QStringLiteral(
"GeometryGroup" ) )
6709 functions << idFunc;
6713 functions << currentFeatureFunc;
6717 functions << uuidFunc;
6723 fcnGetFeature, QStringLiteral(
"Record and Attributes" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"QgsExpressionUtils::getFeature" ) )
6726 fcnGetFeatureById, QStringLiteral(
"Record and Attributes" ), QString(),
false, QSet<QString>(),
false );
6731 functions << attributesFunc;
6734 QStringLiteral(
"maptip" ),
6737 QStringLiteral(
"Record and Attributes" ),
6743 functions << maptipFunc;
6746 QStringLiteral(
"display_expression" ),
6748 fcnFeatureDisplayExpression,
6749 QStringLiteral(
"Record and Attributes" ),
6755 functions << displayFunc;
6758 QStringLiteral(
"is_selected" ),
6761 QStringLiteral(
"Record and Attributes" ),
6767 functions << isSelectedFunc;
6771 QStringLiteral(
"num_selected" ),
6774 QStringLiteral(
"Record and Attributes" ),
6782 QStringLiteral(
"sqlite_fetch_and_increment" ),
6790 fcnSqliteFetchAndIncrement,
6791 QStringLiteral(
"Record and Attributes" )
6809 parent->
setEvalErrorString( tr(
"If represent_value is called with 1 parameter, it must be an attribute." ) );
6819 parent->
setEvalErrorString( tr(
"represent_value must be called with exactly 1 or 2 parameters." ) );
6825 functions << representValueFunc;
6831 fcnGetLayerProperty, QStringLiteral(
"General" ) )
6836 fcnDecodeUri, QStringLiteral(
"Map Layers" ) )
6853 QgsExpressionNode *argNode = node->args()->at( 0 );
6855 if ( !argNode->isStatic( parent, context ) )
6858 QString varName = argNode->eval( parent, context ).toString();
6860 const QgsExpressionContextScope *scope = context->activeScopeForVariable( varName );
6861 return scope ? scope->isStatic( varName ) : false;
6878 QgsExpressionNode *argNode = node->args()->at( 0 );
6880 if ( argNode->isStatic( parent, context ) )
6882 QString expString = argNode->eval( parent, context ).toString();
6884 QgsExpression e( expString );
6886 if ( e.rootNode() && e.rootNode()->isStatic( parent, context ) )
6894 functions << evalFunc;
6900 const QList< QgsExpressionNode *> argList = node->
args()->list();
6903 if ( !argNode->isStatic( parent, context ) )
6915 functions << attributeFunc;
6925 <<
new QgsStaticExpressionFunction( QStringLiteral(
"array" ), -1, fcnArray, QStringLiteral(
"Arrays" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6970 *sOwnedFunctions() << func;
6971 *sBuiltinFunctions() << func->name();
6972 sBuiltinFunctions()->append( func->aliases() );
6985 sFunctions()->append(
function );
6986 if ( transferOwnership )
6987 sOwnedFunctions()->append(
function );
7001 sFunctions()->removeAt( fnIdx );
7009 qDeleteAll( *sOwnedFunctions() );
7010 sOwnedFunctions()->clear();
7015 if ( sBuiltinFunctions()->isEmpty() )
7019 return *sBuiltinFunctions();
7027 QStringLiteral(
"Arrays" ) )
7038 if ( args->
count() < 2 )
7041 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7051 QVariantList result;
7053 if ( args->
count() < 2 )
7057 QVariantList array = args->
at( 0 )->
eval( parent, context ).toList();
7060 std::unique_ptr< QgsExpressionContext > tempContext;
7063 tempContext = qgis::make_unique< QgsExpressionContext >();
7064 subContext = tempContext.get();
7070 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
7073 result << args->
at( 1 )->
eval( parent, subContext );
7098 if ( args->
count() < 2 )
7102 args->
at( 0 )->
prepare( parent, context );
7106 subContext = *context;
7112 args->
at( 1 )->
prepare( parent, &subContext );
7121 QStringLiteral(
"Arrays" ) )
7132 if ( args->
count() < 2 )
7135 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7145 QVariantList result;
7147 if ( args->
count() < 2 )
7151 const QVariantList array = args->
at( 0 )->
eval( parent, context ).toList();
7154 std::unique_ptr< QgsExpressionContext > tempContext;
7157 tempContext = qgis::make_unique< QgsExpressionContext >();
7158 subContext = tempContext.get();
7164 for (
const QVariant &value : array )
7167 if ( args->
at( 1 )->
eval( parent, subContext ).toBool() )
7193 if ( args->
count() < 2 )
7197 args->
at( 0 )->
prepare( parent, context );
7201 subContext = *context;
7207 args->
at( 1 )->
prepare( parent, &subContext );
7216 QStringLiteral(
"General" ) )
7227 if ( args->
count() < 3 )
7231 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7233 QVariant
name = args->
at( 0 )->
eval( parent, context );
7234 QVariant value = args->
at( 1 )->
eval( parent, context );
7237 appendTemporaryVariable( context,
name.toString(), value );
7238 if ( args->
at( 2 )->
isStatic( parent, context ) )
7240 popTemporaryVariable( context );
7251 if ( args->
count() < 3 )
7255 QVariant
name = args->
at( 0 )->
eval( parent, context );
7256 QVariant value = args->
at( 1 )->
eval( parent, context );
7259 std::unique_ptr< QgsExpressionContext > tempContext;
7260 if ( !updatedContext )
7262 tempContext = qgis::make_unique< QgsExpressionContext >();
7263 updatedContext = tempContext.get();
7266 appendTemporaryVariable( updatedContext,
name.toString(), value );
7267 result = args->
at( 2 )->
eval( parent, updatedContext );
7270 popTemporaryVariable( updatedContext );
7291 if ( args->
count() < 3 )
7296 QVariant value = args->
at( 1 )->
prepare( parent, context );
7299 std::unique_ptr< QgsExpressionContext > tempContext;
7300 if ( !updatedContext )
7302 tempContext = qgis::make_unique< QgsExpressionContext >();
7303 updatedContext = tempContext.get();
7306 appendTemporaryVariable( updatedContext,
name.toString(), value );
7307 args->
at( 2 )->
prepare( parent, updatedContext );
7310 popTemporaryVariable( updatedContext );
7315 void QgsWithVariableExpressionFunction::popTemporaryVariable(
const QgsExpressionContext *context )
const
7321 void QgsWithVariableExpressionFunction::appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &name,
const QVariant &value )
const