Class: QgsFieldFormatter¶
A field formatter helps to handle and display values for a field.
It allows for using a shared configuration with the editor widgets for
representation of attribute values. Field kits normally have one single
instance which is managed by the QgsFieldFormatterRegistry
.
Custom field formatters should be registered there and field formatters
for use within code should normally be obtained from there.
This is an abstract base class and will always need to be subclassed.
Class Hierarchy¶
Subclasses¶
Field formatter for a checkbox field. |
|
Field formatter for a date time field. |
|
A default fallback field formatter in case no specialized field formatter is defined. |
|
Field formatter for a key value field. |
|
Field formatter for a list field. |
|
Field formatter for a range (double) field with precision and locale. |
|
Field formatter for a relation reference field. |
|
Field formatter for a ValueMap field. |
|
Field formatter for a value relation field. |
Methods
Returns the alignment for a particular field. |
|
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 |
|
Create a cache for a given field. |
|
Returns the flags |
|
Returns a unique id for this field formatter. |
|
Create a pretty String representation of the value. |
|
Sets the flags |
|
If the default sort order should be overwritten for this widget, you can transform the value in here. |
Attributes
- class qgis.core.QgsFieldFormatter[source]¶
Bases:
object
- CanProvideAvailableValues = 1¶
- class Flag¶
Bases:
int
- class Flags¶
- class Flags(f: QgsFieldFormatter.Flags | QgsFieldFormatter.Flag)
- class Flags(a0: QgsFieldFormatter.Flags)
Bases:
object
- alignmentFlag(self, layer: QgsVectorLayer | None, fieldIndex: int, config: Dict[str, Any]) Qt.AlignmentFlag [source]¶
Returns the alignment for a particular field. By default this will consider the field type but can be overwritten if mapped values are represented.
- Parameters:
layer (Optional[QgsVectorLayer])
fieldIndex (int)
config (Dict[str, Any])
- Return type:
Qt.AlignmentFlag
- availableValues(self, config: Dict[str, Any], countLimit: int, context: QgsFieldFormatterContext) List[Any] [source]¶
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
Added in version 3.12.
- Parameters:
config (Dict[str, Any])
countLimit (int)
context (QgsFieldFormatterContext)
- Return type:
List[Any]
- createCache(self, layer: QgsVectorLayer | None, fieldIndex: int, config: Dict[str, Any]) Any [source]¶
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
andQgsEditorWidgetWrapper
.For example, the attribute table will create a cache once for each field and then use this cache for representation. The
QgsValueRelationFieldFormatter
andQgsValueRelationEditorWidget
implement this functionality to create a lookuptable once (a QVariantMap / dict) and are make use of a cache if present.- Parameters:
layer (Optional[QgsVectorLayer])
fieldIndex (int)
config (Dict[str, Any])
- Return type:
Any
- flags(self) QgsFieldFormatter.Flags [source]¶
Returns the flags
Added in version 3.12.
- Return type:
- id(self) str [source]¶
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
.- Return type:
str
- representValue(self, layer: QgsVectorLayer | None, fieldIndex: int, config: Dict[str, Any], cache: Any, value: Any) str [source]¶
Create a pretty String representation of the value.
- Return type:
str
- Returns:
By default the string representation of the provided value as implied by the field definition is returned.
- Parameters:
layer (Optional[QgsVectorLayer])
fieldIndex (int)
config (Dict[str, Any])
cache (Any)
value (Any)
- setFlags(self, flags: QgsFieldFormatter.Flags | QgsFieldFormatter.Flag)[source]¶
Sets the
flags
Added in version 3.12.
- Parameters:
flags (Union[QgsFieldFormatter.Flags, QgsFieldFormatter.Flag])
- sortValue(self, layer: QgsVectorLayer | None, fieldIndex: int, config: Dict[str, Any], cache: Any, value: Any) Any [source]¶
If the default sort order should be overwritten for this widget, you can transform the value in here.
- Return type:
Any
- Returns:
an unmodified value by default.
- Parameters:
layer (Optional[QgsVectorLayer])
fieldIndex (int)
config (Dict[str, Any])
cache (Any)
value (Any)