Class: QgsValueRelationFieldFormatter

class qgis.core.QgsValueRelationFieldFormatter

Bases: QgsFieldFormatter

Constructor for QgsValueRelationFieldFormatter.

QgsValueRelationFieldFormatter(QgsValueRelationFieldFormatter)

Field formatter for a value relation field.

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

Methods

availableValues

param config

createCache

createCache(config: Dict[str, Any], formFeature: QgsFeature = QgsFeature(), parentFormFeature: QgsFeature = QgsFeature()) -> List[QgsValueRelationFieldFormatter.ValueRelationItem] Create a cache for a value relation field.

expressionFormAttributes

Returns a list of attributes required by the form context expression

expressionFormVariables

Returns a list of variables required by the form context expression

expressionIsUsable

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

expressionParentFormAttributes

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

expressionParentFormVariables

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

expressionRequiresFormScope

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

expressionRequiresParentFormScope

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

id

rtype

str

representValue

param layer

resolveLayer

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

sortValue

param layer

valueToStringList

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

class ValueRelationItem(key: Any, value: str, description: str = '')

Bases: sip.wrapper

Constructor for ValueRelationItem

QgsValueRelationFieldFormatter.ValueRelationItem() Constructor for ValueRelationItem

QgsValueRelationFieldFormatter.ValueRelationItem(QgsValueRelationFieldFormatter.ValueRelationItem)

description
key
value
availableValues(self, config: Dict[str, Any], countLimit: int, context: QgsFieldFormatterContext)List[Any]
Parameters
Return type

List[Any]

createCache(self, layer: QgsVectorLayer, fieldIndex: int, config: Dict[str, Any])Any

createCache(config: Dict[str, Any], formFeature: QgsFeature = QgsFeature(), parentFormFeature: QgsFeature = QgsFeature()) -> List[QgsValueRelationFieldFormatter.ValueRelationItem] 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
  • config (Dict[str) – The widget configuration

  • formFeature – The feature currently being edited with current attribute values

  • parentFormFeature – For embedded forms only, the feature currently being edited in the parent form with current attribute values

Return type

Any

Returns

A kvp list of values for the widget

New in version 3.0.

Parameters
expressionFormAttributes(expression: str)Set[str]

Returns a list of attributes required by the form context expression

Parameters

expression (str) – Form filter expression

Return type

Set[str]

Returns

list of attributes required by the expression

New in version 3.2.

expressionFormVariables(expression: str)Set[str]

Returns a list of variables required by the form context expression

Parameters

expression (str) – Form filter expression

Return type

Set[str]

Returns

list of variables required by the expression

New in version 3.2.

expressionIsUsable(expression: str, feature: QgsFeature, parentFeature: QgsFeature = QgsFeature())bool

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

Return type

bool

Returns

True if the expression can be used

New in version 3.2.

Parameters
expressionParentFormAttributes(expression: str)Set[str]

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

Parameters

expression (str) – Form filter expression

Return type

Set[str]

Returns

list of parent attributes required by the expression

New in version 3.14.

expressionParentFormVariables(expression: str)Set[str]

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

Parameters

expression (str) – Form filter expression

Return type

Set[str]

Returns

list of parent variables required by the expression

New in version 3.14.

expressionRequiresFormScope(expression: str)bool

Check if the expression requires a form scope (i.e. if it uses fields or geometry of the currently edited feature).

Parameters

expression (str) – The widget’s filter expression

Return type

bool

Returns

True if the expression requires a form scope

New in version 3.2.

expressionRequiresParentFormScope(expression: str)bool

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

expression (str) – The widget’s filter expression

Return type

bool

Returns

True if the expression requires a parent form scope

New in version 3.14.

id(self)str
Return type

str

representValue(self, layer: QgsVectorLayer, fieldIndex: int, config: Dict[str, Any], cache: Any, value: Any)str
Parameters
  • layer (QgsVectorLayer) –

  • fieldIndex (int) –

  • config (Dict[str) –

  • cache (Any) –

  • value (Any) –

Return type

str

resolveLayer(config: Dict[str, Any], project: QgsProject)QgsVectorLayer

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

New in version 3.8.

Parameters
Return type

QgsVectorLayer

sortValue(self, layer: QgsVectorLayer, fieldIndex: int, config: Dict[str, Any], cache: Any, value: Any)Any
Parameters
  • layer (QgsVectorLayer) –

  • fieldIndex (int) –

  • config (Dict[str) –

  • cache (Any) –

  • value (Any) –

Return type

Any

valueToStringList(value: Any)List[str]

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

New in version 3.2.

Parameters

value (Any) –

Return type

List[str]