15 #ifndef QGSEXPRESSIONCONTEXT_H 
   16 #define QGSEXPRESSIONCONTEXT_H 
   18 #include "qgis_core.h" 
   23 #include <QStringList> 
   51                                  const QString &helpText = QString(),
 
   52                                  bool usesGeometry = 
false,
 
   53                                  const QSet<QString> &referencedColumns = QSet<QString>(),
 
   54                                  bool lazyEval = 
false,
 
   55                                  bool handlesNull = 
false,
 
   56                                  bool isContextual = 
true )
 
   58       , mUsesGeometry( usesGeometry )
 
   59       , mReferencedColumns( referencedColumns )
 
   70                                  const QString &helpText = QString(),
 
   71                                  bool usesGeometry = 
false,
 
   72                                  const QSet<QString> &referencedColumns = QSet<QString>(),
 
   73                                  bool lazyEval = 
false,
 
   74                                  bool handlesNull = 
false,
 
   75                                  bool isContextual = 
true )
 
   77       , mUsesGeometry( usesGeometry )
 
   78       , mReferencedColumns( referencedColumns )
 
   96     QSet<QString> mReferencedColumns;
 
  131       StaticVariable( 
const QString &name = QString(), 
const QVariant &value = QVariant(), 
bool readOnly = 
false, 
bool isStatic = 
false, 
const QString &description = QString() )
 
  134         , readOnly( readOnly )
 
  135         , isStatic( isStatic )
 
  136         , description( description )
 
  173     QString 
name()
 const { 
return mName; }
 
  182     void setVariable( 
const QString &name, 
const QVariant &value, 
bool isStatic = 
false );
 
  199     bool removeVariable( 
const QString &name );
 
  208     bool hasVariable( 
const QString &name ) 
const;
 
  217     QVariant variable( 
const QString &name ) 
const;
 
  224     QStringList variableNames() 
const;
 
  232     QStringList filteredVariableNames() 
const;
 
  240     bool isReadOnly( 
const QString &name ) 
const;
 
  248     bool isStatic( 
const QString &name ) 
const;
 
  256     QString description( 
const QString &name ) 
const;
 
  270     bool hasFunction( 
const QString &name ) 
const;
 
  287     QStringList functionNames() 
const;
 
  334     void setFields( 
const QgsFields &fields );
 
  348     bool writeXml( QDomElement &element, QDomDocument &document, 
const QgsReadWriteContext &context ) 
const;
 
  352     QHash<QString, StaticVariable> mVariables;
 
  353     QHash<QString, QgsScopedExpressionFunction * > mFunctions;
 
  354     bool mHasFeature = 
false;
 
  403     bool hasVariable( 
const QString &name ) 
const;
 
  414     QVariant variable( 
const QString &name ) 
const;
 
  421     QVariantMap variablesToMap() 
const;
 
  430     bool isHighlightedVariable( 
const QString &name ) 
const;
 
  438     QStringList highlightedVariables() 
const;
 
  447     void setHighlightedVariables( 
const QStringList &variableNames );
 
  457     bool isHighlightedFunction( 
const QString &name ) 
const;
 
  470     void setHighlightedFunctions( 
const QStringList &names );
 
  509     QList< QgsExpressionContextScope * > 
scopes() { 
return mStack; }
 
  524     int indexOfScope( 
const QString &scopeName ) 
const;
 
  534     QStringList variableNames() 
const;
 
  542     QStringList filteredVariableNames() 
const;
 
  550     bool isReadOnly( 
const QString &name ) 
const;
 
  560     QString description( 
const QString &name ) 
const;
 
  568     bool hasFunction( 
const QString &name ) 
const;
 
  575     QStringList functionNames() 
const;
 
  590     int scopeCount() 
const;
 
  607     void appendScopes( 
const QList<QgsExpressionContextScope *> &scopes 
SIP_TRANSFER );
 
  622     QList<QgsExpressionContextScope *> takeScopes() 
SIP_SKIP;
 
  645     bool hasFeature() const;
 
  660     void setFields( const 
QgsFields &fields );
 
  674     void setOriginalValueVariable( const QVariant &value );
 
  687     void setCachedValue( const QString &key, const QVariant &value ) const;
 
  697     bool hasCachedValue( const QString &key ) const;
 
  709     QVariant cachedValue( const QString &key ) const;
 
  718     void clearCachedValues() const;
 
  744     static const QString EXPR_FIELDS;
 
  746     static const QString EXPR_ORIGINAL_VALUE;
 
  748     static const QString EXPR_SYMBOL_COLOR;
 
  750     static const QString EXPR_SYMBOL_ANGLE;
 
  752     static const QString EXPR_GEOMETRY_PART_COUNT;
 
  754     static const QString EXPR_GEOMETRY_PART_NUM;
 
  760     static const QString EXPR_GEOMETRY_RING_NUM;
 
  762     static const QString EXPR_GEOMETRY_POINT_COUNT;
 
  764     static const QString EXPR_GEOMETRY_POINT_NUM;
 
  766     static const QString EXPR_CLUSTER_SIZE;
 
  768     static const QString EXPR_CLUSTER_COLOR;
 
  773     QStringList mHighlightedVariables;
 
  774     QStringList mHighlightedFunctions;
 
  779     mutable QMap< QString, QVariant > mCachedValues;
 
Single scope for storing variables and functions for use within a QgsExpressionContext.
void removeFeature()
Removes any feature associated with the scope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
QString name() const
Returns the friendly display name of the context scope.
int variableCount() const
Returns the count of variables contained within the scope.
QgsFeature feature() const
Sets the feature associated with the scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContext()=default
Constructor for QgsExpressionContext.
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
A abstract base class for defining QgsExpression functions.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
QString name() const
The name of the function.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
An expression node for expression functions.
Class for parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Container of fields for a vector layer.
The class is used as a container of context for various read/write operations on other objects.
Expression function for use within a QgsExpressionContextScope.
QgsScopedExpressionFunction(const QString &fnname, int params, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, bool handlesNull=false, bool isContextual=true)
Create a new QgsScopedExpressionFunction.
QgsScopedExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, bool handlesNull=false, bool isContextual=true)
Create a new QgsScopedExpressionFunction using named parameters.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override=0
Returns result of evaluating the function.
virtual QgsScopedExpressionFunction * clone() const =0
Returns a clone of the function.
Single variable definition for use within a QgsExpressionContextScope.
bool readOnly
True if variable should not be editable by users.
StaticVariable(const QString &name=QString(), const QVariant &value=QVariant(), bool readOnly=false, bool isStatic=false, const QString &description=QString())
Constructor for StaticVariable.
bool isStatic
A static variable can be cached for the lifetime of a context.
QString name
Variable name.
QVariant value
Variable value.
QString description
Translated description of variable, for use within expression builder widgets.