QGIS API Documentation  2.13.0-Master
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 
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 
118 class CORE_EXPORT QgsExpression
119 {
120  Q_DECLARE_TR_FUNCTIONS( QgsExpression )
121  public:
128  QgsExpression( const QString& expr );
129 
135  QgsExpression( const QgsExpression& other );
141  QgsExpression& operator=( const QgsExpression& other );
142  ~QgsExpression();
143 
145  bool hasParserError() const;
147  QString parserErrorString() const;
148 
149  class Node;
150 
152  const Node* rootNode() const;
153 
156  Q_DECL_DEPRECATED bool prepare( const QgsFields &fields );
157 
162  bool prepare( const QgsExpressionContext *context );
163 
172  QStringList referencedColumns() const;
173 
175  bool needsGeometry() const;
176 
177  // evaluation
178 
182  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f );
183 
188  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f );
189 
193  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature* f, const QgsFields& fields );
194 
199  Q_DECL_DEPRECATED QVariant evaluate( const QgsFeature& f, const QgsFields& fields );
200 
205  QVariant evaluate();
206 
212  QVariant evaluate( const QgsExpressionContext* context );
213 
215  bool hasEvalError() const;
217  QString evalErrorString() const;
219  void setEvalErrorString( const QString& str );
220 
223  Q_DECL_DEPRECATED void setCurrentRowNumber( int rowNumber );
226  Q_DECL_DEPRECATED int currentRowNumber(); //TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
227  //but should not be publicly used
231  Q_DECL_DEPRECATED static void setSpecialColumn( const QString& name, const QVariant& value );
235  Q_DECL_DEPRECATED static void unsetSpecialColumn( const QString& name );
239  Q_DECL_DEPRECATED static QVariant specialColumn( const QString& name );
240 
244  static bool hasSpecialColumn( const QString& name );
245 
249  bool isField() const { return rootNode() && dynamic_cast<const NodeColumnRef*>( rootNode() ) ;}
250 
252  Q_DECL_DEPRECATED static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
253 
261  static bool isValid( const QString& text, const QgsExpressionContext* context, QString &errorMessage );
262 
263  void setScale( double scale );
264 
265  double scale();
266 
270  QString expression() const;
271 
276  QString dump() const;
277 
280  QgsDistanceArea* geomCalculator();
281 
284  void setGeomCalculator( const QgsDistanceArea &calc );
285 
300  Q_DECL_DEPRECATED static QString replaceExpressionText( const QString &action, const QgsFeature *feat,
301  QgsVectorLayer *layer,
302  const QMap<QString, QVariant> *substitutionMap = nullptr,
303  const QgsDistanceArea* distanceArea = nullptr
304  );
305 
317  static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
318  const QMap<QString, QVariant> *substitutionMap = nullptr,
319  const QgsDistanceArea* distanceArea = nullptr
320  );
321 
331  static double evaluateToDouble( const QString& text, const double fallbackValue );
332 
338  {
341  };
342 
348  {
349  // logical
352 
353  // comparison
354  boEQ, // =
355  boNE, // <>
356  boLE, // <=
357  boGE, // >=
358  boLT, // <
359  boGT, // >
367 
368  // math
376 
377  // strings
379  };
380 
382  {
392  };
393 
395  static const char* BinaryOperatorText[];
396 
398  static const char* UnaryOperatorText[];
399 
400  typedef QVariant( *FcnEval )( const QVariantList& values, const QgsFeature* f, QgsExpression* parent );
401 
404  typedef QVariant( *FcnEvalContext )( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
405 
409  class CORE_EXPORT Function
410  {
411  public:
412  Function( const QString& fnname,
413  int params,
414  const QString& group,
415  const QString& helpText = QString(),
416  bool usesGeometry = false,
417  const QStringList& referencedColumns = QStringList(),
418  bool lazyEval = false,
419  bool handlesNull = false,
420  bool isContextual = false )
421  : mName( fnname )
422  , mParams( params )
423  , mUsesGeometry( usesGeometry )
424  , mGroup( group )
425  , mHelpText( helpText )
426  , mReferencedColumns( referencedColumns )
427  , mLazyEval( lazyEval )
428  , mHandlesNull( handlesNull )
429  , mIsContextual( isContextual )
430  {}
431 
432  virtual ~Function() {}
433 
435  QString name() { return mName; }
437  int params() { return mParams; }
439  bool usesgeometry() { return mUsesGeometry; }
440 
446  virtual QStringList aliases() const { return QStringList(); }
447 
451  bool lazyEval() { return mLazyEval; }
452 
453  virtual QStringList referencedColumns() const { return mReferencedColumns; }
454 
458  bool isContextual() const { return mIsContextual; }
459 
461  QString group() { return mGroup; }
463  const QString helptext() { return mHelpText.isEmpty() ? QgsExpression::helptext( mName ) : mHelpText; }
464 
466  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList&, const QgsFeature*, QgsExpression* );
467 
475  //TODO QGIS 3.0 - rename python method
476  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent );
477 
478  bool operator==( const Function& other ) const
479  {
480  if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
481  return true;
482 
483  return false;
484  }
485 
486  virtual bool handlesNull() const { return mHandlesNull; }
487 
488  private:
489  QString mName;
490  int mParams;
491  bool mUsesGeometry;
492  QString mGroup;
493  QString mHelpText;
494  QStringList mReferencedColumns;
495  bool mLazyEval;
496  bool mHandlesNull;
497  bool mIsContextual; //if true function is only available through an expression context
498  };
499 
504  class StaticFunction : public Function
505  {
506  public:
508  Q_DECL_DEPRECATED StaticFunction( const QString& fnname,
509  int params,
510  FcnEval fcn,
511  const QString& group,
512  const QString& helpText = QString(),
513  bool usesGeometry = false,
514  const QStringList& referencedColumns = QStringList(),
515  bool lazyEval = false,
516  const QStringList& aliases = QStringList(),
517  bool handlesNull = false )
518  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
519  , mFnc( fcn )
520  , mContextFnc( nullptr )
521  , mAliases( aliases )
522  {}
523 
524  virtual ~StaticFunction() {}
525 
528  StaticFunction( const QString& fnname,
529  int params,
530  FcnEvalContext fcn,
531  const QString& group,
532  const QString& helpText = QString(),
533  bool usesGeometry = false,
534  const QStringList& referencedColumns = QStringList(),
535  bool lazyEval = false,
536  const QStringList& aliases = QStringList(),
537  bool handlesNull = false )
538  : Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
539  , mFnc( nullptr )
540  , mContextFnc( fcn )
541  , mAliases( aliases )
542  {}
543 
545  Q_DECL_DEPRECATED virtual QVariant func( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) override;
546 
553  virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) override
554  {
555  return mContextFnc ? mContextFnc( values, context, parent ) : QVariant();
556  }
557 
558  virtual QStringList aliases() const override { return mAliases; }
559 
560  private:
561  FcnEval mFnc;
562  FcnEvalContext mContextFnc;
563  QStringList mAliases;
564  };
565 
568  static const QList<Function*>& Functions();
569 
572  static const QStringList& BuiltinFunctions();
573 
580  static bool registerFunction( Function* function, bool transferOwnership = false );
581 
586  static bool unregisterFunction( const QString& name );
587 
591 
595  static void cleanRegisteredFunctions();
596 
598  static bool isFunctionName( const QString& name );
599 
601  static int functionIndex( const QString& name );
602 
606  static int functionCount();
607 
611  static QList<Function*> specialColumns();
612 
617  static QString quotedColumnRef( QString name );
618 
623  static QString quotedString( QString text );
624 
632  static QString quotedValue( const QVariant& value );
633 
642  static QString quotedValue( const QVariant& value, QVariant::Type type );
643 
645 
646  class Visitor; // visitor interface is defined below
647 
648  enum NodeType
649  {
656  ntCondition
657  };
658 
659  class CORE_EXPORT Node
660  {
661  public:
662  virtual ~Node() {}
663 
669  virtual NodeType nodeType() const = 0;
670 
676  Q_DECL_DEPRECATED virtual QVariant eval( QgsExpression* parent, const QgsFeature* f );
677 
683  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
684 
690  Q_DECL_DEPRECATED virtual bool prepare( QgsExpression* parent, const QgsFields &fields );
691 
697  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
698 
704  virtual QString dump() const = 0;
705 
714  virtual Node* clone() const = 0;
715 
726  virtual QStringList referencedColumns() const = 0;
727 
736  virtual bool needsGeometry() const = 0;
737 
753  virtual void accept( Visitor& v ) const = 0;
754  };
755 
756  class CORE_EXPORT NodeList
757  {
758  public:
759  NodeList() {}
760  virtual ~NodeList() { qDeleteAll( mList ); }
762  void append( Node* node ) { mList.append( node ); }
763  int count() { return mList.count(); }
764  QList<Node*> list() { return mList; }
766  NodeList* clone() const;
767 
768  virtual QString dump() const;
769 
770  protected:
772  };
773 
774  class CORE_EXPORT Interval
775  {
776  // YEAR const value taken from postgres query
777  // SELECT EXTRACT(EPOCH FROM interval '1 year')
778  static const int YEARS = 31557600;
779  static const int MONTHS = 60 * 60 * 24 * 30;
780  static const int WEEKS = 60 * 60 * 24 * 7;
781  static const int DAY = 60 * 60 * 24;
782  static const int HOUR = 60 * 60;
783  static const int MINUTE = 60;
784  public:
785  Interval( double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
786 
788  double years() { return mSeconds / YEARS;}
790  double months() { return mSeconds / MONTHS; }
792  double weeks() { return mSeconds / WEEKS;}
794  double days() { return mSeconds / DAY;}
796  double hours() { return mSeconds / HOUR;}
798  double minutes() { return mSeconds / MINUTE;}
800  double seconds() { return mSeconds; }
802  bool isValid() { return mValid; }
804  void setValid( bool valid ) { mValid = valid; }
806  bool operator==( QgsExpression::Interval other ) const;
808  static QgsExpression::Interval invalidInterVal();
810  static QgsExpression::Interval fromString( const QString& string );
811 
812  private:
813  double mSeconds;
814  bool mValid;
815  };
816 
817  class CORE_EXPORT NodeUnaryOperator : public Node
818  {
819  public:
820  NodeUnaryOperator( UnaryOperator op, Node* operand ) : mOp( op ), mOperand( operand ) {}
821  ~NodeUnaryOperator() { delete mOperand; }
822 
823  UnaryOperator op() const { return mOp; }
824  Node* operand() const { return mOperand; }
825 
826  virtual NodeType nodeType() const override { return ntUnaryOperator; }
827  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
828  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
829  virtual QString dump() const override;
830 
831  virtual QStringList referencedColumns() const override { return mOperand->referencedColumns(); }
832  virtual bool needsGeometry() const override { return mOperand->needsGeometry(); }
833  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
834  virtual Node* clone() const override;
835 
836  protected:
839  };
840 
841  class CORE_EXPORT NodeBinaryOperator : public Node
842  {
843  public:
844  NodeBinaryOperator( BinaryOperator op, Node* opLeft, Node* opRight ) : mOp( op ), mOpLeft( opLeft ), mOpRight( opRight ) {}
845  ~NodeBinaryOperator() { delete mOpLeft; delete mOpRight; }
846 
847  BinaryOperator op() const { return mOp; }
848  Node* opLeft() const { return mOpLeft; }
849  Node* opRight() const { return mOpRight; }
850 
851  virtual NodeType nodeType() const override { return ntBinaryOperator; }
852  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
853  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
854  virtual QString dump() const override;
855 
856  virtual QStringList referencedColumns() const override { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
857  virtual bool needsGeometry() const override { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
858  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
859  virtual Node* clone() const override;
860 
861  int precedence() const;
862  bool leftAssociative() const;
863 
864  protected:
865  bool compare( double diff );
866  int computeInt( int x, int y );
867  double computeDouble( double x, double y );
868  QDateTime computeDateTimeFromInterval( const QDateTime& d, QgsExpression::Interval *i );
869 
873  };
874 
875  class CORE_EXPORT NodeInOperator : public Node
876  {
877  public:
878  NodeInOperator( Node* node, NodeList* list, bool notin = false ) : mNode( node ), mList( list ), mNotIn( notin ) {}
879  virtual ~NodeInOperator() { delete mNode; delete mList; }
880 
881  Node* node() const { return mNode; }
882  bool isNotIn() const { return mNotIn; }
883  NodeList* list() const { return mList; }
884 
885  virtual NodeType nodeType() const override { return ntInOperator; }
886  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
887  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
888  virtual QString dump() const override;
889 
890  virtual QStringList referencedColumns() const override { QStringList lst( mNode->referencedColumns() ); Q_FOREACH ( const Node* n, mList->list() ) lst.append( n->referencedColumns() ); return lst; }
891  virtual bool needsGeometry() const override { bool needs = false; Q_FOREACH ( Node* n, mList->list() ) needs |= n->needsGeometry(); return needs; }
892  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
893  virtual Node* clone() const override;
894 
895  protected:
898  bool mNotIn;
899  };
900 
901  class CORE_EXPORT NodeFunction : public Node
902  {
903  public:
904  NodeFunction( int fnIndex, NodeList* args ) : mFnIndex( fnIndex ), mArgs( args ) {}
905  //NodeFunction( QString name, NodeList* args ) : mName(name), mArgs(args) {}
906  virtual ~NodeFunction() { delete mArgs; }
907 
908  int fnIndex() const { return mFnIndex; }
909  NodeList* args() const { return mArgs; }
910 
911  virtual NodeType nodeType() const override { return ntFunction; }
912  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
913  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
914  virtual QString dump() const override;
915 
916  virtual QStringList referencedColumns() const override;
917  virtual bool needsGeometry() const override { bool needs = Functions()[mFnIndex]->usesgeometry(); if ( mArgs ) { Q_FOREACH ( Node* n, mArgs->list() ) needs |= n->needsGeometry(); } return needs; }
918  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
919  virtual Node* clone() const override;
920 
921  protected:
922  //QString mName;
923  int mFnIndex;
925 
926  private:
927 
928  QgsExpression::Function* getFunc() const;
929  };
930 
931  class CORE_EXPORT NodeLiteral : public Node
932  {
933  public:
934  NodeLiteral( const QVariant& value ) : mValue( value ) {}
935 
937  inline QVariant value() const { return mValue; }
938 
939  virtual NodeType nodeType() const override { return ntLiteral; }
940  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
941  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
942  virtual QString dump() const override;
943 
944  virtual QStringList referencedColumns() const override { return QStringList(); }
945  virtual bool needsGeometry() const override { return false; }
946  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
947  virtual Node* clone() const override;
948 
949  protected:
951  };
952 
953  class CORE_EXPORT NodeColumnRef : public Node
954  {
955  public:
956  NodeColumnRef( const QString& name ) : mName( name ), mIndex( -1 ) {}
957 
959  QString name() const { return mName; }
960 
961  virtual NodeType nodeType() const override { return ntColumnRef; }
962  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
963  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
964  virtual QString dump() const override;
965 
966  virtual QStringList referencedColumns() const override { return QStringList( mName ); }
967  virtual bool needsGeometry() const override { return false; }
968 
969  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
970  virtual Node* clone() const override;
971 
972  protected:
974  int mIndex;
975  };
976 
977  class CORE_EXPORT WhenThen
978  {
979  public:
980  WhenThen( Node* whenExp, Node* thenExp ) : mWhenExp( whenExp ), mThenExp( thenExp ) {}
981  ~WhenThen() { delete mWhenExp; delete mThenExp; }
982 
983  // protected:
986 
987  private:
988  WhenThen( const WhenThen& rh );
989  WhenThen& operator=( const WhenThen& rh );
990  };
992 
993  class CORE_EXPORT NodeCondition : public Node
994  {
995  public:
996  NodeCondition( WhenThenList* conditions, Node* elseExp = nullptr ) : mConditions( *conditions ), mElseExp( elseExp ) { delete conditions; }
997  NodeCondition( const WhenThenList& conditions, Node* elseExp = nullptr ) : mConditions( conditions ), mElseExp( elseExp ) {}
998  ~NodeCondition() { delete mElseExp; qDeleteAll( mConditions ); }
999 
1000  virtual NodeType nodeType() const override { return ntCondition; }
1001  virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context ) override;
1002  virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context ) override;
1003  virtual QString dump() const override;
1004 
1005  virtual QStringList referencedColumns() const override;
1006  virtual bool needsGeometry() const override;
1007  virtual void accept( Visitor& v ) const override { v.visit( *this ); }
1008  virtual Node* clone() const override;
1009 
1010  protected:
1011  WhenThenList mConditions;
1013  };
1014 
1016 
1019  class CORE_EXPORT Visitor
1020  {
1021  public:
1022  virtual ~Visitor() {}
1023  virtual void visit( const NodeUnaryOperator& n ) = 0;
1024  virtual void visit( const NodeBinaryOperator& n ) = 0;
1025  virtual void visit( const NodeInOperator& n ) = 0;
1026  virtual void visit( const NodeFunction& n ) = 0;
1027  virtual void visit( const NodeLiteral& n ) = 0;
1028  virtual void visit( const NodeColumnRef& n ) = 0;
1029  virtual void visit( const NodeCondition& n ) = 0;
1030  };
1031 
1033  void acceptVisitor( Visitor& v ) const;
1034 
1039  static QString helptext( QString name );
1040 
1048  static QString variableHelpText( const QString& variableName, bool showValue = true, const QVariant& value = QVariant() );
1049 
1053  static QString group( const QString& group );
1054 
1061  static QString formatPreviewString( const QVariant& value );
1062 
1063  protected:
1067  QgsExpression();
1068 
1069  void initGeomCalculator();
1070 
1073 
1074  struct HelpArg
1075  {
1076  HelpArg( const QString& arg, const QString& desc, bool descOnly = false, bool syntaxOnly = false )
1077  : mArg( arg )
1078  , mDescription( desc )
1079  , mDescOnly( descOnly )
1080  , mSyntaxOnly( syntaxOnly )
1081  {}
1082 
1087  };
1088 
1090  {
1091  HelpExample( const QString& expression, const QString& returns, const QString& note = QString::null )
1092  : mExpression( expression )
1093  , mReturns( returns )
1094  , mNote( note )
1095  {}
1096 
1100  };
1101 
1103  {
1104  HelpVariant( const QString& name, const QString& description,
1105  const QList<HelpArg>& arguments = QList<HelpArg>(),
1106  bool variableLenArguments = false,
1107  const QList<HelpExample>& examples = QList<HelpExample>(),
1108  const QString& notes = QString::null )
1109  : mName( name )
1110  , mDescription( description )
1111  , mArguments( arguments )
1112  , mVariableLenArguments( variableLenArguments )
1113  , mExamples( examples )
1114  , mNotes( notes )
1115  {}
1116 
1123  };
1124 
1125  struct Help
1126  {
1127  Help() {}
1128 
1129  Help( const QString& name, const QString& type, const QString& description, const QList<HelpVariant>& variants )
1130  : mName( name )
1131  , mType( type )
1132  , mDescription( description )
1133  , mVariants( variants )
1134  {}
1135 
1140  };
1141 
1148  void detach();
1149 
1150  QgsExpressionPrivate* d;
1151 
1155 
1157  static void initFunctionHelp();
1159  static void initVariableHelp();
1160 
1161  friend class QgsOgcUtils;
1162 };
1163 
1164 
1166 
1167 Q_DECLARE_METATYPE( QgsExpression::Interval )
1168 Q_DECLARE_METATYPE( QgsExpression::Node* )
1169 
1170 #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:189
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...
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)
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