QgsEditorWidgetFactory class

Every attribute editor widget needs a factory, which inherits this class.

It provides metadata for the widgets such as the name (human readable), it serializes the configuration to an xml structure and loads the configuration from there.

It also has factory methods to create a widget wrapper for the attribute editor itself and another factory method to create a configuration dialog.

Derived classes

class QgsBinaryWidgetFactory
Editor widget factory for binary (BLOB) widgets.
class QgsCheckboxWidgetFactory
class QgsClassificationWidgetWrapperFactory
class QgsColorWidgetFactory
class QgsDateTimeEditFactory
class QgsEnumerationWidgetFactory
class QgsExternalResourceWidgetFactory
class QgsHiddenWidgetFactory
class QgsKeyValueWidgetFactory
Factory for widgets for editing a QVariantMap.
class QgsListWidgetFactory
Factory for widgets for editing a QVariantList or a QStringList.
class QgsRangeWidgetFactory
class QgsRelationReferenceFactory
class QgsTextEditWidgetFactory
class QgsUniqueValueWidgetFactory
class QgsUuidWidgetFactory
class QgsValueMapWidgetFactory
class QgsValueRelationWidgetFactory

Constructors, destructors, conversion operators

QgsEditorWidgetFactory(const QString& name)
Constructor.

Public functions

auto configWidget(QgsVectorLayer* vl, int fieldIdx, QWidget* parent) const -> QgsEditorConfigWidget* pure virtual
Override this in your implementation.
auto create(QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent) const -> QgsEditorWidgetWrapper* pure virtual
Override this in your implementation.
auto createSearchWidget(QgsVectorLayer* vl, int fieldIdx, QWidget* parent) const -> QgsSearchWidgetWrapper* virtual
By default a simple QgsFilterLineEdit is returned as search widget.
auto fieldScore(const QgsVectorLayer* vl, int fieldIdx) const -> unsigned int virtual
This method allows disabling this editor widget type for a certain field.
auto name() -> QString
Returns The human readable identifier name of this widget type.
auto supportedWidgetTypes() -> QHash<const char*, int> virtual
Returns a list of widget types which this editor widget supports.
auto supportsField(const QgsVectorLayer* vl, int fieldIdx) -> bool
Check if this editor widget type supports a certain field.

Function documentation

QgsEditorWidgetFactory::QgsEditorWidgetFactory(const QString& name)

Constructor.

Parameters
name A human readable name for this widget type

QgsEditorConfigWidget* QgsEditorWidgetFactory::configWidget(QgsVectorLayer* vl, int fieldIdx, QWidget* parent) const pure virtual

Override this in your implementation.

Parameters
vl The layer for which the widget will be created
fieldIdx The field index for which the widget will be created
parent The parent widget of the created config widget
Returns A configuration widget

Create a new configuration widget for this widget type.

QgsEditorWidgetWrapper* QgsEditorWidgetFactory::create(QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent) const pure virtual

Override this in your implementation.

Parameters
vl The vector layer on which this widget will act
fieldIdx The field index on which this widget will act
editor An editor widget if already existent. If NULL is provided, a new widget will be created.
parent The parent for the wrapper class and any created widget.
Returns A new widget wrapper

Create a new editor widget wrapper. Call QgsEditorWidgetRegistry::create() instead of calling this method directly.

QgsSearchWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget(QgsVectorLayer* vl, int fieldIdx, QWidget* parent) const virtual

By default a simple QgsFilterLineEdit is returned as search widget.

Override in own factory to get something different than the default.

unsigned int QgsEditorWidgetFactory::fieldScore(const QgsVectorLayer* vl, int fieldIdx) const virtual

This method allows disabling this editor widget type for a certain field.

Parameters
vl
fieldIdx
Returns 0 if the field is not supported or a bigger number if it can (the widget with the biggest number will be taken by default). The default implementation returns 5..

By default, it returns 5 for every fields. Reimplement this if you only support certain fields.

Typical return values are:

  • 0: not supported
  • 5: maybe support (for example, Datetime support strings depending on their content)
  • 10: basic support (this is what returns TextEdit for example, since it supports everything in a crude way)
  • 20: specialized support

QString QgsEditorWidgetFactory::name()

Returns The human readable identifier name of this widget type.

Returns a name

QHash<const char*, int> QgsEditorWidgetFactory::supportedWidgetTypes() virtual

Returns a list of widget types which this editor widget supports.

Returns A map of widget type names and weight values

Each widget type can have a priority value attached, the factory with the highest one will be used.

bool QgsEditorWidgetFactory::supportsField(const QgsVectorLayer* vl, int fieldIdx)

Check if this editor widget type supports a certain field.

Parameters
vl The layer
fieldIdx The field index
Returns True if the type is supported for this field