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;
250 QSet<QString> referencedColumns() const;
259 QSet<QString> referencedVariables() const;
266 QSet<QString> referencedFunctions() const;
276 QList<const QgsExpressionNode *> nodes( )
const;
287 QList<const T *> lst;
288 const QList<const QgsExpressionNode *> allNodes( nodes() );
289 for (
const auto &node : allNodes )
291 const T *n =
dynamic_cast<const T *
>( node );
304 QSet<int> referencedAttributeIndexes(
const QgsFields &fields )
const;
307 bool needsGeometry()
const;
327 bool hasEvalError()
const;
329 QString evalErrorString()
const;
331 void setEvalErrorString(
const QString &str );
337 bool isField()
const;
354 void setExpression(
const QString &expression );
361 QString expression()
const;
369 QString dump()
const;
446 static QString replaceExpressionText(
const QString &action,
const QgsExpressionContext *context,
456 static QSet<QString> referencedVariables(
const QString &text );
468 static double evaluateToDouble(
const QString &text,
double fallbackValue );
484 static QList<QgsExpressionFunction *> sFunctions
SIP_SKIP;
485 static const QList<QgsExpressionFunction *> &Functions();
489 static const QStringList &BuiltinFunctions();
505 static bool unregisterFunction(
const QString &name );
511 static QList<QgsExpressionFunction *> sOwnedFunctions
SIP_SKIP;
517 static void cleanRegisteredFunctions();
520 static bool isFunctionName(
const QString &name );
523 static int functionIndex(
const QString &name );
529 static int functionCount();
536 static QString quotedColumnRef( QString name );
543 static QString quotedString( QString text );
553 static QString quotedValue(
const QVariant &value );
564 static QString quotedValue(
const QVariant &value, QVariant::Type type );
574 static QString helpText( QString name );
582 static QString variableHelpText(
const QString &variableName );
593 static QString formatVariableHelp(
const QString &description,
bool showValue =
true,
const QVariant &value = QVariant() );
599 static QString group(
const QString &group );
609 static QString formatPreviewString(
const QVariant &value,
bool htmlOutput =
true );
619 static QString createFieldEqualityExpression(
const QString &fieldName,
const QVariant &value );
622 SIP_PYOBJECT __repr__();
624 QString str = QStringLiteral(
"<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
625 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
632 struct HelpArg SIP_SKIP
634 HelpArg(
const QString &arg,
const QString &desc,
bool descOnly =
false,
bool syntaxOnly =
false,
635 bool optional =
false,
const QString &defaultVal = QString() )
637 , mDescription( desc )
638 , mDescOnly( descOnly )
639 , mSyntaxOnly( syntaxOnly )
640 , mOptional( optional )
641 , mDefaultVal( defaultVal )
645 QString mDescription;
652 struct HelpExample SIP_SKIP
654 HelpExample(
const QString &expression,
const QString &returns,
const QString ¬e = QString() )
655 : mExpression( expression )
656 , mReturns( returns )
665 struct HelpVariant SIP_SKIP
667 HelpVariant(
const QString &name,
const QString &description,
668 const QList<QgsExpression::HelpArg> &arguments = QList<QgsExpression::HelpArg>(),
669 bool variableLenArguments =
false,
670 const QList<QgsExpression::HelpExample> &examples = QList<QgsExpression::HelpExample>(),
671 const QString ¬es = QString() )
673 , mDescription( description )
674 , mArguments( arguments )
675 , mVariableLenArguments( variableLenArguments )
676 , mExamples( examples )
681 QString mDescription;
682 QList<QgsExpression::HelpArg> mArguments;
683 bool mVariableLenArguments;
684 QList<QgsExpression::HelpExample> mExamples;
693 Help(
const QString &name,
const QString &type,
const QString &description,
const QList<QgsExpression::HelpVariant> &variants )
696 , mDescription( description )
697 , mVariants( variants )
702 QString mDescription;
703 QList<QgsExpression::HelpVariant> mVariants;
712 void detach() SIP_SKIP;
714 QgsExpressionPrivate *d =
nullptr;
716 static QHash<QString, Help> sFunctionHelpTexts;
717 static QHash<QString, QString> sVariableHelpTexts;
718 static QHash<QString, QString> sGroups;
721 static
void initFunctionHelp() SIP_SKIP;
723 static
void initVariableHelp() SIP_SKIP;
730 #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...
Q_DECLARE_METATYPE(QModelIndex)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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 ...