QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsexpression.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpression.h
3  -------------------
4  begin : August 2011
5  copyright : (C) 2011 Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
18 
19 #include <QMetaType>
20 #include <QStringList>
21 #include <QVariant>
22 #include <QList>
23 #include <QDomDocument>
24 #include "qgis.h"
25 
26 class QgsFeature;
27 class QgsGeometry;
28 class QgsOgcUtils;
29 class QgsVectorLayer;
31 class QgsField;
32 class QgsFields;
33 class QgsDistanceArea;
34 class QDomElement;
36 
88 class CORE_EXPORT QgsExpression
89 {
90  public:
91  QgsExpression( const QString& expr );
92  ~QgsExpression();
93 
95  bool hasParserError() const { return !mParserErrorString.isNull(); }
97  QString parserErrorString() const { return mParserErrorString; }
98 
99  class Node;
100 
102  const Node* rootNode() const { return mRootNode; }
103 
105  Q_DECL_DEPRECATED bool prepare( const QgsFields &fields );
106 
111  bool prepare( const QgsExpressionContext *context );
112 
119  QStringList referencedColumns() const;
120 
122  bool needsGeometry() const;
123 
124  // evaluation
125 
128  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f );
129 
133  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f );
134 
137  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f, const QgsFields& fields );
138 
142  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f, const QgsFields& fields );
143 
148  QVariant evaluate();
149 
155  QVariant evaluate( const QgsExpressionContext* context );
156 
158  bool hasEvalError() const { return !mEvalErrorString.isNull(); }
160  QString evalErrorString() const { return mEvalErrorString; }
162  void setEvalErrorString( const QString& str ) { mEvalErrorString = str; }
163 
165  Q_DECL_DEPRECATED void setCurrentRowNumber( int rowNumber ) { mRowNumber = rowNumber; }
167  Q_DECL_DEPRECATED int currentRowNumber() { return mRowNumber; }
168 
170  static void setSpecialColumn( const QString& name, QVariant value );
172  static void unsetSpecialColumn( const QString& name );
174  static QVariant specialColumn( const QString& name );
177  static bool hasSpecialColumn( const QString& name );
178 
182  bool isField() const { return rootNode() && dynamic_cast<const NodeColumnRef*>( rootNode() ) ;}
183 
184  Q_DECL_DEPRECATED static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
185 
193  static bool isValid( const QString& text, const QgsExpressionContext* context, QString &errorMessage );
194 
195  void setScale( double scale ) { mScale = scale; }
196 
197  double scale() { return mScale; }
198 
200  const QString expression() const
201  {
202  if ( !mExp.isNull() )
203  return mExp;
204  else
205  return dump();
206  }
207 
209  QString dump() const;
210 
213  QgsDistanceArea *geomCalculator() { initGeomCalculator(); return mCalc; }
214 
216  // instead of the default.
217  void setGeomCalculator( const QgsDistanceArea &calc );
218 
232  Q_DECL_DEPRECATED static QString replaceExpressionText( const QString &action, const QgsFeature *feat,
233  QgsVectorLayer *layer,
234  const QMap<QString, QVariant> *substitutionMap = 0,
235  const QgsDistanceArea* distanceArea = 0
236  );
237 
249  static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
250  const QMap<QString, QVariant> *substitutionMap = 0,
251  const QgsDistanceArea* distanceArea = 0
252  );
253 
263  static double evaluateToDouble( const QString& text, const double fallbackValue );
264 
270  {
273  };
274 
280  {
281  // logical
284 
285  // comparison
286  boEQ, // =
287  boNE, // <>
288  boLE, // <=
289  boGE, // >=
290  boLT, // <
291  boGT, // >
299 
300  // math
308 
309  // strings
311  };
313  {
323  };
324 
325  static const char* BinaryOperatorText[];
326  static const char* UnaryOperatorText[];
327 
328  typedef QVariant( *FcnEval )( const QVariantList& values, const QgsFeature* f, QgsExpression* parent );
329 
332  typedef QVariant( *FcnEvalContext )( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
333 
337  class CORE_EXPORT Function
338  {
339  public:
340  Function( const QString& fnname,
341  int params,
342  QString group,
343  QString helpText = QString(),
344  bool usesGeometry = false,
345  QStringList referencedColumns = QStringList(),
346  bool lazyEval = false,
347  bool handlesNull = false,
348  bool isContextual = false )
349  : mName( fnname )
350  , mParams( params )
351  , mUsesGeometry( usesGeometry )
352  , mGroup( group )
353  , mHelpText( helpText )
354  , mReferencedColumns( referencedColumns )
355  , mLazyEval( lazyEval )
356  , mHandlesNull( handlesNull )
357  , mIsContextual( isContextual )
358  {}
359 
360  virtual ~Function() {}
361 
363  QString name() { return mName; }
365  int params() { return mParams; }
367  bool usesgeometry() { return mUsesGeometry; }
368 
374  virtual QStringList aliases() const { return QStringList(); }
375 
379  bool lazyEval() { return mLazyEval; }
380 
381  virtual QStringList referencedColumns() const { return mReferencedColumns; }
382 
386  bool isContextual() const { return mIsContextual; }
387 
389  QString group() { return mGroup; }
391  const QString helptext() { return mHelpText.isEmpty() ? QgsExpression::helptext( mName ) : mHelpText; }
392 
393  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList&, const QgsFeature*, QgsExpression* );
394 
401  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
402 
403  bool operator==( const Function& other ) const
404  {
405  if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
406  return true;
407 
408  return false;
409  }
410 
411  virtual bool handlesNull() const { return mHandlesNull; }
412 
413  private:
414  QString mName;
415  int mParams;
416  bool mUsesGeometry;
417  QString mGroup;
418  QString mHelpText;
419  QStringList mReferencedColumns;
420  bool mLazyEval;
421  bool mHandlesNull;
422  bool mIsContextual; //if true function is only available through an expression context
423  };
424 
425  class StaticFunction : public Function
426  {
427  public:
428  Q_DECL_DEPRECATED StaticFunction( QString fnname,
429  int params,
430  FcnEval fcn,
431  QString group,
432  QString helpText = QString(),
433  bool usesGeometry = false,
434  QStringList referencedColumns = QStringList(),
435  bool lazyEval = false,
436  const QStringList& aliases = QStringList(),
437  bool handlesNull = false )
438  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
439  , mFnc( fcn )
440  , mContextFnc( 0 )
441  , mAliases( aliases )
442  {}
443 
444  virtual ~StaticFunction() {}
445 
449  int params,
450  FcnEvalContext fcn,
451  QString group,
452  QString helpText = QString(),
453  bool usesGeometry = false,
454  QStringList referencedColumns = QStringList(),
455  bool lazyEval = false,
456  const QStringList& aliases = QStringList(),
457  bool handlesNull = false )
458  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
459  , mFnc( 0 )
460  , mContextFnc( fcn )
461  , mAliases( aliases )
462  {}
463  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) override;
464 
471  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) override
472  {
473  return mContextFnc ? mContextFnc( values, context, parent ) : QVariant();
474  }
475 
476  virtual QStringList aliases() const override { return mAliases; }
477 
478  private:
479  FcnEval mFnc;
480  FcnEvalContext mContextFnc;
481  QStringList mAliases;
482  };
483 
485  static const QList<Function*>& Functions();
486 
488  static const QStringList& BuiltinFunctions();
489 
496  static bool registerFunction( Function* function, bool transferOwnership = false );
497 
502  static bool unregisterFunction( QString name );
503 
506 
510  static void cleanRegisteredFunctions();
511 
512  // tells whether the identifier is a name of existing function
513  static bool isFunctionName( const QString& name );
514 
515  // return index of the function in Functions array
516  static int functionIndex( const QString& name );
517 
521  static int functionCount();
522 
526  static QList<Function*> specialColumns();
527 
529  static QString quotedColumnRef( QString name );
531  static QString quotedString( QString text );
532 
534 
535  class Visitor; // visitor interface is defined below
536 
537  enum NodeType
538  {
545  ntCondition
546  };
547 
548  class CORE_EXPORT Node
549  {
550  public:
551  virtual ~Node() {}
552 
558  virtual NodeType nodeType() const = 0;
559 
564  Q_DECL_DEPRECATED virtual QVariant eval( QgsExpression* parent, const QgsFeature* f );
565 
571  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
572 
577  Q_DECL_DEPRECATED virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
578 
584  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
585 
591  virtual QString dump() const = 0;
592 
603  virtual QStringList referencedColumns() const = 0;
604 
613  virtual bool needsGeometry() const = 0;
614 
630  virtual void accept( Visitor& v ) const = 0;
631  };
632 
633  class CORE_EXPORT NodeList
634  {
635  public:
636  NodeList() {}
637  virtual ~NodeList() { qDeleteAll( mList ); }
639  void append( Node* node ) { mList.append( node ); }
640  int count() { return mList.count(); }
641  QList<Node*> list() { return mList; }
642 
643  virtual QString dump() const;
644 
645  protected:
647  };
648 
649  class CORE_EXPORT Interval
650  {
651  // YEAR const value taken from postgres query
652  // SELECT EXTRACT(EPOCH FROM interval '1 year')
653  static const int YEARS = 31557600;
654  static const int MONTHS = 60 * 60 * 24 * 30;
655  static const int WEEKS = 60 * 60 * 24 * 7;
656  static const int DAY = 60 * 60 * 24;
657  static const int HOUR = 60 * 60;
658  static const int MINUTE = 60;
659  public:
660  Interval( double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
661  ~Interval();
662  double years() { return mSeconds / YEARS;}
663  double months() { return mSeconds / MONTHS; }
664  double weeks() { return mSeconds / WEEKS;}
665  double days() { return mSeconds / DAY;}
666  double hours() { return mSeconds / HOUR;}
667  double minutes() { return mSeconds / MINUTE;}
668  double seconds() { return mSeconds; }
669  bool isValid() { return mValid; }
670  void setValid( bool valid ) { mValid = valid; }
671  bool operator==( const QgsExpression::Interval& other ) const;
672  static QgsExpression::Interval invalidInterVal();
673  static QgsExpression::Interval fromString( QString string );
674  private:
675  double mSeconds;
676  bool mValid;
677  };
678 
679  class CORE_EXPORT NodeUnaryOperator : public Node
680  {
681  public:
682  NodeUnaryOperator( UnaryOperator op, Node* operand ) : mOp( op ), mOperand( operand ) {}
683  ~NodeUnaryOperator() { delete mOperand; }
684 
685  UnaryOperator op() const { return mOp; }
686  Node* operand() const { return mOperand; }
687 
688  virtual NodeType nodeType() const override { return ntUnaryOperator; }
689  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
690  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
691  virtual QString dump() const override;
692 
693  virtual QStringList referencedColumns() const override { return mOperand->referencedColumns(); }
694  virtual bool needsGeometry() const override { return mOperand->needsGeometry(); }
695  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
696 
697  protected:
700  };
701 
702  class CORE_EXPORT NodeBinaryOperator : public Node
703  {
704  public:
705  NodeBinaryOperator( BinaryOperator op, Node* opLeft, Node* opRight ) : mOp( op ), mOpLeft( opLeft ), mOpRight( opRight ) {}
706  ~NodeBinaryOperator() { delete mOpLeft; delete mOpRight; }
707 
708  BinaryOperator op() const { return mOp; }
709  Node* opLeft() const { return mOpLeft; }
710  Node* opRight() const { return mOpRight; }
711 
712  virtual NodeType nodeType() const override { return ntBinaryOperator; }
713  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
714  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
715  virtual QString dump() const override;
716 
717  virtual QStringList referencedColumns() const override { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
718  virtual bool needsGeometry() const override { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
719  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
720 
721  int precedence() const;
722  bool leftAssociative() const;
723 
724  protected:
725  bool compare( double diff );
726  int computeInt( int x, int y );
727  double computeDouble( double x, double y );
728  QDateTime computeDateTimeFromInterval( QDateTime d, QgsExpression::Interval *i );
729 
733  };
734 
735  class CORE_EXPORT NodeInOperator : public Node
736  {
737  public:
738  NodeInOperator( Node* node, NodeList* list, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
739  virtual ~NodeInOperator() { delete mNode; delete mList; }
740 
741  Node* node() const { return mNode; }
742  bool isNotIn() const { return mNotIn; }
743  NodeList* list() const { return mList; }
744 
745  virtual NodeType nodeType() const override { return ntInOperator; }
746  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
747  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
748  virtual QString dump() const override;
749 
750  virtual QStringList referencedColumns() const override { QStringList lst( mNode->referencedColumns() ); foreach ( Node* n, mList->list() ) lst.append( n->referencedColumns() ); return lst; }
751  virtual bool needsGeometry() const override { bool needs = false; foreach ( Node* n, mList->list() ) needs |= n->needsGeometry(); return needs; }
752  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
753 
754  protected:
757  bool mNotIn;
758  };
759 
760  class CORE_EXPORT NodeFunction : public Node
761  {
762  public:
763  NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex ), mArgs( args ) {}
764  //NodeFunction( QString name, NodeList* args ) : mName(name), mArgs(args) {}
765  virtual ~NodeFunction() { delete mArgs; }
766 
767  int fnIndex() const { return mFnIndex; }
768  NodeList* args() const { return mArgs; }
769 
770  virtual NodeType nodeType() const override { return ntFunction; }
771  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
772  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
773  virtual QString dump() const override;
774 
775  virtual QStringList referencedColumns() const override;
776  virtual bool needsGeometry() const override { bool needs = Functions()[mFnIndex]->usesgeometry(); if ( mArgs ) { foreach ( Node* n, mArgs->list() ) needs |= n->needsGeometry(); } return needs; }
777  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
778 
779  protected:
780  //QString mName;
781  int mFnIndex;
783 
784  private:
785 
786  QgsExpression::Function* getFunc() const;
787  };
788 
789  class CORE_EXPORT NodeLiteral : public Node
790  {
791  public:
792  NodeLiteral( const QVariant& value ) : mValue( value ) {}
793 
794  inline QVariant value() const { return mValue; }
795 
796  virtual NodeType nodeType() const override { return ntLiteral; }
797  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
798  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
799  virtual QString dump() const override;
800 
801  virtual QStringList referencedColumns() const override { return QStringList(); }
802  virtual bool needsGeometry() const override { return false; }
803  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
804 
805  protected:
807  };
808 
809  class CORE_EXPORT NodeColumnRef : public Node
810  {
811  public:
812  NodeColumnRef( const QString& name ) : mName( name ), mIndex( -1 ) {}
813 
814  QString name() const { return mName; }
815 
816  virtual NodeType nodeType() const override { return ntColumnRef; }
817  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
818  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
819  virtual QString dump() const override;
820 
821  virtual QStringList referencedColumns() const override { return QStringList( mName ); }
822  virtual bool needsGeometry() const override { return false; }
823 
824  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
825 
826  protected:
828  int mIndex;
829  };
830 
831  class CORE_EXPORT WhenThen
832  {
833  public:
834  WhenThen( Node* whenExp, Node* thenExp ) : mWhenExp( whenExp ), mThenExp( thenExp ) {}
835  ~WhenThen() { delete mWhenExp; delete mThenExp; }
836 
837  //protected:
840  };
842 
843  class CORE_EXPORT NodeCondition : public Node
844  {
845  public:
846  NodeCondition( WhenThenList* conditions, Node* elseExp = NULL ) : mConditions( *conditions ), mElseExp( elseExp ) { delete conditions; }
847  ~NodeCondition() { delete mElseExp; qDeleteAll( mConditions ); }
848 
849  virtual NodeType nodeType() const override { return ntCondition; }
850  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
851  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
852  virtual QString dump() const override;
853 
854  virtual QStringList referencedColumns() const override;
855  virtual bool needsGeometry() const override;
856  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
857 
858  protected:
859  WhenThenList mConditions;
861  };
862 
864 
867  class CORE_EXPORT Visitor
868  {
869  public:
870  virtual ~Visitor() {}
871  virtual void visit( const NodeUnaryOperator& n ) = 0;
872  virtual void visit( const NodeBinaryOperator& n ) = 0;
873  virtual void visit( const NodeInOperator& n ) = 0;
874  virtual void visit( const NodeFunction& n ) = 0;
875  virtual void visit( const NodeLiteral& n ) = 0;
876  virtual void visit( const NodeColumnRef& n ) = 0;
877  virtual void visit( const NodeCondition& n ) = 0;
878  };
879 
881  void acceptVisitor( Visitor& v ) const;
882 
887  static QString helptext( QString name );
888 
896  static QString variableHelpText( const QString& variableName, bool showValue = true, const QVariant& value = QVariant() );
897 
901  static QString group( QString group );
902 
903  protected:
907  QgsExpression() : mRootNode( 0 ), mRowNumber( 0 ), mScale( 0.0 ), mCalc( 0 ) {}
908 
909  void initGeomCalculator();
910 
912 
915 
917  double mScale;
919 
921 
924 
928 
929  static void initFunctionHelp();
930  static void initVariableHelp();
931 
932  friend class QgsOgcUtils;
933 
934  private:
935  Q_DISABLE_COPY( QgsExpression ) // for now - until we have proper copy constructor / implicit sharing
936 };
937 
940 
941 #endif // QGSEXPRESSION_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:88
virtual QStringList referencedColumns() const =0
Abstract virtual method which returns a list of columns required to evaluate this node...
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
UnaryOperator
list of unary operators
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
virtual Q_DECL_DEPRECATED QVariant eval(QgsExpression *parent, const QgsFeature *f)
Abstract virtual eval method Errors are reported to the parent.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Definition: qgsexpression.h:95
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
virtual bool handlesNull() const
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
bool lazyEval()
True if this function should use lazy evaluation.
const QString expression() const
Alias for dump()
Node is a class used by Line3D.
Definition: Node.h:23
A abstract base class for defining QgsExpression functions.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual QString dump() const =0
Abstract virtual dump method.
NodeCondition(WhenThenList *conditions, Node *elseExp=NULL)
NodeColumnRef(const QString &name)
static QString helptext(QString name)
Returns the help text for a specified function.
QgsExpression()
Used by QgsOgcUtils to create an empty.
Container of fields for a vector layer.
Definition: qgsfield.h:177
virtual Q_DECL_DEPRECATED bool prepare(QgsExpression *parent, const QgsFields &fields)
Abstract virtual preparation method Errors are reported to the parent.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
Q_DECL_DEPRECATED int currentRowNumber()
Return the number used for $rownum special column.
Interval(double seconds=0)
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
NodeList * list() const
Q_DECL_DEPRECATED StaticFunction(QString fnname, int params, FcnEval fcn, QString group, QString helpText=QString(), bool usesGeometry=false, QStringList referencedColumns=QStringList(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
QVariant value() const
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString mEvalErrorString
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
void setEvalErrorString(const QString &str)
Set evaluation error (used internally by evaluation functions)
NodeBinaryOperator(BinaryOperator op, Node *opLeft, Node *opRight)
QString mParserErrorString
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
static const QList< Function * > & Functions()
static QHash< QString, QString > gFunctionHelpTexts
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
void append(const T &value)
QgsDistanceArea * geomCalculator()
Return calculator used for distance and area calculations (used by internal functions) ...
NodeList * args() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QgsDistanceArea * mCalc
QList< Node * > mList
bool isContextual() const
Returns whether the function is only available if provided by a QgsExpressionContext object...
static QHash< QString, QString > gGroups
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
bool isEmpty() const
virtual QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent) override
Returns result of evaluating the function.
NodeInOperator(Node *node, NodeList *list, bool notin=false)
static QHash< QString, QString > gVariableHelpTexts
bool isField() const
Checks whether an expression consists only of a single field reference.
double scale()
static QList< Function * > gmFunctions
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:40
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString name()
The name of the function.
WhenThen(Node *whenExp, Node *thenExp)
NodeUnaryOperator(UnaryOperator op, Node *operand)
BinaryOperator op() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
virtual QStringList referencedColumns() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
NodeFunction(int fnIndex, NodeList *args)
General purpose distance and area calculator.
Q_DECL_DEPRECATED void setCurrentRowNumber(int rowNumber)
Set the number for $rownum special column.
static QMap< QString, QString > gmSpecialColumnGroups
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
virtual void accept(Visitor &v) const override
Support the visitor pattern.
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
BinaryOperator
list of binary operators
QString group()
The group the function belongs to.
QList< WhenThen * > WhenThenList
virtual QStringList aliases() const
Returns a list of possible aliases for the function.
virtual void visit(const NodeUnaryOperator &n)=0
int params()
The number of parameters this function takes.
NodeLiteral(const QVariant &value)
const QString helptext()
The help text for the function.
Support for visitor pattern - algorithms dealing with the expressions may be implemented without modi...
virtual bool needsGeometry() const =0
Abstract virtual method which returns if the geometry is required to evaluate this expression...
bool operator==(const Function &other) const
static QStringList gmBuiltinFunctions
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
StaticFunction(QString fnname, int params, FcnEvalContext fcn, QString group, QString helpText=QString(), bool usesGeometry=false, QStringList referencedColumns=QStringList(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext.
void append(Node *node)
Takes ownership of the provided node.
UnaryOperator op() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
Function(const QString &fnname, int params, QString group, QString helpText=QString(), bool usesGeometry=false, QStringList referencedColumns=QStringList(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
void setValid(bool valid)
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
static QList< Function * > gmOwnedFunctions
List of functions owned by the expression engine.
This is the base class for vector data providers.
void setScale(double scale)
Represents a vector layer which manages a vector based data sets.
int compare(const QString &other) const
virtual QStringList aliases() const override
Returns a list of possible aliases for the function.
QString parserErrorString() const
Returns parser error.
Definition: qgsexpression.h:97
Q_DECLARE_METATYPE(QgsExpression::Interval)
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:28
QString evalErrorString() const
Returns evaluation error.
bool usesgeometry()
Does this function use a geometry object.
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
QList< Node * > list()
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
static QMap< QString, QVariant > gmSpecialColumns