@@ -113,11 +113,19 @@ class CORE_EXPORT QgsExpression
113
113
114
114
// ! Evaluate the feature and return the result
115
115
// ! @note prepare() should be called before calling this method
116
- QVariant evaluate ( QgsFeature* f = NULL );
116
+ QVariant evaluate ( const QgsFeature* f = NULL );
117
+
118
+ // ! Evaluate the feature and return the result
119
+ // ! @note prepare() should be called before calling this method
120
+ inline QVariant evaluate ( const QgsFeature& f ) { return evaluate ( &f ); }
121
+
122
+ // ! Evaluate the feature and return the result
123
+ // ! @note this method does not expect that prepare() has been called on this instance
124
+ QVariant evaluate ( const QgsFeature* f, const QgsFields& fields );
117
125
118
126
// ! Evaluate the feature and return the result
119
127
// ! @note this method does not expect that prepare() has been called on this instance
120
- QVariant evaluate ( QgsFeature* f, const QgsFields& fields );
128
+ inline QVariant evaluate ( const QgsFeature& f, const QgsFields& fields ) { return evaluate ( &f, fields ); }
121
129
122
130
// ! Returns true if an error occurred when evaluating last input
123
131
bool hasEvalError () const { return !mEvalErrorString .isNull (); }
@@ -223,7 +231,7 @@ class CORE_EXPORT QgsExpression
223
231
static const char * BinaryOperatorText[];
224
232
static const char * UnaryOperatorText[];
225
233
226
- typedef QVariant ( *FcnEval )( const QVariantList& values, QgsFeature* f, QgsExpression* parent );
234
+ typedef QVariant ( *FcnEval )( const QVariantList& values, const QgsFeature* f, QgsExpression* parent );
227
235
228
236
229
237
/* *
@@ -245,7 +253,7 @@ class CORE_EXPORT QgsExpression
245
253
/* * The help text for the function. */
246
254
QString helptext () { return mHelpText .isEmpty () ? QgsExpression::helptext ( mName ) : mHelpText ; }
247
255
248
- virtual QVariant func ( const QVariantList& values, QgsFeature* f, QgsExpression* parent ) = 0;
256
+ virtual QVariant func ( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) = 0;
249
257
250
258
bool operator ==( const Function& other ) const
251
259
{
@@ -269,7 +277,7 @@ class CORE_EXPORT QgsExpression
269
277
StaticFunction ( QString fnname, int params, FcnEval fcn, QString group, QString helpText = QString(), bool usesGeometry = false )
270
278
: Function( fnname, params, group, helpText, usesGeometry ), mFnc ( fcn ) {}
271
279
272
- virtual QVariant func ( const QVariantList& values, QgsFeature* f, QgsExpression* parent )
280
+ virtual QVariant func ( const QVariantList& values, const QgsFeature* f, QgsExpression* parent )
273
281
{
274
282
return mFnc ( values, f, parent );
275
283
}
@@ -330,7 +338,7 @@ class CORE_EXPORT QgsExpression
330
338
virtual NodeType nodeType () const = 0;
331
339
// abstract virtual eval function
332
340
// errors are reported to the parent
333
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f ) = 0;
341
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f ) = 0;
334
342
335
343
// abstract virtual preparation function
336
344
// errors are reported to the parent
@@ -401,7 +409,7 @@ class CORE_EXPORT QgsExpression
401
409
402
410
virtual NodeType nodeType () const { return ntUnaryOperator; }
403
411
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
404
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
412
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
405
413
virtual QString dump () const ;
406
414
407
415
virtual QStringList referencedColumns () const { return mOperand ->referencedColumns (); }
@@ -425,7 +433,7 @@ class CORE_EXPORT QgsExpression
425
433
426
434
virtual NodeType nodeType () const { return ntBinaryOperator; }
427
435
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
428
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
436
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
429
437
virtual QString dump () const ;
430
438
431
439
virtual QStringList referencedColumns () const { return mOpLeft ->referencedColumns () + mOpRight ->referencedColumns (); }
@@ -455,7 +463,7 @@ class CORE_EXPORT QgsExpression
455
463
456
464
virtual NodeType nodeType () const { return ntInOperator; }
457
465
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
458
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
466
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
459
467
virtual QString dump () const ;
460
468
461
469
virtual QStringList referencedColumns () const { QStringList lst ( mNode ->referencedColumns () ); foreach ( Node* n, mList ->list () ) lst.append ( n->referencedColumns () ); return lst; }
@@ -480,7 +488,7 @@ class CORE_EXPORT QgsExpression
480
488
481
489
virtual NodeType nodeType () const { return ntFunction; }
482
490
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
483
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
491
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
484
492
virtual QString dump () const ;
485
493
486
494
virtual QStringList referencedColumns () const { QStringList lst; if ( !mArgs ) return lst; foreach ( Node* n, mArgs ->list () ) lst.append ( n->referencedColumns () ); return lst; }
@@ -502,7 +510,7 @@ class CORE_EXPORT QgsExpression
502
510
503
511
virtual NodeType nodeType () const { return ntLiteral; }
504
512
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
505
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
513
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
506
514
virtual QString dump () const ;
507
515
508
516
virtual QStringList referencedColumns () const { return QStringList (); }
@@ -522,7 +530,7 @@ class CORE_EXPORT QgsExpression
522
530
523
531
virtual NodeType nodeType () const { return ntColumnRef; }
524
532
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
525
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
533
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
526
534
virtual QString dump () const ;
527
535
528
536
virtual QStringList referencedColumns () const { return QStringList ( mName ); }
@@ -553,7 +561,7 @@ class CORE_EXPORT QgsExpression
553
561
~NodeCondition () { delete mElseExp ; foreach ( WhenThen* cond, mConditions ) delete cond; }
554
562
555
563
virtual NodeType nodeType () const { return ntCondition; }
556
- virtual QVariant eval ( QgsExpression* parent, QgsFeature* f );
564
+ virtual QVariant eval ( QgsExpression* parent, const QgsFeature* f );
557
565
virtual bool prepare ( QgsExpression* parent, const QgsFields& fields );
558
566
virtual QString dump () const ;
559
567
0 commit comments