QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsValueRelationFieldFormatter Class Reference

Field formatter for a value relation field. More...

#include <qgsvaluerelationfieldformatter.h>

Inheritance diagram for QgsValueRelationFieldFormatter:
Inheritance graph
[legend]

Classes

struct  ValueRelationItem
 

Public Types

typedef QVector< QgsValueRelationFieldFormatter::ValueRelationItemValueRelationCache
 
- Public Types inherited from QgsFieldFormatter
enum  Flag { CanProvideAvailableValues = 1 }
 Flags for the abilities of the formatter. More...
 

Public Member Functions

 QgsValueRelationFieldFormatter ()
 Constructor for QgsValueRelationFieldFormatter. More...
 
QVariantList availableValues (const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context) const override
 Returns a list of the values that would be possible to select with this widget type On a RelationReference that would be the parents ids or on ValueMap all the configured keys according to the settings in the config. More...
 
QVariant createCache (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config) const override
 Create a cache for a given field. More...
 
QString id () const override
 Returns a unique id for this field formatter. More...
 
QList< QgsVectorLayerReflayerDependencies (const QVariantMap &config) const override
 Returns a list of weak layer references to other layers required by this formatter for the given config. More...
 
QString representValue (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const override
 Create a pretty String representation of the value. More...
 
QVariant sortValue (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const override
 If the default sort order should be overwritten for this widget, you can transform the value in here. More...
 
- Public Member Functions inherited from QgsFieldFormatter
 QgsFieldFormatter ()=default
 Default constructor. More...
 
virtual ~QgsFieldFormatter ()=default
 
virtual Qt::AlignmentFlag alignmentFlag (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config) const
 Returns the alignment for a particular field. More...
 
Flags flags () const
 Returns the flags. More...
 
void setFlags (const Flags &flags)
 Sets the flags. More...
 

Static Public Member Functions

static QgsValueRelationFieldFormatter::ValueRelationCache createCache (const QVariantMap &config, const QgsFeature &formFeature=QgsFeature(), const QgsFeature &parentFormFeature=QgsFeature())
 Create a cache for a value relation field. More...
 
static QSet< QString > expressionFormAttributes (const QString &expression)
 Returns a list of attributes required by the form context expression. More...
 
static QSet< QString > expressionFormVariables (const QString &expression)
 Returns a list of variables required by the form context expression. More...
 
static bool expressionIsUsable (const QString &expression, const QgsFeature &feature, const QgsFeature &parentFeature=QgsFeature())
 Check whether the feature has all values required by the expression, optionally checks for parentFeature. More...
 
static QSet< QString > expressionParentFormAttributes (const QString &expression)
 Returns a list of attributes required by the parent form's form context expression. More...
 
static QSet< QString > expressionParentFormVariables (const QString &expression)
 Returns a list of variables required by the parent form's form context expression. More...
 
static bool expressionRequiresFormScope (const QString &expression)
 Check if the expression requires a form scope (i.e. More...
 
static bool expressionRequiresParentFormScope (const QString &expression)
 Check if the expression requires a parent form scope (i.e. More...
 
static QgsVectorLayerresolveLayer (const QVariantMap &config, const QgsProject *project)
 Returns the (possibly NULL) layer from the widget's config and project. More...
 
static QStringList valueToStringList (const QVariant &value)
 Utility to convert a list or a string representation of an (hstore style: {1,2...}) list in value to a string list. More...
 

Detailed Description

Field formatter for a value relation field.

A value relation field formatter looks up the values from features on another layer.

Since
QGIS 3.0

Definition at line 36 of file qgsvaluerelationfieldformatter.h.

Member Typedef Documentation

◆ ValueRelationCache

Definition at line 56 of file qgsvaluerelationfieldformatter.h.

Constructor & Destructor Documentation

◆ QgsValueRelationFieldFormatter()

QgsValueRelationFieldFormatter::QgsValueRelationFieldFormatter ( )

Constructor for QgsValueRelationFieldFormatter.

Definition at line 43 of file qgsvaluerelationfieldformatter.cpp.

Member Function Documentation

◆ availableValues()

QVariantList QgsValueRelationFieldFormatter::availableValues ( const QVariantMap &  config,
int  countLimit,
const QgsFieldFormatterContext context 
) const
overridevirtual

Returns a list of the values that would be possible to select with this widget type On a RelationReference that would be the parents ids or on ValueMap all the configured keys according to the settings in the config.

Since
QGIS 3.12

Reimplemented from QgsFieldFormatter.

Definition at line 212 of file qgsvaluerelationfieldformatter.cpp.

◆ createCache() [1/2]

QgsValueRelationFieldFormatter::ValueRelationCache QgsValueRelationFieldFormatter::createCache ( const QVariantMap &  config,
const QgsFeature formFeature = QgsFeature(),
const QgsFeature parentFormFeature = QgsFeature() 
)
static

Create a cache for a value relation field.

This can be used to keep the value map in the local memory if doing multiple lookups in a loop.

Parameters
configThe widget configuration
formFeatureThe feature currently being edited with current attribute values
parentFormFeatureFor embedded forms only, the feature currently being edited in the parent form with current attribute values
Returns
A kvp list of values for the widget
Since
QGIS 3.0

Definition at line 124 of file qgsvaluerelationfieldformatter.cpp.

◆ createCache() [2/2]

QVariant QgsValueRelationFieldFormatter::createCache ( QgsVectorLayer layer,
int  fieldIndex,
const QVariantMap &  config 
) const
overridevirtual

Create a cache for a given field.

This will be used in situations where a field is being represented various times in a loop. And will be passed to other methods on QgsFieldKit and QgsEditorWidgetWrapper.

For example, the attribute table will create a cache once for each field and then use this cache for representation. The QgsValueRelationFieldFormatter and QgsValueRelationEditorWidget implement this functionality to create a lookuptable once (a QVariantMap / dict) and are make use of a cache if present.

Since
QGIS 3.0

Reimplemented from QgsFieldFormatter.

Definition at line 116 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionFormAttributes()

QSet< QString > QgsValueRelationFieldFormatter::expressionFormAttributes ( const QString &  expression)
static

Returns a list of attributes required by the form context expression.

Parameters
expressionForm filter expression
Returns
list of attributes required by the expression
Since
QGIS 3.2

Definition at line 343 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionFormVariables()

QSet< QString > QgsValueRelationFieldFormatter::expressionFormVariables ( const QString &  expression)
static

Returns a list of variables required by the form context expression.

Parameters
expressionForm filter expression
Returns
list of variables required by the expression
Since
QGIS 3.2

Definition at line 291 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionIsUsable()

bool QgsValueRelationFieldFormatter::expressionIsUsable ( const QString &  expression,
const QgsFeature feature,
const QgsFeature parentFeature = QgsFeature() 
)
static

Check whether the feature has all values required by the expression, optionally checks for parentFeature.

Returns
true if the expression can be used
Since
QGIS 3.2

Definition at line 367 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionParentFormAttributes()

QSet< QString > QgsValueRelationFieldFormatter::expressionParentFormAttributes ( const QString &  expression)
static

Returns a list of attributes required by the parent form's form context expression.

Parameters
expressionForm filter expression
Returns
list of parent attributes required by the expression
Since
QGIS 3.14

Definition at line 319 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionParentFormVariables()

QSet< QString > QgsValueRelationFieldFormatter::expressionParentFormVariables ( const QString &  expression)
static

Returns a list of variables required by the parent form's form context expression.

Parameters
expressionForm filter expression
Returns
list of parent variables required by the expression
Since
QGIS 3.14

Definition at line 300 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionRequiresFormScope()

bool QgsValueRelationFieldFormatter::expressionRequiresFormScope ( const QString &  expression)
static

Check if the expression requires a form scope (i.e.

if it uses fields or geometry of the currently edited feature).

Parameters
expressionThe widget's filter expression
Returns
true if the expression requires a form scope
Since
QGIS 3.2

Definition at line 309 of file qgsvaluerelationfieldformatter.cpp.

◆ expressionRequiresParentFormScope()

bool QgsValueRelationFieldFormatter::expressionRequiresParentFormScope ( const QString &  expression)
static

Check if the expression requires a parent form scope (i.e.

if it uses fields or geometry of the parent form's currently edited feature).

Parameters
expressionThe widget's filter expression
Returns
true if the expression requires a parent form scope
Since
QGIS 3.14

Definition at line 314 of file qgsvaluerelationfieldformatter.cpp.

◆ id()

QString QgsValueRelationFieldFormatter::id ( ) const
overridevirtual

Returns a unique id for this field formatter.

This id will later be used to identify this field formatter in the registry with QgsFieldFormatterRegistry::fieldFormatter().

This id matches the id of a QgsEditorWidgetFactory.

Implements QgsFieldFormatter.

Definition at line 48 of file qgsvaluerelationfieldformatter.cpp.

◆ layerDependencies()

QList< QgsVectorLayerRef > QgsValueRelationFieldFormatter::layerDependencies ( const QVariantMap &  config) const
overridevirtual

Returns a list of weak layer references to other layers required by this formatter for the given config.

The default implementation returns an empty list.

This method should be reimplemented by formatters that handle relations with other layers, (e.g. ValueRelation) and can be used by client code to warn the user about missing required dependencies or to add some resolution logic in order to load the missing dependency.

Note
not available in Python bindings
Since
QGIS 3.12

Reimplemented from QgsFieldFormatter.

Definition at line 198 of file qgsvaluerelationfieldformatter.cpp.

◆ representValue()

QString QgsValueRelationFieldFormatter::representValue ( QgsVectorLayer layer,
int  fieldIndex,
const QVariantMap &  config,
const QVariant &  cache,
const QVariant &  value 
) const
overridevirtual

Create a pretty String representation of the value.

Returns
By default the string representation of the provided value as implied by the field definition is returned.
Since
QGIS 3.0

Reimplemented from QgsFieldFormatter.

Definition at line 53 of file qgsvaluerelationfieldformatter.cpp.

◆ resolveLayer()

QgsVectorLayer * QgsValueRelationFieldFormatter::resolveLayer ( const QVariantMap &  config,
const QgsProject project 
)
static

Returns the (possibly NULL) layer from the widget's config and project.

Since
QGIS 3.8

Definition at line 395 of file qgsvaluerelationfieldformatter.cpp.

◆ sortValue()

QVariant QgsValueRelationFieldFormatter::sortValue ( QgsVectorLayer layer,
int  fieldIndex,
const QVariantMap &  config,
const QVariant &  cache,
const QVariant &  value 
) const
overridevirtual

If the default sort order should be overwritten for this widget, you can transform the value in here.

Returns
an unmodified value by default.
Since
QGIS 3.0

Reimplemented from QgsFieldFormatter.

Definition at line 111 of file qgsvaluerelationfieldformatter.cpp.

◆ valueToStringList()

QStringList QgsValueRelationFieldFormatter::valueToStringList ( const QVariant &  value)
static

Utility to convert a list or a string representation of an (hstore style: {1,2...}) list in value to a string list.

Since
QGIS 3.2

Definition at line 228 of file qgsvaluerelationfieldformatter.cpp.


The documentation for this class was generated from the following files: