16 #ifndef QGSEXPRESSION_H 17 #define QGSEXPRESSION_H 19 #include "qgis_core.h" 21 #include <QStringList> 24 #include <QDomDocument> 25 #include <QCoreApplication> 44 class QgsExpressionPrivate;
128 FunctionWrongArgs = 2,
129 FunctionInvalidParams = 3,
130 FunctionNamedArgsError = 4
218 bool isValid() const;
221 bool hasParserError() const;
223 QString parserErrorString() const;
254 QSet<QString> referencedColumns() const;
263 QSet<QString> referencedVariables() const;
270 QSet<QString> referencedFunctions() const;
280 QList<const QgsExpressionNode *> nodes( )
const;
291 QList<const T *> lst;
292 const QList<const QgsExpressionNode *> allNodes( nodes() );
293 for (
const auto &node : allNodes )
295 const T *n =
dynamic_cast<const T *
>( node );
308 QSet<int> referencedAttributeIndexes(
const QgsFields &fields )
const;
311 bool needsGeometry()
const;
331 bool hasEvalError()
const;
333 QString evalErrorString()
const;
335 void setEvalErrorString(
const QString &str );
341 bool isField()
const;
358 void setExpression(
const QString &expression );
365 QString expression()
const;
373 QString dump()
const;
450 static QString replaceExpressionText(
const QString &action,
const QgsExpressionContext *context,
460 static QSet<QString> referencedVariables(
const QString &text );
472 static double evaluateToDouble(
const QString &text,
double fallbackValue );
488 static QList<QgsExpressionFunction *> sFunctions
SIP_SKIP;
489 static const QList<QgsExpressionFunction *> &Functions();
493 static const QStringList &BuiltinFunctions();
509 static bool unregisterFunction(
const QString &name );
515 static QList<QgsExpressionFunction *> sOwnedFunctions
SIP_SKIP;
521 static void cleanRegisteredFunctions();
524 static bool isFunctionName(
const QString &name );
527 static int functionIndex(
const QString &name );
533 static int functionCount();
540 static QString quotedColumnRef( QString name );
547 static QString quotedString( QString text );
557 static QString quotedValue(
const QVariant &value );
568 static QString quotedValue(
const QVariant &value, QVariant::Type type );
578 static QString helpText( QString name );
586 static QString variableHelpText(
const QString &variableName );
597 static QString formatVariableHelp(
const QString &description,
bool showValue =
true,
const QVariant &value = QVariant() );
603 static QString group(
const QString &group );
613 static QString formatPreviewString(
const QVariant &value,
bool htmlOutput =
true );
623 static QString createFieldEqualityExpression(
const QString &fieldName,
const QVariant &value );
626 SIP_PYOBJECT __repr__();
628 QString str = QStringLiteral(
"<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
629 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
636 struct HelpArg SIP_SKIP
638 HelpArg(
const QString &arg,
const QString &desc,
bool descOnly =
false,
bool syntaxOnly =
false,
639 bool optional =
false,
const QString &defaultVal = QString() )
641 , mDescription( desc )
642 , mDescOnly( descOnly )
643 , mSyntaxOnly( syntaxOnly )
644 , mOptional( optional )
645 , mDefaultVal( defaultVal )
649 QString mDescription;
656 struct HelpExample SIP_SKIP
658 HelpExample(
const QString &expression,
const QString &returns,
const QString ¬e = QString() )
659 : mExpression( expression )
660 , mReturns( returns )
669 struct HelpVariant SIP_SKIP
671 HelpVariant(
const QString &name,
const QString &description,
672 const QList<QgsExpression::HelpArg> &arguments = QList<QgsExpression::HelpArg>(),
673 bool variableLenArguments =
false,
674 const QList<QgsExpression::HelpExample> &examples = QList<QgsExpression::HelpExample>(),
675 const QString ¬es = QString() )
677 , mDescription( description )
678 , mArguments( arguments )
679 , mVariableLenArguments( variableLenArguments )
680 , mExamples( examples )
685 QString mDescription;
686 QList<QgsExpression::HelpArg> mArguments;
687 bool mVariableLenArguments;
688 QList<QgsExpression::HelpExample> mExamples;
697 Help(
const QString &name,
const QString &type,
const QString &description,
const QList<QgsExpression::HelpVariant> &variants )
700 , mDescription( description )
701 , mVariants( variants )
706 QString mDescription;
707 QList<QgsExpression::HelpVariant> mVariants;
716 void detach() SIP_SKIP;
718 QgsExpressionPrivate *d =
nullptr;
720 static QHash<QString, Help> sFunctionHelpTexts;
721 static QHash<QString, QString> sVariableHelpTexts;
722 static QHash<QString, QString> sGroups;
725 static
void initFunctionHelp() SIP_SKIP;
727 static
void initVariableHelp() SIP_SKIP;
734 #endif // QGSEXPRESSION_H Class for parsing and evaluation of expressions (formerly called "search strings").
QString errorMsg
The message for the error at this location.
Details about any parser errors that were found when parsing the expression.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
Abstract base class for all nodes that can appear in an expression.
Encapsulate a field in an attribute table or data source.
DistanceUnit
Units of distance.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
A abstract base class for defining QgsExpression functions.
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
QList< const T * > findNodes() const
Returns a list of all nodes of the given class which are used in this expression. ...
The QgsOgcUtils class provides various utility functions for conversion between OGC (Open Geospatial ...