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.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: id()
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. |
Abstract Methods
Returns a unique id for this field formatter. |
Methods
Returns the flags |
|
Sets the flags |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsFieldFormatter. See the FAQ for more details.
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. |
|
Create a pretty String representation of the value. |
|
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
- virtual 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
- virtual 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]
- virtual 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:
- abstract 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
- virtual 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])
- virtual 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)