@@ -347,6 +347,13 @@ static QVariant fcnSqrt( const QVariantList& values, QgsFeature* /*f*/, QgsExpre
347
347
double x = getDoubleValue ( values.at ( 0 ), parent );
348
348
return QVariant ( sqrt ( x ) );
349
349
}
350
+
351
+ static QVariant fcnAbs ( const QVariantList& values, QgsFeature*, QgsExpression* parent )
352
+ {
353
+ double val = getDoubleValue ( values.at ( 0 ), parent );
354
+ return QVariant ( fabs ( val ) );
355
+ }
356
+
350
357
static QVariant fcnSin ( const QVariantList& values, QgsFeature* , QgsExpression* parent )
351
358
{
352
359
double x = getDoubleValue ( values.at ( 0 ), parent );
@@ -1299,7 +1306,7 @@ const QStringList &QgsExpression::BuiltinFunctions()
1299
1306
if ( gmBuiltinFunctions.isEmpty () )
1300
1307
{
1301
1308
gmBuiltinFunctions
1302
- << " sqrt" << " cos" << " sin" << " tan"
1309
+ << " abs " << " sqrt" << " cos" << " sin" << " tan"
1303
1310
<< " asin" << " acos" << " atan" << " atan2"
1304
1311
<< " exp" << " ln" << " log10" << " log"
1305
1312
<< " round" << " rand" << " randf" << " max" << " min"
@@ -1331,6 +1338,7 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
1331
1338
{
1332
1339
gmFunctions
1333
1340
<< new StaticFunction ( " sqrt" , 1 , fcnSqrt, QObject::tr ( " Math" ) )
1341
+ << new StaticFunction ( " abs" , 1 , fcnAbs, QObject::tr ( " Math" ) )
1334
1342
<< new StaticFunction ( " cos" , 1 , fcnCos, QObject::tr ( " Math" ) )
1335
1343
<< new StaticFunction ( " sin" , 1 , fcnSin, QObject::tr ( " Math" ) )
1336
1344
<< new StaticFunction ( " tan" , 1 , fcnTan, QObject::tr ( " Math" ) )
0 commit comments