39 return QStringLiteral(
"ValueRelation" );
46 if ( cache.isValid() )
55 if ( config.value( QStringLiteral(
"AllowMulti" ) ).toBool() )
59 if ( layer->
fields().
at( fieldIndex ).
type() == QVariant::Map )
62 keyList = value.toStringList();
69 QStringList valueList;
73 if ( keyList.contains( item.key.toString() ) )
75 valueList << item.value;
79 return valueList.join( QStringLiteral(
", " ) ).prepend(
'{' ).append(
'}' );
90 if ( item.key == value )
97 return QStringLiteral(
"(%1)" ).arg( value.toString() );
108 Q_UNUSED( fieldIndex )
109 return QVariant::fromValue<ValueRelationCache>(
createCache( config ) );
123 int ki = fields.
indexOf( config.value( QStringLiteral(
"Key" ) ).toString() );
124 int vi = fields.
indexOf( config.value( QStringLiteral(
"Value" ) ).toString() );
131 const QString expression = config.value( QStringLiteral(
"FilterExpression" ) ).toString();
153 if ( config.value( QStringLiteral(
"OrderByValue" ) ).toBool() )
167 QStringList checkList;
168 if ( value.type() == QVariant::StringList )
169 checkList = value.toStringList();
170 else if ( value.type() == QVariant::String )
171 checkList = value.toString().remove( QChar(
'{' ) ).remove( QChar(
'}' ) ).split(
',' );
172 else if ( value.type() == QVariant::List )
174 QVariantList valuesList( value.toList( ) );
175 for (
const QVariant &listItem : qgis::as_const( valuesList ) )
177 QString v( listItem.toString( ) );
179 checkList.append( v );
189 QSet< QString > formVariables = scope->variableNames().toSet();
191 formVariables.intersect( usedVariables );
192 return formVariables;
202 QSet<QString> attributes;
206 const QSet<QString> formFunctions( scope->functionNames()
211 for (
const auto &f : expFunctions )
214 if ( formFunctions.contains( fd->
name( ) ) )
216 for (
const auto ¶m : f->args( )->list() )
218 attributes.insert( param->eval( &exp, &context ).toString() );
228 for (
auto it = attrs.constBegin() ; it != attrs.constEnd(); it++ )
230 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...
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table feat...
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.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
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 FINAL
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.
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.
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.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
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.