@@ -370,46 +370,53 @@ static QVariant fcnGeomPerimeter( const QVariantList& , QgsFeature* f, QgsExpres
370
370
return QVariant ( calc->measurePerimeter ( f->geometry () ) );
371
371
}
372
372
373
- typedef QgsExpression::FunctionDef FnDef;
374
-
375
- FnDef QgsExpression::BuiltinFunctions[] =
376
- {
377
- // math
378
- FnDef ( " sqrt" , 1 , fcnSqrt, " Math" ),
379
- FnDef ( " sin" , 1 , fcnSin, " Math" ),
380
- FnDef ( " cos" , 1 , fcnCos, " Math" ),
381
- FnDef ( " tan" , 1 , fcnTan, " Math" ),
382
- FnDef ( " asin" , 1 , fcnAsin, " Math" ),
383
- FnDef ( " acos" , 1 , fcnAcos, " Math" ),
384
- FnDef ( " atan" , 1 , fcnAtan, " Math" ),
385
- FnDef ( " atan2" , 2 , fcnAtan2, " Math" ),
386
- FnDef ( " exp" , 1 , fcnExp, " Math" ),
387
- FnDef ( " ln" , 1 , fcnLn, " Math" ),
388
- FnDef ( " log10" , 1 , fcnLog10, " Math" ),
389
- FnDef ( " log" , 2 , fcnLog, " Math" ),
390
- // casts
391
- FnDef ( " toint" , 1 , fcnToInt, " Conversions" ),
392
- FnDef ( " toreal" , 1 , fcnToReal, " Conversions" ),
393
- FnDef ( " tostring" , 1 , fcnToString, " Conversions" ),
394
- // string manipulation
395
- FnDef ( " lower" , 1 , fcnLower, " String" ),
396
- FnDef ( " upper" , 1 , fcnUpper, " String" ),
397
- FnDef ( " length" , 1 , fcnLength, " String" ),
398
- FnDef ( " replace" , 3 , fcnReplace, " String" ),
399
- FnDef ( " regexp_replace" , 3 , fcnRegexpReplace, " String" ),
400
- FnDef ( " substr" , 3 , fcnSubstr, " String" ),
401
- // geometry accessors
402
- FnDef ( " xat" , 1 , fcnXat, " Geometry" , " " , true ),
403
- FnDef ( " yat" , 1 , fcnYat, " Geometry" , " " , true ),
404
- FnDef ( " $area" , 0 , fcnGeomArea, " Geometry" , " " , true ),
405
- FnDef ( " $length" , 0 , fcnGeomLength, " Geometry" , " " , true ),
406
- FnDef ( " $perimeter" , 0 , fcnGeomPerimeter, " Geometry" , " " , true ),
407
- FnDef ( " $x" , 0 , fcnX, " Geometry" , " " , true ),
408
- FnDef ( " $y" , 0 , fcnY, " Geometry" , " " , true ),
409
- // special columns
410
- FnDef ( " $rownum" , 0 , fcnRowNumber, " Record" ),
411
- FnDef ( " $id" , 0 , fcnFeatureId, " Record" )
412
- };
373
+ QList<QgsExpression::FunctionDef> QgsExpression::gmBuiltinFunctions;
374
+
375
+ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions ()
376
+ {
377
+ if ( gmBuiltinFunctions.isEmpty () )
378
+ {
379
+ // math
380
+ gmBuiltinFunctions
381
+ << FunctionDef ( " sqrt" , 1 , fcnSqrt, QObject::tr ( " Math" ) )
382
+ << FunctionDef ( " sin" , 1 , fcnSin, QObject::tr ( " Math" ) )
383
+ << FunctionDef ( " cos" , 1 , fcnCos, QObject::tr ( " Math" ) )
384
+ << FunctionDef ( " tan" , 1 , fcnTan, QObject::tr ( " Math" ) )
385
+ << FunctionDef ( " asin" , 1 , fcnAsin, QObject::tr ( " Math" ) )
386
+ << FunctionDef ( " acos" , 1 , fcnAcos, QObject::tr ( " Math" ) )
387
+ << FunctionDef ( " atan" , 1 , fcnAtan, QObject::tr ( " Math" ) )
388
+ << FunctionDef ( " atan2" , 2 , fcnAtan2, QObject::tr ( " Math" ) )
389
+ << FunctionDef ( " exp" , 1 , fcnExp, QObject::tr ( " Math" ) )
390
+ << FunctionDef ( " ln" , 1 , fcnLn, QObject::tr ( " Math" ) )
391
+ << FunctionDef ( " log10" , 1 , fcnLog10, QObject::tr ( " Math" ) )
392
+ << FunctionDef ( " log" , 2 , fcnLog, QObject::tr ( " Math" ) )
393
+ // casts
394
+ << FunctionDef ( " toint" , 1 , fcnToInt, QObject::tr ( " Conversions" ) )
395
+ << FunctionDef ( " toreal" , 1 , fcnToReal, QObject::tr ( " Conversions" ) )
396
+ << FunctionDef ( " tostring" , 1 , fcnToString, QObject::tr ( " Conversions" ) )
397
+ // string manipulation
398
+ << FunctionDef ( " lower" , 1 , fcnLower, QObject::tr ( " String" ) )
399
+ << FunctionDef ( " upper" , 1 , fcnUpper, QObject::tr ( " String" ) )
400
+ << FunctionDef ( " length" , 1 , fcnLength, QObject::tr ( " String" ) )
401
+ << FunctionDef ( " replace" , 3 , fcnReplace, QObject::tr ( " String" ) )
402
+ << FunctionDef ( " regexp_replace" , 3 , fcnRegexpReplace, QObject::tr ( " String" ) )
403
+ << FunctionDef ( " substr" , 3 , fcnSubstr, QObject::tr ( " String" ) )
404
+ // geometry accessors
405
+ << FunctionDef ( " xat" , 1 , fcnXat, QObject::tr ( " Geometry" ), " " , true )
406
+ << FunctionDef ( " yat" , 1 , fcnYat, QObject::tr ( " Geometry" ), " " , true )
407
+ << FunctionDef ( " $area" , 0 , fcnGeomArea, QObject::tr ( " Geometry" ), " " , true )
408
+ << FunctionDef ( " $length" , 0 , fcnGeomLength, QObject::tr ( " Geometry" ), " " , true )
409
+ << FunctionDef ( " $perimeter" , 0 , fcnGeomPerimeter, QObject::tr ( " Geometry" ), " " , true )
410
+ << FunctionDef ( " $x" , 0 , fcnX, QObject::tr ( " Geometry" ), " " , true )
411
+ << FunctionDef ( " $y" , 0 , fcnY, QObject::tr ( " Geometry" ), " " , true )
412
+ // special columns
413
+ << FunctionDef ( " $rownum" , 0 , fcnRowNumber, QObject::tr ( " Record" ) )
414
+ << FunctionDef ( " $id" , 0 , fcnFeatureId, QObject::tr ( " Record" ) )
415
+ ;
416
+ }
417
+
418
+ return gmBuiltinFunctions;
419
+ }
413
420
414
421
415
422
bool QgsExpression::isFunctionName ( QString name )
@@ -422,15 +429,15 @@ int QgsExpression::functionIndex( QString name )
422
429
int count = functionCount ();
423
430
for ( int i = 0 ; i < count; i++ )
424
431
{
425
- if ( QString::compare ( name, BuiltinFunctions[i].mName , Qt::CaseInsensitive ) == 0 )
432
+ if ( QString::compare ( name, BuiltinFunctions () [i].mName , Qt::CaseInsensitive ) == 0 )
426
433
return i;
427
434
}
428
435
return -1 ;
429
436
}
430
437
431
438
int QgsExpression::functionCount ()
432
439
{
433
- return ( sizeof ( BuiltinFunctions ) / sizeof ( FunctionDef ) );
440
+ return BuiltinFunctions (). size ( );
434
441
}
435
442
436
443
@@ -527,7 +534,8 @@ QVariant QgsExpression::evaluate( QgsFeature* f, const QgsFieldMap& fields )
527
534
528
535
QString QgsExpression::dump () const
529
536
{
530
- if ( !mRootNode ) return " (no root)" ;
537
+ if ( !mRootNode )
538
+ return QObject::tr ( " (no root)" );
531
539
532
540
return mRootNode ->dump ();
533
541
}
@@ -861,7 +869,7 @@ QString QgsExpression::NodeInOperator::dump() const
861
869
862
870
QVariant QgsExpression::NodeFunction::eval ( QgsExpression* parent, QgsFeature* f )
863
871
{
864
- const FunctionDef& fd = BuiltinFunctions[mFnIndex ];
872
+ const FunctionDef& fd = BuiltinFunctions () [mFnIndex ];
865
873
866
874
// evaluate arguments
867
875
QVariantList argValues;
@@ -900,7 +908,7 @@ bool QgsExpression::NodeFunction::prepare( QgsExpression* parent, const QgsField
900
908
901
909
QString QgsExpression::NodeFunction::dump () const
902
910
{
903
- const FnDef & fd = BuiltinFunctions[mFnIndex ];
911
+ const FunctionDef & fd = BuiltinFunctions () [mFnIndex ];
904
912
if ( fd.mParams == 0 )
905
913
return fd.mName ; // special column
906
914
else
@@ -930,7 +938,7 @@ QString QgsExpression::NodeLiteral::dump() const
930
938
case QVariant::Int: return QString::number ( mValue .toInt () );
931
939
case QVariant::Double: return QString::number ( mValue .toDouble () );
932
940
case QVariant::String: return QString ( " '%1'" ).arg ( mValue .toString () );
933
- default : return QString ( " [unsupported type;%1; value:%2]" ).arg ( mValue .typeName () ).arg ( mValue .toString () );
941
+ default : return QObject::tr ( " [unsupported type;%1; value:%2]" ).arg ( mValue .typeName () ).arg ( mValue .toString () );
934
942
}
935
943
}
936
944
0 commit comments