@@ -431,6 +431,43 @@ static QVariant fcnRnd( const QVariantList& values, QgsFeature* , QgsExpression*
431
431
// Return a random integer in the range [min, max] (inclusive)
432
432
return QVariant ( min + ( rand () % ( int )( max - min + 1 ) ) );
433
433
}
434
+
435
+ static QVariant fcnMax ( const QVariantList& values, QgsFeature* , QgsExpression *parent )
436
+ {
437
+ // initially set max as first value
438
+ double maxVal = getDoubleValue ( values.at ( 0 ), parent );
439
+
440
+ // check against all other values
441
+ for ( int i = 1 ; i < values.length (); ++i )
442
+ {
443
+ double testVal = getDoubleValue ( values[i], parent );
444
+ if ( testVal > maxVal )
445
+ {
446
+ maxVal = testVal;
447
+ }
448
+ }
449
+
450
+ return QVariant ( maxVal );
451
+ }
452
+
453
+ static QVariant fcnMin ( const QVariantList& values, QgsFeature* , QgsExpression *parent )
454
+ {
455
+ // initially set min as first value
456
+ double minVal = getDoubleValue ( values.at ( 0 ), parent );
457
+
458
+ // check against all other values
459
+ for ( int i = 1 ; i < values.length (); ++i )
460
+ {
461
+ double testVal = getDoubleValue ( values[i], parent );
462
+ if ( testVal < minVal )
463
+ {
464
+ minVal = testVal;
465
+ }
466
+ }
467
+
468
+ return QVariant ( minVal );
469
+ }
470
+
434
471
static QVariant fcnToInt ( const QVariantList& values, QgsFeature* , QgsExpression* parent )
435
472
{
436
473
return QVariant ( getIntValue ( values.at ( 0 ), parent ) );
@@ -1253,7 +1290,8 @@ const QStringList &QgsExpression::BuiltinFunctions()
1253
1290
<< " sqrt" << " cos" << " sin" << " tan"
1254
1291
<< " asin" << " acos" << " atan" << " atan2"
1255
1292
<< " exp" << " ln" << " log10" << " log"
1256
- << " round" << " rand" << " randf" << " toint" << " toreal" << " tostring"
1293
+ << " round" << " rand" << " randf" << " max" << " min"
1294
+ << " toint" << " toreal" << " tostring"
1257
1295
<< " todatetime" << " todate" << " totime" << " tointerval"
1258
1296
<< " coalesce" << " regexp_match" << " $now" << " age" << " year"
1259
1297
<< " month" << " week" << " day" << " hour"
@@ -1294,6 +1332,8 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
1294
1332
<< new StaticFunction ( " round" , -1 , fcnRound, QObject::tr ( " Math" ) )
1295
1333
<< new StaticFunction ( " rand" , 2 , fcnRnd, QObject::tr ( " Math" ) )
1296
1334
<< new StaticFunction ( " randf" , 2 , fcnRndF, QObject::tr ( " Math" ) )
1335
+ << new StaticFunction ( " max" , -1 , fcnMax, QObject::tr ( " Math" ) )
1336
+ << new StaticFunction ( " min" , -1 , fcnMin, QObject::tr ( " Math" ) )
1297
1337
<< new StaticFunction ( " $pi" , 0 , fcnPi, QObject::tr ( " Math" ) )
1298
1338
<< new StaticFunction ( " toint" , 1 , fcnToInt, QObject::tr ( " Conversions" ) )
1299
1339
<< new StaticFunction ( " toreal" , 1 , fcnToReal, QObject::tr ( " Conversions" ) )
0 commit comments