QGIS API Documentation  2.14.0-Essen
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 #include "qgsunittypes.h"
28 
29 class QgsFeature;
30 class QgsGeometry;
31 class QgsOgcUtils;
32 class QgsVectorLayer;
34 class QgsField;
35 class QgsFields;
36 class QgsDistanceArea;
37 class QDomElement;
39 class QgsExpressionPrivate;
40 
107 class CORE_EXPORT QgsExpression
108 {
109  Q_DECLARE_TR_FUNCTIONS( QgsExpression )
110  public:
117  QgsExpression( const QString& expr );
118 
124  QgsExpression( const QgsExpression& other );
130  QgsExpression& operator=( const QgsExpression& other );
131  ~QgsExpression();
132 
134  bool hasParserError() const;
136  QString parserErrorString() const;
137 
138  class Node;
139 
141  const Node* rootNode() const;
142 
145  Q_DECL_DEPRECATED bool prepare( const QgsFields &fields );
146 
151  bool prepare( const QgsExpressionContext *context );
152 
161  QStringList referencedColumns() const;
162 
164  bool needsGeometry() const;
165 
166  // evaluation
167 
171  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f );
172 
177  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f );
178 
182  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f, const QgsFields& fields );
183 
188  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f, const QgsFields& fields );
189 
194  QVariant evaluate();
195 
201  QVariant evaluate( const QgsExpressionContext* context );
202 
204  bool hasEvalError() const;
206  QString evalErrorString() const;
208  void setEvalErrorString( const QString& str );
209 
212  Q_DECL_DEPRECATED void setCurrentRowNumber( int rowNumber );
215  Q_DECL_DEPRECATED int currentRowNumber(); //TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
216  //but should not be publicly used
220  Q_DECL_DEPRECATED static void setSpecialColumn( const QString& name, const QVariant& value );
224  Q_DECL_DEPRECATED static void unsetSpecialColumn( const QString& name );
228  Q_DECL_DEPRECATED static QVariant specialColumn( const QString& name );
229 
233  static bool hasSpecialColumn( const QString& name );
234 
238  bool isField() const { return rootNode() && dynamic_cast<const NodeColumnRef*>( rootNode() ) ;}
239 
241  Q_DECL_DEPRECATED static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
242 
250  static bool isValid( const QString& text, const QgsExpressionContext* context, QString &errorMessage );
251 
252  void setScale( double scale );
253 
254  double scale();
255 
259  QString expression() const;
260 
265  QString dump() const;
266 
273  QgsDistanceArea *geomCalculator();
274 
281  //TODO QGIS 3.0 change calc to a pointer, so that calculator can be cleared by passing nullptr
282  void setGeomCalculator( const QgsDistanceArea &calc );
283 
290  QGis::UnitType distanceUnits() const;
291 
298  void setDistanceUnits( QGis::UnitType unit );
299 
306  QgsUnitTypes::AreaUnit areaUnits() const;
307 
314  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
315 
329  Q_DECL_DEPRECATED static QString replaceExpressionText( const QString &action, const QgsFeature *feat,
330  QgsVectorLayer *layer,
331  const QMap<QString, QVariant> *substitutionMap = nullptr,
332  const QgsDistanceArea* distanceArea = nullptr );
333 
345  static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
346  const QMap<QString, QVariant> *substitutionMap = nullptr,
347  const QgsDistanceArea* distanceArea = nullptr );
348 
358  static double evaluateToDouble( const QString& text, const double fallbackValue );
359 
365  {
368  };
369 
375  {
376  // logical
379 
380  // comparison
381  boEQ, // =
382  boNE, // <>
383  boLE, // <=
384  boGE, // >=
385  boLT, // <
386  boGT, // >
394 
395  // math
403 
404  // strings
406  };
407 
409  {
419  };
420 
422  static const char* BinaryOperatorText[];
423 
425  static const char* UnaryOperatorText[];
426 
427  typedef QVariant( *FcnEval )( const QVariantList& values, const QgsFeature* f, QgsExpression* parent );
428 
431  typedef QVariant( *FcnEvalContext )( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
432 
436  class CORE_EXPORT Function
437  {
438  public:
439  Function( const QString& fnname,
440  int params,
441  const QString& group,
442  const QString& helpText = QString(),
443  bool usesGeometry = false,
444  const QStringList& referencedColumns = QStringList(),
445  bool lazyEval = false,
446  bool handlesNull = false,
447  bool isContextual = false )
448  : mName( fnname )
449  , mParams( params )
450  , mUsesGeometry( usesGeometry )
451  , mGroup( group )
452  , mHelpText( helpText )
453  , mReferencedColumns( referencedColumns )
454  , mLazyEval( lazyEval )
455  , mHandlesNull( handlesNull )
456  , mIsContextual( isContextual )
457  {}
458 
459  virtual ~Function() {}
460 
462  QString name() { return mName; }
464  int params() { return mParams; }
466  bool usesgeometry() { return mUsesGeometry; }
467 
473  virtual QStringList aliases() const { return QStringList(); }
474 
478  bool lazyEval() { return mLazyEval; }
479 
480  virtual QStringList referencedColumns() const { return mReferencedColumns; }
481 
485  bool isContextual() const { return mIsContextual; }
486 
488  QString group() { return mGroup; }
490  const QString helptext() { return mHelpText.isEmpty() ? QgsExpression::helptext( mName ) : mHelpText; }
491 
493  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList&, const QgsFeature*, QgsExpression* );
494 
502  //TODO QGIS 3.0 - rename python method
503  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
504 
505  bool operator==( const Function& other ) const
506  {
507  if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
508  return true;
509 
510  return false;
511  }
512 
513  virtual bool handlesNull() const { return mHandlesNull; }
514 
515  private:
516  QString mName;
517  int mParams;
518  bool mUsesGeometry;
519  QString mGroup;
520  QString mHelpText;
521  QStringList mReferencedColumns;
522  bool mLazyEval;
523  bool mHandlesNull;
524  bool mIsContextual; //if true function is only available through an expression context
525  };
526 
531  class StaticFunction : public Function
532  {
533  public:
535  Q_DECL_DEPRECATED StaticFunction( const QString& fnname,
536  int params,
537  FcnEval fcn,
538  const QString& group,
539  const QString& helpText = QString(),
540  bool usesGeometry = false,
541  const QStringList& referencedColumns = QStringList(),
542  bool lazyEval = false,
543  const QStringList& aliases = QStringList(),
544  bool handlesNull = false )
545  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
546  , mFnc( fcn )
547  , mContextFnc( nullptr )
548  , mAliases( aliases )
549  {}
550 
551  virtual ~StaticFunction() {}
552 
555  StaticFunction( const QString& fnname,
556  int params,
557  FcnEvalContext fcn,
558  const QString& group,
559  const QString& helpText = QString(),
560  bool usesGeometry = false,
561  const QStringList& referencedColumns = QStringList(),
562  bool lazyEval = false,
563  const QStringList& aliases = QStringList(),
564  bool handlesNull = false )
565  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
566  , mFnc( nullptr )
567  , mContextFnc( fcn )
568  , mAliases( aliases )
569  {}
570 
572  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) override;
573 
580  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) override
581  {
582  return mContextFnc ? mContextFnc( values, context, parent ) : QVariant();
583  }
584 
585  virtual QStringList aliases() const override { return mAliases; }
586 
587  private:
588  FcnEval mFnc;
589  FcnEvalContext mContextFnc;
590  QStringList mAliases;
591  };
592 
595  static const QList<Function*>& Functions();
596 
599  static const QStringList& BuiltinFunctions();
600 
607  static bool registerFunction( Function* function, bool transferOwnership = false );
608 
613  static bool unregisterFunction( const QString& name );
614 
618 
622  static void cleanRegisteredFunctions();
623 
625  static bool isFunctionName( const QString& name );
626 
628  static int functionIndex( const QString& name );
629 
633  static int functionCount();
634 
638  static QList<Function*> specialColumns();
639 
644  static QString quotedColumnRef( QString name );
645 
650  static QString quotedString( QString text );
651 
659  static QString quotedValue( const QVariant& value );
660 
669  static QString quotedValue( const QVariant& value, QVariant::Type type );
670 
672 
673  class Visitor; // visitor interface is defined below
674 
675  enum NodeType
676  {
683  ntCondition
684  };
685 
686  class CORE_EXPORT Node
687  {
688  public:
689  virtual ~Node() {}
690 
696  virtual NodeType nodeType() const = 0;
697 
703  Q_DECL_DEPRECATED virtual QVariant eval( QgsExpression* parent, const QgsFeature* f );
704 
710  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
711 
717  Q_DECL_DEPRECATED virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
718 
724  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
725 
731  virtual QString dump() const = 0;
732 
741  virtual Node* clone() const = 0;
742 
753  virtual QStringList referencedColumns() const = 0;
754 
763  virtual bool needsGeometry() const = 0;
764 
780  virtual void accept( Visitor& v ) const = 0;
781  };
782 
783  class CORE_EXPORT NodeList
784  {
785  public:
786  NodeList() {}
787  virtual ~NodeList() { qDeleteAll( mList ); }
789  void append( Node* node ) { mList.append( node ); }
790  int count() { return mList.count(); }
791  QList<Node*> list() { return mList; }
793  NodeList* clone() const;
794 
795  virtual QString dump() const;
796 
797  protected:
799  };
800 
801  class CORE_EXPORT Interval
802  {
803  // YEAR const value taken from postgres query
804  // SELECT EXTRACT(EPOCH FROM interval '1 year')
805  static const int YEARS = 31557600;
806  static const int MONTHS = 60 * 60 * 24 * 30;
807  static const int WEEKS = 60 * 60 * 24 * 7;
808  static const int DAY = 60 * 60 * 24;
809  static const int HOUR = 60 * 60;
810  static const int MINUTE = 60;
811  public:
812  Interval( double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
813 
815  double years() { return mSeconds / YEARS;}
817  double months() { return mSeconds / MONTHS; }
819  double weeks() { return mSeconds / WEEKS;}
821  double days() { return mSeconds / DAY;}
823  double hours() { return mSeconds / HOUR;}
825  double minutes() { return mSeconds / MINUTE;}
827  double seconds() { return mSeconds; }
829  bool isValid() { return mValid; }
831  void setValid( bool valid ) { mValid = valid; }
833  bool operator==( QgsExpression::Interval other ) const;
835  static QgsExpression::Interval invalidInterVal();
837  static QgsExpression::Interval fromString( const QString& string );
838 
839  private:
840  double mSeconds;
841  bool mValid;
842  };
843 
844  class CORE_EXPORT NodeUnaryOperator : public Node
845  {
846  public:
847  NodeUnaryOperator( UnaryOperator op, Node* operand ) : mOp( op ), mOperand( operand ) {}
848  ~NodeUnaryOperator() { delete mOperand; }
849 
850  UnaryOperator op() const { return mOp; }
851  Node* operand() const { return mOperand; }
852 
853  virtual NodeType nodeType() const override { return ntUnaryOperator; }
854  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
855  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
856  virtual QString dump() const override;
857 
858  virtual QStringList referencedColumns() const override { return mOperand->referencedColumns(); }
859  virtual bool needsGeometry() const override { return mOperand->needsGeometry(); }
860  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
861  virtual Node* clone() const override;
862 
863  protected:
866  };
867 
868  class CORE_EXPORT NodeBinaryOperator : public Node
869  {
870  public:
871  NodeBinaryOperator( BinaryOperator op, Node* opLeft, Node* opRight ) : mOp( op ), mOpLeft( opLeft ), mOpRight( opRight ) {}
872  ~NodeBinaryOperator() { delete mOpLeft; delete mOpRight; }
873 
874  BinaryOperator op() const { return mOp; }
875  Node* opLeft() const { return mOpLeft; }
876  Node* opRight() const { return mOpRight; }
877 
878  virtual NodeType nodeType() const override { return ntBinaryOperator; }
879  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
880  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
881  virtual QString dump() const override;
882 
883  virtual QStringList referencedColumns() const override { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
884  virtual bool needsGeometry() const override { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
885  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
886  virtual Node* clone() const override;
887 
888  int precedence() const;
889  bool leftAssociative() const;
890 
891  protected:
892  bool compare( double diff );
893  int computeInt( int x, int y );
894  double computeDouble( double x, double y );
895  QDateTime computeDateTimeFromInterval( const QDateTime& d, QgsExpression::Interval *i );
896 
900  };
901 
902  class CORE_EXPORT NodeInOperator : public Node
903  {
904  public:
905  NodeInOperator( Node* node, NodeList* list, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
906  virtual ~NodeInOperator() { delete mNode; delete mList; }
907 
908  Node* node() const { return mNode; }
909  bool isNotIn() const { return mNotIn; }
910  NodeList* list() const { return mList; }
911 
912  virtual NodeType nodeType() const override { return ntInOperator; }
913  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
914  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
915  virtual QString dump() const override;
916 
917  virtual QStringList referencedColumns() const override { QStringList lst( mNode->referencedColumns() ); Q_FOREACH ( const Node* n, mList->list() ) lst.append( n->referencedColumns() ); return lst; }
918  virtual bool needsGeometry() const override { bool needs = false; Q_FOREACH ( Node* n, mList->list() ) needs |= n->needsGeometry(); return needs; }
919  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
920  virtual Node* clone() const override;
921 
922  protected:
925  bool mNotIn;
926  };
927 
928  class CORE_EXPORT NodeFunction : public Node
929  {
930  public:
931  NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex ), mArgs( args ) {}
932  //NodeFunction( QString name, NodeList* args ) : mName(name), mArgs(args) {}
933  virtual ~NodeFunction() { delete mArgs; }
934 
935  int fnIndex() const { return mFnIndex; }
936  NodeList* args() const { return mArgs; }
937 
938  virtual NodeType nodeType() const override { return ntFunction; }
939  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
940  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
941  virtual QString dump() const override;
942 
943  virtual QStringList referencedColumns() const override;
944  virtual bool needsGeometry() const override { bool needs = Functions()[mFnIndex]->usesgeometry(); if ( mArgs ) { Q_FOREACH ( Node* n, mArgs->list() ) needs |= n->needsGeometry(); } return needs; }
945  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
946  virtual Node* clone() const override;
947 
948  protected:
949  int mFnIndex;
951 
952  private:
953 
954  QgsExpression::Function* getFunc() const;
955  };
956 
957  class CORE_EXPORT NodeLiteral : public Node
958  {
959  public:
960  NodeLiteral( const QVariant& value ) : mValue( value ) {}
961 
963  inline QVariant value() const { return mValue; }
964 
965  virtual NodeType nodeType() const override { return ntLiteral; }
966  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
967  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
968  virtual QString dump() const override;
969 
970  virtual QStringList referencedColumns() const override { return QStringList(); }
971  virtual bool needsGeometry() const override { return false; }
972  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
973  virtual Node* clone() const override;
974 
975  protected:
977  };
978 
979  class CORE_EXPORT NodeColumnRef : public Node
980  {
981  public:
982  NodeColumnRef( const QString& name ) : mName( name ), mIndex( -1 ) {}
983 
985  QString name() const { return mName; }
986 
987  virtual NodeType nodeType() const override { return ntColumnRef; }
988  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
989  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
990  virtual QString dump() const override;
991 
992  virtual QStringList referencedColumns() const override { return QStringList( mName ); }
993  virtual bool needsGeometry() const override { return false; }
994 
995  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
996  virtual Node* clone() const override;
997 
998  protected:
1000  int mIndex;
1001  };
1002 
1003  class CORE_EXPORT WhenThen
1004  {
1005  public:
1006  WhenThen( Node* whenExp, Node* thenExp ) : mWhenExp( whenExp ), mThenExp( thenExp ) {}
1007  ~WhenThen() { delete mWhenExp; delete mThenExp; }
1008 
1009  // protected:
1012 
1013  private:
1014  WhenThen( const WhenThen& rh );
1015  WhenThen& operator=( const WhenThen& rh );
1016  };
1018 
1019  class CORE_EXPORT NodeCondition : public Node
1020  {
1021  public:
1022  NodeCondition( WhenThenList* conditions, Node* elseExp = nullptr ) : mConditions( *conditions ), mElseExp( elseExp ) { delete conditions; }
1023  NodeCondition( const WhenThenList& conditions, Node* elseExp = nullptr ) : mConditions( conditions ), mElseExp( elseExp ) {}
1024  ~NodeCondition() { delete mElseExp; qDeleteAll( mConditions ); }
1025 
1026  virtual NodeType nodeType() const override { return ntCondition; }
1027  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
1028  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
1029  virtual QString dump() const override;
1030 
1031  virtual QStringList referencedColumns() const override;
1032  virtual bool needsGeometry() const override;
1033  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
1034  virtual Node* clone() const override;
1035 
1036  protected:
1037  WhenThenList mConditions;
1039  };
1040 
1042 
1045  class CORE_EXPORT Visitor
1046  {
1047  public:
1048  virtual ~Visitor() {}
1049  virtual void visit( const NodeUnaryOperator& n ) = 0;
1050  virtual void visit( const NodeBinaryOperator& n ) = 0;
1051  virtual void visit( const NodeInOperator& n ) = 0;
1052  virtual void visit( const NodeFunction& n ) = 0;
1053  virtual void visit( const NodeLiteral& n ) = 0;
1054  virtual void visit( const NodeColumnRef& n ) = 0;
1055  virtual void visit( const NodeCondition& n ) = 0;
1056  };
1057 
1059  void acceptVisitor( Visitor& v ) const;
1060 
1065  static QString helptext( QString name );
1066 
1074  static QString variableHelpText( const QString& variableName, bool showValue = true, const QVariant& value = QVariant() );
1075 
1079  static QString group( const QString& group );
1080 
1087  static QString formatPreviewString( const QVariant& value );
1088 
1089  protected:
1093  QgsExpression();
1094 
1095  void initGeomCalculator();
1096 
1099 
1100  struct HelpArg
1101  {
1102  HelpArg( const QString& arg, const QString& desc, bool descOnly = false, bool syntaxOnly = false )
1103  : mArg( arg )
1104  , mDescription( desc )
1105  , mDescOnly( descOnly )
1106  , mSyntaxOnly( syntaxOnly )
1107  {}
1108 
1113  };
1114 
1116  {
1117  HelpExample( const QString& expression, const QString& returns, const QString& note = QString::null )
1118  : mExpression( expression )
1119  , mReturns( returns )
1120  , mNote( note )
1121  {}
1122 
1126  };
1127 
1129  {
1130  HelpVariant( const QString& name, const QString& description,
1131  const QList<HelpArg>& arguments = QList<HelpArg>(),
1132  bool variableLenArguments = false,
1133  const QList<HelpExample>& examples = QList<HelpExample>(),
1134  const QString& notes = QString::null )
1135  : mName( name )
1136  , mDescription( description )
1137  , mArguments( arguments )
1138  , mVariableLenArguments( variableLenArguments )
1139  , mExamples( examples )
1140  , mNotes( notes )
1141  {}
1142 
1149  };
1150 
1151  struct Help
1152  {
1153  Help() {}
1154 
1155  Help( const QString& name, const QString& type, const QString& description, const QList<HelpVariant>& variants )
1156  : mName( name )
1157  , mType( type )
1158  , mDescription( description )
1159  , mVariants( variants )
1160  {}
1161 
1166  };
1167 
1174  void detach();
1175 
1176  QgsExpressionPrivate* d;
1177 
1181 
1183  static void initFunctionHelp();
1185  static void initVariableHelp();
1186 
1187  friend class QgsOgcUtils;
1188 };
1189 
1190 
1192 
1193 Q_DECLARE_METATYPE( QgsExpression::Interval )
1194 Q_DECLARE_METATYPE( QgsExpression::Node* )
1195 
1196 #endif // QGSEXPRESSION_H
Class for parsing and evaluation of expressions (formerly called "search strings").
double years()
interval length in years
virtual QStringList referencedColumns() const =0
Abstract virtual method which returns a list of columns required to evaluate this node...
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 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)
double months()
interval length in months
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
bool lazyEval()
True if this function should use lazy evaluation.
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.
NodeColumnRef(const QString &name)
static QString helptext(QString name)
Returns the help text for a specified function.
double weeks()
interval length in weeks
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:407
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:187
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
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
c++ helper class for defining QgsExpression functions.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QList< HelpVariant > mVariants
QVariant value() const
The value of the literal.
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.
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
NodeBinaryOperator(BinaryOperator op, Node *opLeft, Node *opRight)
virtual NodeType nodeType() const override
Abstract virtual that returns the type of this node.
NodeCondition(WhenThenList *conditions, Node *elseExp=nullptr)
bool isValid()
getter interval validity
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)
QgsExpressionPrivate * d
NodeList * args() const
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString name() const
The name of the column.
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...
bool isEmpty() const
double minutes()
interval length in minutus
virtual QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent) override
Returns result of evaluating the function.
double hours()
interval length in hours
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.
QList< HelpArg > mArguments
static QList< Function * > gmFunctions
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
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.
double days()
interval length in days
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:408
NodeFunction(int fnIndex, NodeList *args)
General purpose distance and area calculator.
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
double seconds()
interval length in seconds
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...
UnitType
Map units that qgis supports.
Definition: qgis.h:155
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)
setter interval validity
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.
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.
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
Definition: qgsogcutils.h:42
NodeCondition(const WhenThenList &conditions, Node *elseExp=nullptr)
AreaUnit
Units of area.
Definition: qgsunittypes.h:49
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