QgsValueRelationFieldFormatter class
Field formatter for a value relation field.
Contents
A value relation field formatter looks up the values from features on another layer.
Base classes
- class QgsFieldFormatter
- A field formatter helps to handle and display values for a field.
Public static functions
-
static auto createCache(const QVariantMap& config,
const QgsFeature& formFeature = QgsFeature()) -> QgsValueRelationFieldFormatter::
ValueRelationCache - Create a cache for a value relation field.
- static auto expressionFormAttributes(const QString& expression) -> QSet<QString>
- Returns a list of attributes required by the form context expression.
- static auto expressionFormVariables(const QString& expression) -> QSet<QString>
- Returns a list of variables required by the form context expression.
- static auto expressionIsUsable(const QString& expression, const QgsFeature& feature) -> bool
- Check whether the feature has all values required by the expression.
- static auto expressionRequiresFormScope(const QString& expression) -> bool
- Check if the expression requires a form scope (i.e.
- static auto valueToStringList(const QVariant& value) -> QStringList
- Utility to convert an array or a string representation of an array value to a string list.
Constructors, destructors, conversion operators
- QgsValueRelationFieldFormatter() defaulted
- Constructor for QgsValueRelationFieldFormatter.
Public functions
- auto createCache(QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config) const -> QVariant override
- Create a cache for a given field.
- auto id() const -> QString override
- Returns a unique id for this field formatter.
- auto representValue(QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value) const -> QString override
- Create a pretty String representation of the value.
- auto sortValue(QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value) const -> QVariant override
- If the default sort order should be overwritten for this widget, you can transform the value in here.
Function documentation
static QgsValueRelationFieldFormatter:: ValueRelationCache QgsValueRelationFieldFormatter:: createCache(const QVariantMap& config,
const QgsFeature& formFeature = QgsFeature())
Create a cache for a value relation field.
| Parameters | |
|---|---|
| config | The widget configuration |
| formFeature | The feature currently being edited with current attribute values |
| Returns | A kvp list of values for the widget |
This can be used to keep the value map in the local memory if doing multiple lookups in a loop.
static QSet<QString> QgsValueRelationFieldFormatter:: expressionFormAttributes(const QString& expression)
Returns a list of attributes required by the form context expression.
| Parameters | |
|---|---|
| expression | Form filter expression |
| Returns | list of attributes required by the expression |
static QSet<QString> QgsValueRelationFieldFormatter:: expressionFormVariables(const QString& expression)
Returns a list of variables required by the form context expression.
| Parameters | |
|---|---|
| expression | Form filter expression |
| Returns | list of variables required by the expression |
static bool QgsValueRelationFieldFormatter:: expressionIsUsable(const QString& expression,
const QgsFeature& feature)
Check whether the feature has all values required by the expression.
| Returns | True if the expression can be used |
|---|
static bool QgsValueRelationFieldFormatter:: expressionRequiresFormScope(const QString& expression)
Check if the expression requires a form scope (i.e.
| Parameters | |
|---|---|
| expression | The widget's filter expression |
| Returns | true if the expression requires a form scope |
if it uses fields or geometry of the currently edited feature).
static QStringList QgsValueRelationFieldFormatter:: valueToStringList(const QVariant& value)
Utility to convert an array or a string representation of an array value to a string list.
QVariant QgsValueRelationFieldFormatter:: createCache(QgsVectorLayer* layer,
int fieldIndex,
const QVariantMap& config) const override
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.
QString QgsValueRelationFieldFormatter:: id() const override
Returns a unique id for this field formatter.
This id will later be used to identify this field formatter in the registry with QgsFieldFormatterRegistry::
This id matches the id of a QgsEditorWidgetFactory.
QString QgsValueRelationFieldFormatter:: representValue(QgsVectorLayer* layer,
int fieldIndex,
const QVariantMap& config,
const QVariant& cache,
const QVariant& value) const override
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. |
|---|
QVariant QgsValueRelationFieldFormatter:: sortValue(QgsVectorLayer* layer,
int fieldIndex,
const QVariantMap& config,
const QVariant& cache,
const QVariant& value) const override
If the default sort order should be overwritten for this widget, you can transform the value in here.
| Returns | an unmodified value by default. |
|---|