QGIS API Documentation  3.20.0-Odense (decaadbb31)
Public Types | Public Member Functions | List of all members
QgsFieldFormatter Class Referenceabstract

A field formatter helps to handle and display values for a field. More...

#include <qgsfieldformatter.h>

Inheritance diagram for QgsFieldFormatter:
Inheritance graph
[legend]

Public Types

enum  Flag { CanProvideAvailableValues = 1 }
 Flags for the abilities of the formatter. More...
 

Public Member Functions

 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...
 
virtual QVariantList availableValues (const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context) const
 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...
 
virtual QVariant createCache (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config) const
 Create a cache for a given field. More...
 
Flags flags () const
 Returns the flags. More...
 
virtual QString id () const =0
 Returns a unique id for this field formatter. More...
 
virtual QList< QgsVectorLayerReflayerDependencies (const QVariantMap &config) const SIP_SKIP
 Returns a list of weak layer references to other layers required by this formatter for the given config. More...
 
virtual QString representValue (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const
 Create a pretty String representation of the value. More...
 
void setFlags (const Flags &flags)
 Sets the flags. More...
 
virtual QVariant sortValue (QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value) const
 If the default sort order should be overwritten for this widget, you can transform the value in here. More...
 

Detailed Description

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.

Since
QGIS 3.0

Definition at line 72 of file qgsfieldformatter.h.

Member Enumeration Documentation

◆ Flag

Flags for the abilities of the formatter.

Since
QGIS 3.12
Enumerator
CanProvideAvailableValues 

Can provide possible values.

Definition at line 88 of file qgsfieldformatter.h.

Constructor & Destructor Documentation

◆ QgsFieldFormatter()

QgsFieldFormatter::QgsFieldFormatter ( )
default

Default constructor.

◆ ~QgsFieldFormatter()

virtual QgsFieldFormatter::~QgsFieldFormatter ( )
virtualdefault

Member Function Documentation

◆ alignmentFlag()

Qt::AlignmentFlag QgsFieldFormatter::alignmentFlag ( QgsVectorLayer layer,
int  fieldIndex,
const QVariantMap &  config 
) const
virtual

Returns the alignment for a particular field.

By default this will consider the field type but can be overwritten if mapped values are represented.

Since
QGIS 3.0

Definition at line 53 of file qgsfieldformatter.cpp.

◆ availableValues()

QVariantList QgsFieldFormatter::availableValues ( const QVariantMap &  config,
int  countLimit,
const QgsFieldFormatterContext context 
) const
virtual

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 in QgsValueRelationFieldFormatter, QgsValueMapFieldFormatter, and QgsRelationReferenceFieldFormatter.

Definition at line 79 of file qgsfieldformatter.cpp.

◆ createCache()

QVariant QgsFieldFormatter::createCache ( QgsVectorLayer layer,
int  fieldIndex,
const QVariantMap &  config 
) const
virtual

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 in QgsValueRelationFieldFormatter, and QgsRelationReferenceFieldFormatter.

Definition at line 64 of file qgsfieldformatter.cpp.

◆ flags()

Flags QgsFieldFormatter::flags ( ) const
inline

Returns the flags.

Since
QGIS 3.12

Definition at line 170 of file qgsfieldformatter.h.

◆ id()

virtual QString QgsFieldFormatter::id ( ) const
pure virtual

◆ layerDependencies()

QList< QgsVectorLayerRef > QgsFieldFormatter::layerDependencies ( const QVariantMap &  config) const
virtual

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 in QgsRelationReferenceFieldFormatter, and QgsValueRelationFieldFormatter.

Definition at line 73 of file qgsfieldformatter.cpp.

◆ representValue()

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

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 in QgsValueRelationFieldFormatter, QgsValueMapFieldFormatter, QgsRelationReferenceFieldFormatter, QgsRangeFieldFormatter, QgsListFieldFormatter, QgsKeyValueFieldFormatter, QgsDateTimeFieldFormatter, and QgsCheckBoxFieldFormatter.

Definition at line 24 of file qgsfieldformatter.cpp.

◆ setFlags()

void QgsFieldFormatter::setFlags ( const Flags &  flags)

Sets the flags.

Since
QGIS 3.12

Definition at line 88 of file qgsfieldformatter.cpp.

◆ sortValue()

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

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 in QgsValueRelationFieldFormatter, QgsValueMapFieldFormatter, and QgsRelationReferenceFieldFormatter.

Definition at line 43 of file qgsfieldformatter.cpp.


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