16#ifndef QGSEXPRESSION_H
17#define QGSEXPRESSION_H
24#include <QDomDocument>
25#include <QCoreApplication>
27#include <QRecursiveMutex>
45class QgsExpressionPrivate;
52 HelpArg(
const QString &arg,
const QString &desc,
bool descOnly =
false,
bool syntaxOnly =
false,
53 bool optional =
false,
const QString &defaultVal = QString() )
55 , mDescription( desc )
56 , mDescOnly( descOnly )
57 , mSyntaxOnly( syntaxOnly )
58 , mOptional( optional )
59 , mDefaultVal( defaultVal )
72 HelpExample(
const QString &expression,
const QString &returns,
const QString ¬e = QString() )
73 : mExpression( expression )
86 HelpVariant(
const QString &name,
const QString &description,
87 const QList<HelpArg> &arguments = QList<HelpArg>(),
88 bool variableLenArguments =
false,
89 const QList<HelpExample> &examples = QList<HelpExample>(),
90 const QString ¬es = QString(),
91 const QStringList &tags = QStringList() )
93 , mDescription( description )
94 , mArguments( arguments )
95 , mVariableLenArguments( variableLenArguments )
96 , mExamples( examples )
102 QString mDescription;
103 QList<HelpArg> mArguments;
104 bool mVariableLenArguments;
105 QList<HelpExample> mExamples;
115 Help(
const QString &name,
const QString &type,
const QString &description,
const QList<HelpVariant> &variants )
118 , mDescription( description )
119 , mVariants( variants )
124 QString mDescription;
125 QList<HelpVariant> mVariants;
128typedef QHash<QString, Help> HelpTextHash;
202 FunctionWrongArgs = 2,
203 FunctionInvalidParams = 3,
204 FunctionNamedArgsError = 4
288 bool isValid() const;
291 bool hasParserError() const;
293 QString parserErrorString() const;
330 QSet<QString> referencedColumns() const;
342 QSet<QString> referencedVariables() const;
353 QSet<QString> referencedFunctions() const;
363 QList<const QgsExpressionNode *> nodes( )
const;
374 QList<const T *> lst;
375 const QList<const QgsExpressionNode *> allNodes( nodes() );
376 for (
const auto &node : allNodes )
378 const T *n =
dynamic_cast<const T *
>( node );
398 QSet<int> referencedAttributeIndexes(
const QgsFields &fields )
const;
401 bool needsGeometry()
const;
419 bool hasEvalError()
const;
421 QString evalErrorString()
const;
423 void setEvalErrorString(
const QString &
str );
430 bool isField()
const;
444 static int expressionToLayerFieldIndex(
const QString &expression,
const QgsVectorLayer *layer );
458 static QString quoteFieldExpression(
const QString &expression,
const QgsVectorLayer *layer );
473 void setExpression(
const QString &expression );
480 QString expression()
const;
488 QString dump()
const;
560 static QString replaceExpressionText(
const QString &action,
const QgsExpressionContext *context,
570 static QSet<QString> referencedVariables(
const QString &text );
581 static double evaluateToDouble(
const QString &text,
double fallbackValue );
596 static const QList<QgsExpressionFunction *> &Functions();
598 static const QStringList &BuiltinFunctions();
614 static bool unregisterFunction(
const QString &name );
619 static void cleanRegisteredFunctions();
622 static bool isFunctionName(
const QString &name );
625 static int functionIndex(
const QString &name );
631 static int functionCount();
638 static QString quotedColumnRef( QString name );
645 static QString quotedString( QString text );
654 static QString quotedValue(
const QVariant &value );
664 static QString quotedValue(
const QVariant &value, QMetaType::Type type );
675 Q_DECL_DEPRECATED
static QString quotedValue(
const QVariant &value, QVariant::Type type )
SIP_DEPRECATED;
681 static HelpTextHash &functionHelpTexts();
691 static QString helpText( QString name );
698 static QStringList tags(
const QString &name );
712 static bool addVariableHelpText(
const QString name,
const QString &description );
720 static QString variableHelpText(
const QString &variableName );
730 static QString
formatVariableHelp(
const QString &description,
bool showValue =
true,
const QVariant &value = QVariant() );
736 static QString group(
const QString &group );
746 static QString formatPreviewString(
const QVariant &value,
bool htmlOutput =
true,
int maximumPreviewLength = 60 );
756 static QString createFieldEqualityExpression(
const QString &fieldName,
const QVariant &value, QMetaType::Type fieldType = QMetaType::Type::UnknownType );
767 Q_DECL_DEPRECATED
static QString createFieldEqualityExpression(
const QString &fieldName,
const QVariant &value, QVariant::Type fieldType )
SIP_DEPRECATED;
779 static bool isFieldEqualityExpression(
const QString &expression, QString &field
SIP_OUT, QVariant &value
SIP_OUT );
795 static bool attemptReduceToInClause(
const QStringList &expressions, QString &result
SIP_OUT );
798 SIP_PYOBJECT __repr__();
800 QString
str = QStringLiteral(
"<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
801 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
816 QgsExpressionPrivate *d =
nullptr;
818 static HelpTextHash sFunctionHelpTexts;
821 static
void initFunctionHelp()
SIP_SKIP;
823 static
void initVariableHelp()
SIP_SKIP;
826 static QRecursiveMutex sFunctionsMutex;
827 static QMap< QString,
int> sFunctionIndexMap;
DistanceUnit
Units of distance.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A abstract base class for defining QgsExpression functions.
An expression node for expression functions.
Abstract base class for all nodes that can appear in an expression.
Class for parsing and evaluation of expressions (formerly called "search strings").
QList< const T * > findNodes() const
Returns a list of all nodes of the given class which are used in this expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QString formatVariableHelp(const QString &variable, const QString &description, bool showValue, const QVariant &value)
Returns a HTML formatted string for use as a variable item help.
Details about any parser errors that were found when parsing the expression.
QString errorMsg
The message for the error at this location.