QGIS API Documentation  2.12.0-Lyon
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 <QCoreApplication>
25 
26 #include "qgis.h"
27 
28 class QgsFeature;
29 class QgsGeometry;
30 class QgsOgcUtils;
31 class QgsVectorLayer;
33 class QgsField;
34 class QgsFields;
35 class QgsDistanceArea;
36 class QDomElement;
38 
92 class CORE_EXPORT QgsExpression
93 {
94  Q_DECLARE_TR_FUNCTIONS( QgsExpression )
95  public:
96  QgsExpression( const QString& expr );
97  ~QgsExpression();
98 
100  bool hasParserError() const { return !mParserErrorString.isNull(); }
102  QString parserErrorString() const { return mParserErrorString; }
103 
104  class Node;
105 
107  const Node* rootNode() const { return mRootNode; }
108 
110  Q_DECL_DEPRECATED bool prepare( const QgsFields &fields );
111 
116  bool prepare( const QgsExpressionContext *context );
117 
124  QStringList referencedColumns() const;
125 
127  bool needsGeometry() const;
128 
129  // evaluation
130 
133  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f );
134 
138  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f );
139 
142  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f, const QgsFields& fields );
143 
147  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f, const QgsFields& fields );
148 
153  QVariant evaluate();
154 
160  QVariant evaluate( const QgsExpressionContext* context );
161 
163  bool hasEvalError() const { return !mEvalErrorString.isNull(); }
165  QString evalErrorString() const { return mEvalErrorString; }
167  void setEvalErrorString( const QString& str ) { mEvalErrorString = str; }
168 
170  Q_DECL_DEPRECATED void setCurrentRowNumber( int rowNumber ) { mRowNumber = rowNumber; }
172  Q_DECL_DEPRECATED int currentRowNumber() { return mRowNumber; }
173 
174  //TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
175  //but should not be publicly used
179  Q_DECL_DEPRECATED static void setSpecialColumn( const QString& name, const QVariant& value );
183  Q_DECL_DEPRECATED static void unsetSpecialColumn( const QString& name );
187  Q_DECL_DEPRECATED static QVariant specialColumn( const QString& name );
188 
192  static bool hasSpecialColumn( const QString& name );
193 
197  bool isField() const { return rootNode() && dynamic_cast<const NodeColumnRef*>( rootNode() ) ;}
198 
199  Q_DECL_DEPRECATED static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
200 
208  static bool isValid( const QString& text, const QgsExpressionContext* context, QString &errorMessage );
209 
210  void setScale( double scale ) { mScale = scale; }
211 
212  double scale() { return mScale; }
213 
215  const QString expression() const
216  {
217  if ( !mExp.isNull() )
218  return mExp;
219  else
220  return dump();
221  }
222 
224  QString dump() const;
225 
228  QgsDistanceArea *geomCalculator() { initGeomCalculator(); return mCalc; }
229 
231  // instead of the default.
232  void setGeomCalculator( const QgsDistanceArea &calc );
233 
247  Q_DECL_DEPRECATED static QString replaceExpressionText( const QString &action, const QgsFeature *feat,
248  QgsVectorLayer *layer,
249  const QMap<QString, QVariant> *substitutionMap = 0,
250  const QgsDistanceArea* distanceArea = 0
251  );
252 
264  static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
265  const QMap<QString, QVariant> *substitutionMap = 0,
266  const QgsDistanceArea* distanceArea = 0
267  );
268 
278  static double evaluateToDouble( const QString& text, const double fallbackValue );
279 
285  {
288  };
289 
295  {
296  // logical
299 
300  // comparison
301  boEQ, // =
302  boNE, // <>
303  boLE, // <=
304  boGE, // >=
305  boLT, // <
306  boGT, // >
314 
315  // math
323 
324  // strings
326  };
328  {
338  };
339 
340  static const char* BinaryOperatorText[];
341  static const char* UnaryOperatorText[];
342 
343  typedef QVariant( *FcnEval )( const QVariantList& values, const QgsFeature* f, QgsExpression* parent );
344 
347  typedef QVariant( *FcnEvalContext )( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
348 
352  class CORE_EXPORT Function
353  {
354  public:
355  Function( const QString& fnname,
356  int params,
357  const QString& group,
358  const QString& helpText = QString(),
359  bool usesGeometry = false,
360  const QStringList& referencedColumns = QStringList(),
361  bool lazyEval = false,
362  bool handlesNull = false,
363  bool isContextual = false )
364  : mName( fnname )
365  , mParams( params )
366  , mUsesGeometry( usesGeometry )
367  , mGroup( group )
368  , mHelpText( helpText )
369  , mReferencedColumns( referencedColumns )
370  , mLazyEval( lazyEval )
371  , mHandlesNull( handlesNull )
372  , mIsContextual( isContextual )
373  {}
374 
375  virtual ~Function() {}
376 
378  QString name() { return mName; }
380  int params() { return mParams; }
382  bool usesgeometry() { return mUsesGeometry; }
383 
389  virtual QStringList aliases() const { return QStringList(); }
390 
394  bool lazyEval() { return mLazyEval; }
395 
396  virtual QStringList referencedColumns() const { return mReferencedColumns; }
397 
401  bool isContextual() const { return mIsContextual; }
402 
404  QString group() { return mGroup; }
406  const QString helptext() { return mHelpText.isEmpty() ? QgsExpression::helptext( mName ) : mHelpText; }
407 
408  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList&, const QgsFeature*, QgsExpression* );
409 
417  //TODO QGIS 3.0 - rename python method
418  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
419 
420  bool operator==( const Function& other ) const
421  {
422  if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
423  return true;
424 
425  return false;
426  }
427 
428  virtual bool handlesNull() const { return mHandlesNull; }
429 
430  private:
431  QString mName;
432  int mParams;
433  bool mUsesGeometry;
434  QString mGroup;
435  QString mHelpText;
436  QStringList mReferencedColumns;
437  bool mLazyEval;
438  bool mHandlesNull;
439  bool mIsContextual; //if true function is only available through an expression context
440  };
441 
442  class StaticFunction : public Function
443  {
444  public:
445  Q_DECL_DEPRECATED StaticFunction( const QString& fnname,
446  int params,
447  FcnEval fcn,
448  const QString& group,
449  const QString& helpText = QString(),
450  bool usesGeometry = false,
451  const QStringList& referencedColumns = QStringList(),
452  bool lazyEval = false,
453  const QStringList& aliases = QStringList(),
454  bool handlesNull = false )
455  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
456  , mFnc( fcn )
457  , mContextFnc( 0 )
458  , mAliases( aliases )
459  {}
460 
461  virtual ~StaticFunction() {}
462 
465  StaticFunction( const QString& fnname,
466  int params,
467  FcnEvalContext fcn,
468  const QString& group,
469  const QString& helpText = QString(),
470  bool usesGeometry = false,
471  const QStringList& referencedColumns = QStringList(),
472  bool lazyEval = false,
473  const QStringList& aliases = QStringList(),
474  bool handlesNull = false )
475  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
476  , mFnc( 0 )
477  , mContextFnc( fcn )
478  , mAliases( aliases )
479  {}
480 
481  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) override;
482 
489  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) override
490  {
491  return mContextFnc ? mContextFnc( values, context, parent ) : QVariant();
492  }
493 
494  virtual QStringList aliases() const override { return mAliases; }
495 
496  private:
497  FcnEval mFnc;
498  FcnEvalContext mContextFnc;
499  QStringList mAliases;
500  };
501 
503  static const QList<Function*>& Functions();
504 
506  static const QStringList& BuiltinFunctions();
507 
514  static bool registerFunction( Function* function, bool transferOwnership = false );
515 
520  static bool unregisterFunction( const QString& name );
521 
524 
528  static void cleanRegisteredFunctions();
529 
530  // tells whether the identifier is a name of existing function
531  static bool isFunctionName( const QString& name );
532 
533  // return index of the function in Functions array
534  static int functionIndex( const QString& name );
535 
539  static int functionCount();
540 
544  static QList<Function*> specialColumns();
545 
547  static QString quotedColumnRef( QString name );
549  static QString quotedString( QString text );
550 
552 
553  class Visitor; // visitor interface is defined below
554 
555  enum NodeType
556  {
563  ntCondition
564  };
565 
566  class CORE_EXPORT Node
567  {
568  public:
569  virtual ~Node() {}
570 
576  virtual NodeType nodeType() const = 0;
577 
582  Q_DECL_DEPRECATED virtual QVariant eval( QgsExpression* parent, const QgsFeature* f );
583 
589  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
590 
595  Q_DECL_DEPRECATED virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
596 
602  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
603 
609  virtual QString dump() const = 0;
610 
621  virtual QStringList referencedColumns() const = 0;
622 
631  virtual bool needsGeometry() const = 0;
632 
648  virtual void accept( Visitor& v ) const = 0;
649  };
650 
651  class CORE_EXPORT NodeList
652  {
653  public:
654  NodeList() {}
655  virtual ~NodeList() { qDeleteAll( mList ); }
657  void append( Node* node ) { mList.append( node ); }
658  int count() { return mList.count(); }
659  QList<Node*> list() { return mList; }
660 
661  virtual QString dump() const;
662 
663  protected:
665  };
666 
667  class CORE_EXPORT Interval
668  {
669  // YEAR const value taken from postgres query
670  // SELECT EXTRACT(EPOCH FROM interval '1 year')
671  static const int YEARS = 31557600;
672  static const int MONTHS = 60 * 60 * 24 * 30;
673  static const int WEEKS = 60 * 60 * 24 * 7;
674  static const int DAY = 60 * 60 * 24;
675  static const int HOUR = 60 * 60;
676  static const int MINUTE = 60;
677  public:
678  Interval( double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
679  ~Interval();
680  double years() { return mSeconds / YEARS;}
681  double months() { return mSeconds / MONTHS; }
682  double weeks() { return mSeconds / WEEKS;}
683  double days() { return mSeconds / DAY;}
684  double hours() { return mSeconds / HOUR;}
685  double minutes() { return mSeconds / MINUTE;}
686  double seconds() { return mSeconds; }
687  bool isValid() { return mValid; }
688  void setValid( bool valid ) { mValid = valid; }
689  bool operator==( const QgsExpression::Interval& other ) const;
690  static QgsExpression::Interval invalidInterVal();
691  static QgsExpression::Interval fromString( const QString& string );
692  private:
693  double mSeconds;
694  bool mValid;
695  };
696 
697  class CORE_EXPORT NodeUnaryOperator : public Node
698  {
699  public:
700  NodeUnaryOperator( UnaryOperator op, Node* operand ) : mOp( op ), mOperand( operand ) {}
701  ~NodeUnaryOperator() { delete mOperand; }
702 
703  UnaryOperator op() const { return mOp; }
704  Node* operand() const { return mOperand; }
705 
706  virtual NodeType nodeType() const override { return ntUnaryOperator; }
707  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
708  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
709  virtual QString dump() const override;
710 
711  virtual QStringList referencedColumns() const override { return mOperand->referencedColumns(); }
712  virtual bool needsGeometry() const override { return mOperand->needsGeometry(); }
713  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
714 
715  protected:
718  };
719 
720  class CORE_EXPORT NodeBinaryOperator : public Node
721  {
722  public:
723  NodeBinaryOperator( BinaryOperator op, Node* opLeft, Node* opRight ) : mOp( op ), mOpLeft( opLeft ), mOpRight( opRight ) {}
724  ~NodeBinaryOperator() { delete mOpLeft; delete mOpRight; }
725 
726  BinaryOperator op() const { return mOp; }
727  Node* opLeft() const { return mOpLeft; }
728  Node* opRight() const { return mOpRight; }
729 
730  virtual NodeType nodeType() const override { return ntBinaryOperator; }
731  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
732  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
733  virtual QString dump() const override;
734 
735  virtual QStringList referencedColumns() const override { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
736  virtual bool needsGeometry() const override { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
737  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
738 
739  int precedence() const;
740  bool leftAssociative() const;
741 
742  protected:
743  bool compare( double diff );
744  int computeInt( int x, int y );
745  double computeDouble( double x, double y );
746  QDateTime computeDateTimeFromInterval( const QDateTime& d, QgsExpression::Interval *i );
747 
751  };
752 
753  class CORE_EXPORT NodeInOperator : public Node
754  {
755  public:
756  NodeInOperator( Node* node, NodeList* list, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
757  virtual ~NodeInOperator() { delete mNode; delete mList; }
758 
759  Node* node() const { return mNode; }
760  bool isNotIn() const { return mNotIn; }
761  NodeList* list() const { return mList; }
762 
763  virtual NodeType nodeType() const override { return ntInOperator; }
764  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
765  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
766  virtual QString dump() const override;
767 
768  virtual QStringList referencedColumns() const override { QStringList lst( mNode->referencedColumns() ); Q_FOREACH ( Node* n, mList->list() ) lst.append( n->referencedColumns() ); return lst; }
769  virtual bool needsGeometry() const override { bool needs = false; Q_FOREACH ( Node* n, mList->list() ) needs |= n->needsGeometry(); return needs; }
770  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
771 
772  protected:
775  bool mNotIn;
776  };
777 
778  class CORE_EXPORT NodeFunction : public Node
779  {
780  public:
781  NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex ), mArgs( args ) {}
782  //NodeFunction( QString name, NodeList* args ) : mName(name), mArgs(args) {}
783  virtual ~NodeFunction() { delete mArgs; }
784 
785  int fnIndex() const { return mFnIndex; }
786  NodeList* args() const { return mArgs; }
787 
788  virtual NodeType nodeType() const override { return ntFunction; }
789  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
790  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
791  virtual QString dump() const override;
792 
793  virtual QStringList referencedColumns() const override;
794  virtual bool needsGeometry() const override { bool needs = Functions()[mFnIndex]->usesgeometry(); if ( mArgs ) { Q_FOREACH ( Node* n, mArgs->list() ) needs |= n->needsGeometry(); } return needs; }
795  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
796 
797  protected:
798  //QString mName;
799  int mFnIndex;
801 
802  private:
803 
804  QgsExpression::Function* getFunc() const;
805  };
806 
807  class CORE_EXPORT NodeLiteral : public Node
808  {
809  public:
810  NodeLiteral( const QVariant& value ) : mValue( value ) {}
811 
812  inline QVariant value() const { return mValue; }
813 
814  virtual NodeType nodeType() const override { return ntLiteral; }
815  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
816  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
817  virtual QString dump() const override;
818 
819  virtual QStringList referencedColumns() const override { return QStringList(); }
820  virtual bool needsGeometry() const override { return false; }
821  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
822 
823  protected:
825  };
826 
827  class CORE_EXPORT NodeColumnRef : public Node
828  {
829  public:
830  NodeColumnRef( const QString& name ) : mName( name ), mIndex( -1 ) {}
831 
832  QString name() const { return mName; }
833 
834  virtual NodeType nodeType() const override { return ntColumnRef; }
835  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
836  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
837  virtual QString dump() const override;
838 
839  virtual QStringList referencedColumns() const override { return QStringList( mName ); }
840  virtual bool needsGeometry() const override { return false; }
841 
842  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
843 
844  protected:
846  int mIndex;
847  };
848 
849  class CORE_EXPORT WhenThen
850  {
851  public:
852  WhenThen( Node* whenExp, Node* thenExp ) : mWhenExp( whenExp ), mThenExp( thenExp ) {}
853  ~WhenThen() { delete mWhenExp; delete mThenExp; }
854 
855  //protected:
858  };
860 
861  class CORE_EXPORT NodeCondition : public Node
862  {
863  public:
864  NodeCondition( WhenThenList* conditions, Node* elseExp = NULL ) : mConditions( *conditions ), mElseExp( elseExp ) { delete conditions; }
865  ~NodeCondition() { delete mElseExp; qDeleteAll( mConditions ); }
866 
867  virtual NodeType nodeType() const override { return ntCondition; }
868  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
869  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
870  virtual QString dump() const override;
871 
872  virtual QStringList referencedColumns() const override;
873  virtual bool needsGeometry() const override;
874  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
875 
876  protected:
877  WhenThenList mConditions;
879  };
880 
882 
885  class CORE_EXPORT Visitor
886  {
887  public:
888  virtual ~Visitor() {}
889  virtual void visit( const NodeUnaryOperator& n ) = 0;
890  virtual void visit( const NodeBinaryOperator& n ) = 0;
891  virtual void visit( const NodeInOperator& n ) = 0;
892  virtual void visit( const NodeFunction& n ) = 0;
893  virtual void visit( const NodeLiteral& n ) = 0;
894  virtual void visit( const NodeColumnRef& n ) = 0;
895  virtual void visit( const NodeCondition& n ) = 0;
896  };
897 
899  void acceptVisitor( Visitor& v ) const;
900 
905  static QString helptext( QString name );
906 
914  static QString variableHelpText( const QString& variableName, bool showValue = true, const QVariant& value = QVariant() );
915 
919  static QString group( const QString& group );
920 
921  protected:
925  QgsExpression() : mRootNode( 0 ), mRowNumber( 0 ), mScale( 0.0 ), mCalc( 0 ) {}
926 
927  void initGeomCalculator();
928 
930 
933 
935  double mScale;
937 
939 
942 
943  struct HelpArg
944  {
945  HelpArg( const QString& arg, const QString& desc, bool descOnly = false, bool syntaxOnly = false )
946  : mArg( arg )
947  , mDescription( desc )
948  , mDescOnly( descOnly )
949  , mSyntaxOnly( syntaxOnly )
950  {}
951 
954  bool mDescOnly;
956  };
957 
958  struct HelpExample
959  {
960  HelpExample( const QString& expression, const QString& returns, const QString& note = QString::null )
961  : mExpression( expression )
962  , mReturns( returns )
963  , mNote( note )
964  {}
965 
969  };
970 
971  struct HelpVariant
972  {
973  HelpVariant( const QString& name, const QString& description,
974  const QList<HelpArg>& arguments = QList<HelpArg>(),
975  bool variableLenArguments = false,
976  const QList<HelpExample>& examples = QList<HelpExample>(),
977  const QString& notes = QString::null )
978  : mName( name )
979  , mDescription( description )
980  , mArguments( arguments )
981  , mVariableLenArguments( variableLenArguments )
982  , mExamples( examples )
983  , mNotes( notes )
984  {}
985 
992  };
993 
994  struct Help
995  {
996  Help() {}
997 
998  Help( const QString& name, const QString& type, const QString& description, const QList<HelpVariant>& variants )
999  : mName( name )
1000  , mType( type )
1001  , mDescription( description )
1002  , mVariants( variants )
1003  {}
1004 
1009  };
1010 
1014 
1015  static void initFunctionHelp();
1016  static void initVariableHelp();
1017 
1018  friend class QgsOgcUtils;
1019 
1020  private:
1021  Q_DISABLE_COPY( QgsExpression ) // for now - until we have proper copy constructor / implicit sharing
1022 };
1024 
1027 
1028 #endif // QGSEXPRESSION_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:92
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.
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
virtual bool handlesNull() const
Function(const QString &fnname, int params, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QStringList &referencedColumns=QStringList(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
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.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:390
QgsExpression()
Used by QgsOgcUtils to create an empty.
Q_DECL_DEPRECATED StaticFunction(const QString &fnname, int params, FcnEval fcn, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QStringList &referencedColumns=QStringList(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
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:76
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
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
QList< HelpVariant > mVariants
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()
HelpVariant(const QString &name, const QString &description, const QList< HelpArg > &arguments=QList< HelpArg >(), bool variableLenArguments=false, const QList< HelpExample > &examples=QList< HelpExample >(), const QString &notes=QString::null)
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)
Help(const QString &name, const QString &type, const QString &description, const QList< HelpVariant > &variants)
static QHash< QString, QString > gVariableHelpTexts
bool isField() const
Checks whether an expression consists only of a single field reference.
double scale()
QList< HelpArg > mArguments
static QList< Function * > gmFunctions
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:40
HelpExample(const QString &expression, const QString &returns, const QString &note=QString::null)
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString name()
The name of the function.
WhenThen(Node *whenExp, Node *thenExp)
QList< HelpExample > mExamples
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.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:391
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.
HelpArg(const QString &arg, const QString &desc, bool descOnly=false, bool syntaxOnly=false)
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...
static QHash< QString, Help > gFunctionHelpTexts
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...
void append(Node *node)
Takes ownership of the provided node.
UnaryOperator op() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
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)
Q_NOWARN_DEPRECATED_POP Q_DECLARE_METATYPE(QgsExpression::Interval)
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.
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.
StaticFunction(const QString &fnname, int params, FcnEvalContext fcn, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QStringList &referencedColumns=QStringList(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext.
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