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

createCache

createCache(config: Dict[str, Any], formFeature: 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

expressionRequiresFormScope

Check if the expression requires a 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)

Bases: sip.wrapper

Constructor for ValueRelationItem

QgsValueRelationFieldFormatter.ValueRelationItem() Constructor for ValueRelationItem

QgsValueRelationFieldFormatter.ValueRelationItem(QgsValueRelationFieldFormatter.ValueRelationItem)

Parameters
  • key (Any) –

  • value (str) –

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

createCache(config: Dict[str, Any], formFeature: 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

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) → bool

Check whether the feature has all values required by the expression

Return type

bool

Returns

True if the expression can be used

New in version 3.2.

Parameters
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.

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]