16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
24 #include <QCoreApplication>
110 Q_DECL_DEPRECATED
bool prepare(
const QgsFields &fields );
127 bool needsGeometry()
const;
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 );
192 static bool hasSpecialColumn(
const QString& name );
217 if ( !mExp.isNull() )
278 static double evaluateToDouble(
const QString& text,
const double fallbackValue );
340 static const char* BinaryOperatorText[];
341 static const char* UnaryOperatorText[];
359 bool usesGeometry =
false,
361 bool lazyEval =
false,
362 bool handlesNull =
false,
363 bool isContextual =
false )
366 , mUsesGeometry( usesGeometry )
368 , mHelpText( helpText )
369 , mReferencedColumns( referencedColumns )
370 , mLazyEval( lazyEval )
371 , mHandlesNull( handlesNull )
372 , mIsContextual( isContextual )
450 bool usesGeometry =
false,
452 bool lazyEval =
false,
454 bool handlesNull =
false )
455 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
458 , mAliases( aliases )
470 bool usesGeometry =
false,
472 bool lazyEval =
false,
474 bool handlesNull =
false )
475 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
478 , mAliases( aliases )
491 return mContextFnc ? mContextFnc( values, context, parent ) :
QVariant();
498 FcnEvalContext mContextFnc;
514 static bool registerFunction(
Function*
function,
bool transferOwnership =
false );
520 static bool unregisterFunction(
const QString& name );
528 static void cleanRegisteredFunctions();
531 static bool isFunctionName(
const QString& name );
534 static int functionIndex(
const QString& name );
539 static int functionCount();
576 virtual NodeType nodeType()
const = 0;
609 virtual QString dump()
const = 0;
631 virtual bool needsGeometry()
const = 0;
648 virtual void accept(
Visitor& v )
const = 0;
658 int count() {
return mList.count(); }
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;
678 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
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;}
712 virtual bool needsGeometry()
const override {
return mOperand->needsGeometry(); }
736 virtual bool needsGeometry()
const override {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
739 int precedence()
const;
740 bool leftAssociative()
const;
743 bool compare(
double diff );
744 int computeInt(
int x,
int y );
745 double computeDouble(
double x,
double y );
864 NodeCondition( WhenThenList* conditions,
Node* elseExp = NULL ) : mConditions( *conditions ), mElseExp( elseExp ) {
delete conditions; }
899 void acceptVisitor( Visitor& v )
const;
925 QgsExpression() : mRootNode( 0 ), mRowNumber( 0 ), mScale( 0.0 ), mCalc( 0 ) {}
927 void initGeomCalculator();
947 , mDescription( desc )
948 , mDescOnly( descOnly )
949 , mSyntaxOnly( syntaxOnly )
961 : mExpression( expression )
962 , mReturns( returns )
975 bool variableLenArguments =
false,
977 const QString& notes = QString::null )
979 , mDescription( description )
980 , mArguments( arguments )
981 , mVariableLenArguments( variableLenArguments )
982 , mExamples( examples )
1001 , mDescription( description )
1002 , mVariants( variants )
1015 static void initFunctionHelp();
1016 static void initVariableHelp();
1028 #endif // QGSEXPRESSION_H
Class for parsing and evaluation of expressions (formerly called "search strings").
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.
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
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.
virtual ~StaticFunction()
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.
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...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QList< HelpVariant > mVariants
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...
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 ¬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)
QgsDistanceArea * geomCalculator()
Return calculator used for distance and area calculations (used by internal functions) ...
virtual void accept(Visitor &v) const override
Support the visitor pattern.
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.
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.
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.
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.
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.
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 ...
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 ~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