16 #ifndef QGSEXPRESSION_H 17 #define QGSEXPRESSION_H 20 #include <QStringList> 23 #include <QDomDocument> 24 #include <QCoreApplication> 39 class QgsExpressionPrivate;
134 bool hasParserError()
const;
136 QString parserErrorString()
const;
141 const Node* rootNode()
const;
145 Q_DECL_DEPRECATED
bool prepare(
const QgsFields &fields );
164 bool needsGeometry()
const;
204 bool hasEvalError()
const;
206 QString evalErrorString()
const;
208 void setEvalErrorString(
const QString& str );
212 Q_DECL_DEPRECATED
void setCurrentRowNumber(
int rowNumber );
215 Q_DECL_DEPRECATED
int currentRowNumber();
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 );
233 static bool hasSpecialColumn(
const QString& name );
252 void setScale(
double scale );
358 static double evaluateToDouble(
const QString& text,
const double fallbackValue );
422 static const char* BinaryOperatorText[];
425 static const char* UnaryOperatorText[];
443 bool usesGeometry =
false,
445 bool lazyEval =
false,
446 bool handlesNull =
false,
447 bool isContextual =
false )
450 , mUsesGeometry( usesGeometry )
452 , mHelpText( helpText )
453 , mReferencedColumns( referencedColumns )
454 , mLazyEval( lazyEval )
455 , mHandlesNull( handlesNull )
456 , mIsContextual( isContextual )
540 bool usesGeometry =
false,
542 bool lazyEval =
false,
544 bool handlesNull =
false )
545 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
547 , mContextFnc( nullptr )
548 , mAliases( aliases )
560 bool usesGeometry =
false,
562 bool lazyEval =
false,
564 bool handlesNull =
false )
565 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
568 , mAliases( aliases )
582 return mContextFnc ? mContextFnc( values, context, parent ) :
QVariant();
589 FcnEvalContext mContextFnc;
607 static bool registerFunction(
Function*
function,
bool transferOwnership =
false );
613 static bool unregisterFunction(
const QString& name );
622 static void cleanRegisteredFunctions();
625 static bool isFunctionName(
const QString& name );
628 static int functionIndex(
const QString& name );
633 static int functionCount();
669 static QString quotedValue(
const QVariant& value, QVariant::Type type );
696 virtual NodeType nodeType()
const = 0;
731 virtual QString dump()
const = 0;
741 virtual Node* clone()
const = 0;
763 virtual bool needsGeometry()
const = 0;
780 virtual void accept(
Visitor& v )
const = 0;
790 int count() {
return mList.count(); }
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;
812 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
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;}
856 virtual QString dump()
const override;
859 virtual bool needsGeometry()
const override {
return mOperand->needsGeometry(); }
861 virtual Node* clone()
const override;
881 virtual QString dump()
const override;
884 virtual bool needsGeometry()
const override {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
886 virtual Node* clone()
const override;
888 int precedence()
const;
889 bool leftAssociative()
const;
892 bool compare(
double diff );
893 int computeInt(
int x,
int y );
894 double computeDouble(
double x,
double y );
915 virtual QString dump()
const override;
920 virtual Node* clone()
const override;
941 virtual QString dump()
const override;
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; }
946 virtual Node* clone()
const override;
968 virtual QString dump()
const override;
973 virtual Node* clone()
const override;
990 virtual QString dump()
const override;
996 virtual Node* clone()
const override;
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 ) {}
1029 virtual QString dump()
const override;
1031 virtual QStringList referencedColumns()
const override;
1032 virtual bool needsGeometry()
const override;
1034 virtual Node* clone()
const override;
1059 void acceptVisitor(
Visitor& v )
const;
1095 void initGeomCalculator();
1104 , mDescription( desc )
1105 , mDescOnly( descOnly )
1106 , mSyntaxOnly( syntaxOnly )
1118 : mExpression( expression )
1119 , mReturns( returns )
1132 bool variableLenArguments =
false,
1134 const QString& notes = QString::null )
1136 , mDescription( description )
1137 , mArguments( arguments )
1138 , mVariableLenArguments( variableLenArguments )
1139 , mExamples( examples )
1158 , mDescription( description )
1159 , mVariants( variants )
1176 QgsExpressionPrivate*
d;
1183 static void initFunctionHelp();
1185 static void initVariableHelp();
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
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.
virtual ~StaticFunction()
A geometry is the spatial representation of a feature.
Interval(double seconds=0)
virtual QStringList referencedColumns() const override
Abstract virtual method which returns a list of columns required to evaluate this node...
c++ helper class for defining QgsExpression functions.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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 ¬es=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)
virtual void accept(Visitor &v) const override
Support the visitor pattern.
QString name() const
The name of the column.
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...
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.
HelpExample(const QString &expression, const QString &returns, const QString ¬e=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
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.
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.
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 ...
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 ~NodeInOperator()
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...
static QMap< QString, QVariant > gmSpecialColumns
bool mVariableLenArguments