16#ifndef QGSEXPRESSION_H
17#define QGSEXPRESSION_H
24#include <QDomDocument>
25#include <QCoreApplication>
43class QgsExpressionPrivate;
50 HelpArg(
const QString &arg,
const QString &desc,
bool descOnly =
false,
bool syntaxOnly =
false,
51 bool optional =
false,
const QString &defaultVal = QString() )
53 , mDescription( desc )
54 , mDescOnly( descOnly )
55 , mSyntaxOnly( syntaxOnly )
56 , mOptional( optional )
57 , mDefaultVal( defaultVal )
70 HelpExample(
const QString &expression,
const QString &returns,
const QString ¬e = QString() )
71 : mExpression( expression )
84 HelpVariant(
const QString &name,
const QString &description,
85 const QList<HelpArg> &arguments = QList<HelpArg>(),
86 bool variableLenArguments =
false,
87 const QList<HelpExample> &examples = QList<HelpExample>(),
88 const QString ¬es = QString(),
89 const QStringList &tags = QStringList() )
91 , mDescription( description )
92 , mArguments( arguments )
93 , mVariableLenArguments( variableLenArguments )
94 , mExamples( examples )
100 QString mDescription;
101 QList<HelpArg> mArguments;
102 bool mVariableLenArguments;
103 QList<HelpExample> mExamples;
114 Help(
const QString &name,
const QString &type,
const QString &description,
const QList<HelpVariant> &variants )
117 , mDescription( description )
118 , mVariants( variants )
123 QString mDescription;
124 QList<HelpVariant> mVariants;
127typedef QHash<QString, Help> HelpTextHash;
202 FunctionWrongArgs = 2,
203 FunctionInvalidParams = 3,
204 FunctionNamedArgsError = 4
292 bool isValid() const;
295 bool hasParserError() const;
297 QString parserErrorString() const;
336 QSet<QString> referencedColumns() const;
349 QSet<QString> referencedVariables() const;
360 QSet<QString> referencedFunctions() const;
370 QList<const QgsExpressionNode *> nodes( )
const;
381 QList<const T *> lst;
382 const QList<const QgsExpressionNode *> allNodes( nodes() );
383 for (
const auto &node : allNodes )
385 const T *n =
dynamic_cast<const T *
>( node );
406 QSet<int> referencedAttributeIndexes(
const QgsFields &fields )
const;
409 bool needsGeometry()
const;
429 bool hasEvalError()
const;
431 QString evalErrorString()
const;
433 void setEvalErrorString(
const QString &
str );
441 bool isField()
const;
455 static int expressionToLayerFieldIndex(
const QString &expression,
const QgsVectorLayer *layer );
469 static QString quoteFieldExpression(
const QString &expression,
const QgsVectorLayer *layer );
486 void setExpression(
const QString &expression );
493 QString expression()
const;
501 QString dump()
const;
578 static QString replaceExpressionText(
const QString &action,
const QgsExpressionContext *context,
588 static QSet<QString> referencedVariables(
const QString &text );
600 static double evaluateToDouble(
const QString &text,
double fallbackValue );
615 static const QList<QgsExpressionFunction *> &Functions();
617 static const QStringList &BuiltinFunctions();
633 static bool unregisterFunction(
const QString &name );
639 static void cleanRegisteredFunctions();
642 static bool isFunctionName(
const QString &name );
645 static int functionIndex(
const QString &name );
651 static int functionCount();
658 static QString quotedColumnRef( QString name );
665 static QString quotedString( QString text );
675 static QString quotedValue(
const QVariant &value );
686 static QString quotedValue(
const QVariant &value, QVariant::Type type );
692 static HelpTextHash &functionHelpTexts();
702 static QString helpText( QString name );
709 static QStringList tags(
const QString &name );
723 static bool addVariableHelpText(
const QString name,
const QString &description );
732 static QString variableHelpText(
const QString &variableName );
743 static QString
formatVariableHelp(
const QString &description,
bool showValue =
true,
const QVariant &value = QVariant() );
749 static QString group(
const QString &group );
760 static QString formatPreviewString(
const QVariant &value,
bool htmlOutput =
true,
int maximumPreviewLength = 60 );
771 static QString createFieldEqualityExpression(
const QString &fieldName,
const QVariant &value, QVariant::Type fieldType = QVariant::Type::Invalid );
783 static bool isFieldEqualityExpression(
const QString &expression, QString &
field SIP_OUT, QVariant &value
SIP_OUT );
799 static bool attemptReduceToInClause(
const QStringList &expressions, QString &result
SIP_OUT );
802 SIP_PYOBJECT __repr__();
804 QString
str = QStringLiteral(
"<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
805 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
820 QgsExpressionPrivate *d =
nullptr;
822 static HelpTextHash sFunctionHelpTexts;
825 static
void initFunctionHelp()
SIP_SKIP;
827 static
void initVariableHelp()
SIP_SKIP;
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.
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.