37 return QStringLiteral(
"ValueRelation" );
43 Q_UNUSED( fieldIndex )
47 if ( cache.isValid() )
56 if ( config.value( QStringLiteral(
"AllowMulti" ) ).toBool() )
59 QStringList valueList;
63 if ( keyList.contains( item.key.toString() ) )
65 valueList << item.value;
69 return valueList.join( QStringLiteral(
", " ) ).prepend(
'{' ).append(
'}' );
80 if ( item.key == value )
87 return QStringLiteral(
"(%1)" ).arg( value.toString() );
98 Q_UNUSED( fieldIndex )
99 return QVariant::fromValue<ValueRelationCache>(
createCache( config ) );
113 int ki = fields.
indexOf( config.value( QStringLiteral(
"Key" ) ).toString() );
114 int vi = fields.
indexOf( config.value( QStringLiteral(
"Value" ) ).toString() );
121 const QString expression = config.value( QStringLiteral(
"FilterExpression" ) ).toString();
143 if ( config.value( QStringLiteral(
"OrderByValue" ) ).toBool() )
157 QStringList checkList;
158 if ( value.type() == QVariant::StringList )
159 checkList = value.toStringList();
160 else if ( value.type() == QVariant::String )
161 checkList = value.toString().remove( QChar(
'{' ) ).remove( QChar(
'}' ) ).split(
',' );
162 else if ( value.type() == QVariant::List )
164 QVariantList valuesList( value.toList( ) );
165 for (
const QVariant &listItem : qgis::as_const( valuesList ) )
167 QString v( listItem.toString( ) );
169 checkList.append( v );
179 QSet< QString > formVariables = scope->variableNames().toSet();
181 formVariables.intersect( usedVariables );
182 return formVariables;
192 QSet<QString> attributes;
196 const QSet<QString> formFunctions( scope->functionNames()
201 for (
const auto &f : expFunctions )
204 if ( formFunctions.contains( fd->
name( ) ) )
206 for (
const auto ¶m : f->args( )->list() )
208 attributes.insert( param->eval( &exp, &context ).toString() );
218 for (
auto it = attrs.constBegin() ; it != attrs.constEnd(); it++ )
220 if ( ! feature.
attribute( *it ).isValid() )
bool isValid() const
Returns the validity of this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QSet< QString > referencedVariables() const
Returns a list of all variables which are used in this expression.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFields fields() const override
Returns the list of fields of this layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
An expression node for expression functions.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override
Query the layer for features specified in request.
QString name() const
The name of the function.
A abstract base class for defining QgsExpression functions.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature())
Creates a new scope which contains functions and variables from the current attribute form/table feat...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QList< int > QgsAttributeList
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QList< const T * > findNodes() const
Returns a list of all nodes of the given class which are used in this expression. ...
QSet< QString > referencedFunctions() const
Returns a list of the names of all functions which are used in this expression.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.