QGIS API Documentation  2.99.0-Master (6a61179)
Public Member Functions | Static Protected Member Functions | List of all members
QgsEditorWidgetFactory Class Referenceabstract

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

#include <qgseditorwidgetfactory.h>

Inheritance diagram for QgsEditorWidgetFactory:
Inheritance graph
[legend]

Public Member Functions

 QgsEditorWidgetFactory (const QString &name)
 Constructor. More...
 
virtual ~QgsEditorWidgetFactory ()
 
virtual Qt::AlignmentFlag alignmentFlag (QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config) const
 Return the alignment for a particular field. More...
 
virtual QgsEditorConfigWidgetconfigWidget (QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const =0
 Override this in your implementation. More...
 
virtual QgsEditorWidgetWrappercreate (QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const =0
 Override this in your implementation. More...
 
virtual QVariant createCache (QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config)
 Create a cache for a given field. More...
 
virtual QgsSearchWidgetWrappercreateSearchWidget (QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const
 By default a simple QgsFilterLineEdit is returned as search widget. More...
 
virtual unsigned int fieldScore (const QgsVectorLayer *vl, int fieldIdx) const
 This method allows disabling this editor widget type for a certain field. More...
 
QString name ()
 Return The human readable identifier name of this widget type. More...
 
virtual QgsEditorWidgetConfig readConfig (const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx)
 Read the config from an XML file and map it to a proper QgsEditorWidgetConfig. More...
 
QgsEditorWidgetConfig readEditorConfig (const QDomElement &configElement, QgsVectorLayer *layer, int fieldIdx)
 Read the config from an XML file and map it to a proper QgsEditorWidgetConfig. More...
 
virtual QString representValue (QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value) const
 Create a pretty String representation of the value. More...
 
virtual QVariant sortValue (QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &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...
 
virtual QHash< const char *, int > supportedWidgetTypes ()
 Returns a list of widget types which this editor widget supports. More...
 
bool supportsField (const QgsVectorLayer *vl, int fieldIdx)
 Check if this editor widget type supports a certain field. More...
 
virtual void writeConfig (const QgsEditorWidgetConfig &config, QDomElement &configElement, QDomDocument &doc, const QgsVectorLayer *layer, int fieldIdx)
 Serialize your configuration and save it in a xml doc. More...
 

Static Protected Member Functions

static void config2xml (const QgsEditorWidgetConfig &config, QDomElement &configElement, const QString &fieldName)
 Copy the given config element to a XML attribute. More...
 
static void xml2config (const QDomElement &configElement, QgsEditorWidgetConfig &config, const QString &fieldName)
 Copy the given XML attribute to the configuration element. More...
 

Detailed Description

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.

Definition at line 40 of file qgseditorwidgetfactory.h.

Constructor & Destructor Documentation

§ QgsEditorWidgetFactory()

QgsEditorWidgetFactory::QgsEditorWidgetFactory ( const QString &  name)

Constructor.

Parameters
nameA human readable name for this widget type

Definition at line 26 of file qgseditorwidgetfactory.cpp.

§ ~QgsEditorWidgetFactory()

QgsEditorWidgetFactory::~QgsEditorWidgetFactory ( )
virtual

Definition at line 31 of file qgseditorwidgetfactory.cpp.

Member Function Documentation

§ alignmentFlag()

Qt::AlignmentFlag QgsEditorWidgetFactory::alignmentFlag ( QgsVectorLayer vl,
int  fieldIdx,
const QgsEditorWidgetConfig config 
) const
virtual

Return the alignment for a particular field.

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

Parameters
vlThe vector layer.
fieldIdxThe index of the field.
configThe editor widget config.
Returns
The alignment flag, normally Qt::AlignRight or Qt::AlignLeft

Reimplemented in QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsValueRelationWidgetFactory, and QgsValueMapWidgetFactory.

Definition at line 87 of file qgseditorwidgetfactory.cpp.

§ config2xml()

void QgsEditorWidgetFactory::config2xml ( const QgsEditorWidgetConfig config,
QDomElement &  configElement,
const QString &  fieldName 
)
staticprotected

Copy the given config element to a XML attribute.

Definition at line 126 of file qgseditorwidgetfactory.cpp.

§ configWidget()

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

Override this in your implementation.

Create a new configuration widget for this widget type.

Parameters
vlThe layer for which the widget will be created
fieldIdxThe field index for which the widget will be created
parentThe parent widget of the created config widget
Returns
A configuration widget

Implemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsValueRelationWidgetFactory, QgsExternalResourceWidgetFactory, QgsCheckboxWidgetFactory, QgsPhotoWidgetFactory, QgsTextEditWidgetFactory, QgsUniqueValueWidgetFactory, QgsValueMapWidgetFactory, QgsClassificationWidgetWrapperFactory, QgsColorWidgetFactory, QgsEnumerationWidgetFactory, QgsFileNameWidgetFactory, QgsHiddenWidgetFactory, QgsRangeWidgetFactory, QgsUuidWidgetFactory, and QgsWebViewWidgetFactory.

§ create()

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

Override this in your implementation.

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

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

Implemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsExternalResourceWidgetFactory, QgsValueRelationWidgetFactory, QgsPhotoWidgetFactory, QgsUniqueValueWidgetFactory, QgsCheckboxWidgetFactory, QgsClassificationWidgetWrapperFactory, QgsColorWidgetFactory, QgsEnumerationWidgetFactory, QgsFileNameWidgetFactory, QgsHiddenWidgetFactory, QgsRangeWidgetFactory, QgsTextEditWidgetFactory, QgsUuidWidgetFactory, QgsValueMapWidgetFactory, and QgsWebViewWidgetFactory.

§ createCache()

QVariant QgsEditorWidgetFactory::createCache ( QgsVectorLayer vl,
int  fieldIdx,
const QgsEditorWidgetConfig config 
)
virtual

Create a cache for a given field.

Parameters
vlThe vector layer.
fieldIdxThe index of the field.
configThe editor widget config.
Returns
The default implementation returns an invalid QVariant

Reimplemented in QgsValueRelationWidgetFactory.

Definition at line 101 of file qgseditorwidgetfactory.cpp.

§ createSearchWidget()

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.

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsValueRelationWidgetFactory, QgsCheckboxWidgetFactory, QgsTextEditWidgetFactory, and QgsValueMapWidgetFactory.

Definition at line 39 of file qgseditorwidgetfactory.cpp.

§ fieldScore()

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

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

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: specialised support
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..
See also
supportsField( QgsVectorLayer* vl, fieldIdx )

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsCheckboxWidgetFactory, QgsExternalResourceWidgetFactory, QgsTextEditWidgetFactory, QgsEnumerationWidgetFactory, QgsColorWidgetFactory, and QgsUuidWidgetFactory.

Definition at line 119 of file qgseditorwidgetfactory.cpp.

§ name()

QString QgsEditorWidgetFactory::name ( )

Return The human readable identifier name of this widget type.

Returns
a name

Definition at line 44 of file qgseditorwidgetfactory.cpp.

§ readConfig()

QgsEditorWidgetConfig QgsEditorWidgetFactory::readConfig ( const QDomElement &  configElement,
QgsVectorLayer layer,
int  fieldIdx 
)
virtual

Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.

Parameters
configElementThe configuration element from the project file
layerThe layer for which this configuration applies
fieldIdxThe field on the layer for which this configuration applies
Returns
A configuration object. This will be passed to your widget wrapper later on

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsValueRelationWidgetFactory, QgsCheckboxWidgetFactory, QgsPhotoWidgetFactory, QgsUniqueValueWidgetFactory, QgsValueMapWidgetFactory, QgsRangeWidgetFactory, and QgsWebViewWidgetFactory.

Definition at line 110 of file qgseditorwidgetfactory.cpp.

§ readEditorConfig()

QgsEditorWidgetConfig QgsEditorWidgetFactory::readEditorConfig ( const QDomElement &  configElement,
QgsVectorLayer layer,
int  fieldIdx 
)

Read the config from an XML file and map it to a proper QgsEditorWidgetConfig.

Parameters
configElementThe configuration element from the project file
layerThe layer for which this configuration applies
fieldIdxThe field on the layer for which this configuration applies
Returns
A configuration object. This will be passed to your widget wrapper later on

Definition at line 49 of file qgseditorwidgetfactory.cpp.

§ representValue()

QString QgsEditorWidgetFactory::representValue ( QgsVectorLayer vl,
int  fieldIdx,
const QgsEditorWidgetConfig config,
const QVariant &  cache,
const QVariant &  value 
) const
virtual

Create a pretty String representation of the value.

Parameters
vlThe vector layer.
fieldIdxThe index of the field.
configThe editor widget config.
cacheThe editor widget cache.
valueThe value to represent.
Returns
By default the string representation of the provided value as implied by the field definition is returned.

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsValueRelationWidgetFactory, and QgsValueMapWidgetFactory.

Definition at line 63 of file qgseditorwidgetfactory.cpp.

§ sortValue()

QVariant QgsEditorWidgetFactory::sortValue ( QgsVectorLayer vl,
int  fieldIdx,
const QgsEditorWidgetConfig 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.

Parameters
vlThe vector layer.
fieldIdxThe index of the field.
configThe editor widget config.
cacheThe editor widget cache.
valueThe value to represent.
Returns
By default the value is returned unmodified.
Note
Added in 2.16

Reimplemented in QgsRelationReferenceFactory, QgsValueRelationWidgetFactory, and QgsValueMapWidgetFactory.

Definition at line 78 of file qgseditorwidgetfactory.cpp.

§ supportedWidgetTypes()

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

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

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

Returns
A map of widget type names and weight values
Note
not available in Python bindings

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsValueMapWidgetFactory, QgsCheckboxWidgetFactory, and QgsRangeWidgetFactory.

Definition at line 129 of file qgseditorwidgetfactory.h.

§ supportsField()

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

Check if this editor widget type supports a certain field.

Parameters
vlThe layer
fieldIdxThe field index
Returns
True if the type is supported for this field
See also
fieldScore( const QgsVectorLayer* vl, ind fieldIdx )

Definition at line 119 of file qgseditorwidgetfactory.h.

§ writeConfig()

void QgsEditorWidgetFactory::writeConfig ( const QgsEditorWidgetConfig config,
QDomElement &  configElement,
QDomDocument &  doc,
const QgsVectorLayer layer,
int  fieldIdx 
)
virtual

Serialize your configuration and save it in a xml doc.

Parameters
configThe configuration to serialize
configElementThe element, where you can write your configuration into
docThe document. You can use this to create new nodes
layerThe layer for which this configuration applies
fieldIdxThe field on the layer for which this configuration applies

Reimplemented in QgsRelationReferenceFactory, QgsDateTimeEditFactory, QgsKeyValueWidgetFactory, QgsListWidgetFactory, QgsValueRelationWidgetFactory, QgsExternalResourceWidgetFactory, QgsCheckboxWidgetFactory, QgsPhotoWidgetFactory, QgsTextEditWidgetFactory, QgsUniqueValueWidgetFactory, QgsValueMapWidgetFactory, QgsRangeWidgetFactory, and QgsWebViewWidgetFactory.

Definition at line 54 of file qgseditorwidgetfactory.cpp.

§ xml2config()

void QgsEditorWidgetFactory::xml2config ( const QDomElement &  configElement,
QgsEditorWidgetConfig config,
const QString &  fieldName 
)
staticprotected

Copy the given XML attribute to the configuration element.

Definition at line 142 of file qgseditorwidgetfactory.cpp.


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