16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
114 bool needsGeometry()
const;
151 static void unsetSpecialColumn(
const QString& name );
156 static bool hasSpecialColumn(
const QString& name );
172 if ( !mExp.isNull() )
215 static double evaluateToDouble(
const QString& text,
const double fallbackValue );
277 static const char* BinaryOperatorText[];
278 static const char* UnaryOperatorText[];
293 bool usesGeometry =
false,
295 bool lazyEval =
false,
296 bool handlesNull =
false )
299 , mUsesGeometry( usesGeometry )
301 , mHelpText( helpText )
302 , mReferencedColumns( referencedColumns )
303 , mLazyEval( lazyEval )
304 , mHandlesNull( handlesNull )
366 bool usesGeometry =
false,
368 bool lazyEval =
false,
370 bool handlesNull =
false )
371 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval, handlesNull )
373 , mAliases( aliases )
380 return mFnc( values, f, parent );
396 static bool registerFunction(
Function*
function );
397 static bool unregisterFunction(
QString name );
400 static bool isFunctionName(
QString name );
403 static int functionIndex(
const QString& name );
408 static int functionCount();
439 virtual NodeType nodeType()
const = 0;
448 virtual QString dump()
const = 0;
451 virtual bool needsGeometry()
const = 0;
454 virtual void accept(
Visitor& v )
const = 0;
464 int count() {
return mList.count(); }
477 static const int YEARS = 31557600;
478 static const int MONTHS = 60 * 60 * 24 * 30;
479 static const int WEEKS = 60 * 60 * 24 * 7;
480 static const int DAY = 60 * 60 * 24;
481 static const int HOUR = 60 * 60;
482 static const int MINUTE = 60;
484 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
486 double years() {
return mSeconds / YEARS;}
487 double months() {
return mSeconds / MONTHS; }
488 double weeks() {
return mSeconds / WEEKS;}
489 double days() {
return mSeconds / DAY;}
490 double hours() {
return mSeconds / HOUR;}
518 virtual bool needsGeometry()
const override {
return mOperand->needsGeometry(); }
542 virtual bool needsGeometry()
const override {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
545 int precedence()
const;
546 bool leftAssociative()
const;
549 bool compare(
double diff );
550 int computeInt(
int x,
int y );
551 double computeDouble(
double x,
double y );
701 void acceptVisitor( Visitor& v )
const;
710 QgsExpression() : mRootNode( 0 ), mRowNumber( 0 ), mScale( 0.0 ), mCalc( 0 ) {}
712 void initGeomCalculator();
731 static void initFunctionHelp();
742 #endif // QGSEXPRESSION_H
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual QStringList referencedColumns() const =0
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant evaluate(const QgsFeature &f, const QgsFields &fields)
Evaluate the feature and return the result.
UnaryOperator
list of unary operators
virtual bool needsGeometry() const override
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
virtual QStringList referencedColumns() const override
virtual bool handlesNull() const
virtual NodeType nodeType() const override
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
virtual QString dump() const =0
StaticFunction(QString fnname, int params, FcnEval fcn, QString group, QString helpText=QString(), bool usesGeometry=false, QStringList referencedColumns=QStringList(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
NodeCondition(WhenThenList *conditions, Node *elseExp=NULL)
NodeColumnRef(const QString &name)
static QString helptext(QString name)
QgsExpression()
Used by QgsOgcUtils to create an empty.
Function(const QString &fnname, int params, QString group, QString helpText=QString(), bool usesGeometry=false, QStringList referencedColumns=QStringList(), bool lazyEval=false, 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
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)=0
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual NodeType nodeType() const override
virtual QVariant func(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) override
int currentRowNumber()
Return the number used for $rownum special column.
virtual void accept(Visitor &v) const override
virtual bool needsGeometry() const override
NodeBinaryOperator(BinaryOperator op, Node *opLeft, Node *opRight)
QString mParserErrorString
virtual NodeType nodeType() const override
static const QList< Function * > & Functions()
static QHash< QString, QString > gFunctionHelpTexts
virtual QStringList referencedColumns() const override
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
static QHash< QString, QString > gGroups
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
NodeInOperator(Node *node, NodeList *list, bool notin=false)
bool isField() const
Checks whether an expression consists only of a single field reference.
static QList< Function * > gmFunctions
Encapsulate a field in an attribute table or data source.
virtual void accept(Visitor &v) const override
QString name()
The name of the function.
void setCurrentRowNumber(int rowNumber)
Set the number for $rownum special column.
WhenThen(Node *whenExp, Node *thenExp)
NodeUnaryOperator(UnaryOperator op, Node *operand)
BinaryOperator op() const
virtual void accept(Visitor &v) const override
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)=0
virtual NodeType nodeType() const override
virtual QStringList referencedColumns() const override
virtual QStringList referencedColumns() const
virtual void accept(Visitor &v) const override
void setEvalErrorString(QString str)
Set evaluation error (used internally by evaluation functions)
NodeFunction(int fnIndex, NodeList *args)
General purpose distance and area calculator.
static QMap< QString, QString > gmSpecialColumnGroups
virtual bool needsGeometry() const override
virtual void accept(Visitor &v) const override
virtual NodeType nodeType() const override
virtual bool needsGeometry() const override
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
QVariant evaluate(const QgsFeature &f)
Evaluate the feature and return the result.
int params()
The number of parameters this function takes.
NodeLiteral(const QVariant &value)
const QString helptext()
The help text for the function.
support for visitor pattern - algorithms dealing with the expressions may be implemented without modi...
virtual bool needsGeometry() const =0
bool operator==(const Function &other) const
static QStringList gmBuiltinFunctions
virtual bool needsGeometry() const override
void append(Node *node)
Takes ownership of the provided node.
virtual void accept(Visitor &v) const override
void setValid(bool valid)
virtual NodeType nodeType() const override
This is the base class for vector data providers.
void setScale(double scale)
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.
Q_DECLARE_METATYPE(QgsExpression::Interval)
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.
virtual ~NodeInOperator()
virtual bool needsGeometry() const override
virtual QStringList referencedColumns() const override
static QMap< QString, QVariant > gmSpecialColumns