QgsWidgetWrapper class
Manages an editor widget Widget and wrapper share the same parent.
Contents
A wrapper controls one attribute editor widget and is able to create a default widget or use a pre-existent widget. It is able to set the widget to the value implied by a field of a vector layer, or return the value it currently holds. Every time it is changed it has to emit a valueChanged signal. If it fails to do so, there is no guarantee that the changed status of the widget will be saved.
Derived classes
- class QgsEditorWidgetWrapper
- Manages an editor widget Widget and wrapper share the same parent.
- class QgsQmlWidgetWrapper
- Wraps a QQuickWidget to display QML code.
- class QgsSearchWidgetWrapper
- Shows a search widget on a filter form.
Public types
- enum Property { RootPath = 0, DocumentViewerContent }
- Data defined properties for different editor widgets.
Public static functions
- static auto fromWidget(QWidget* widget) -> QgsWidgetWrapper*
- Will return a wrapper for a given widget.
- static auto propertyDefinitions() -> const QgsPropertiesDefinition&
- Returns the editor widget property definitions.
Constructors, destructors, conversion operators
- QgsWidgetWrapper(QgsVectorLayer* vl, QWidget* editor = nullptr, QWidget* parent = nullptr) explicit
- Create a new widget wrapper.
Public functions
- auto config(const QString& key, const QVariant& defaultVal = QVariant()) const -> QVariant
- Use this inside your overridden classes to access the configuration.
- auto config() const -> QVariantMap
- Returns the whole config.
- auto context() const -> const QgsAttributeEditorContext&
- Returns information about the context in which this widget is shown.
- auto dataDefinedProperties() -> QgsPropertyCollection&
- Returns a reference to the editor widget's property collection, used for data defined overrides.
- auto dataDefinedProperties() const -> const QgsPropertyCollection&
- Returns a reference to the editor widget's property collection, used for data defined overrides.
- auto layer() const -> QgsVectorLayer*
- Returns the vector layer associated with the widget.
- void notifyAboutToSave()
- Notify this widget, that the containing form is about to save and that any pending changes should be pushed to the edit buffer or they might be lost.
- void setConfig(const QVariantMap& config)
- Will set the config of this wrapper to the specified config.
- void setContext(const QgsAttributeEditorContext& context)
- Set the context in which this widget is shown.
- void setDataDefinedProperties(const QgsPropertyCollection& collection)
- Sets the editor widget's property collection, used for data defined overrides.
- auto valid() const -> bool pure virtual
- Returns true if the widget has been properly initialized.
- auto widget() -> QWidget*
- Access the widget managed by this wrapper.
-
template<class T>auto widget() -> T*
- Access the widget managed by this wrapper and cast it to a given type Example: QPushButton* pb = wrapper->widget<QPushButton*>();.
Signals
- void contextChanged()
- Signal when QgsAttributeEditorContext mContext changed.
Public slots
- void setEnabled(bool enabled) virtual
- Is used to enable or disable the edit functionality of the managed widget.
- void setFeature(const QgsFeature& feature) pure virtual
- Is called, when the value of the widget needs to be changed.
Protected functions
- auto createWidget(QWidget* parent) -> QWidget* pure virtual
- This method should create a new widget with the provided parent.
- void initWidget(QWidget* editor) virtual
- This method should initialize the editor widget with runtime data.
Protected variables
- QgsPropertyCollection mPropertyCollection
- Data defined property collection.
Private functions
- void aboutToSave() virtual
- Called when the containing attribute form is about to save.
Enum documentation
enum QgsWidgetWrapper:: Property
Data defined properties for different editor widgets.
| Enumerators | |
|---|---|
| RootPath |
Root path for external resource. |
| DocumentViewerContent |
Document type for external resource. |
Function documentation
static QgsWidgetWrapper* QgsWidgetWrapper:: fromWidget(QWidget* widget)
Will return a wrapper for a given widget.
| Parameters | |
|---|---|
| widget | The widget which was created by a wrapper |
| Returns | The wrapper for the widget or NULL |
static const QgsPropertiesDefinition& QgsWidgetWrapper:: propertyDefinitions()
Returns the editor widget property definitions.
QgsWidgetWrapper:: QgsWidgetWrapper(QgsVectorLayer* vl,
QWidget* editor = nullptr,
QWidget* parent = nullptr) explicit
Create a new widget wrapper.
| Parameters | |
|---|---|
| vl | The layer on which the field is |
| editor | An editor widget. Can be NULL if one should be autogenerated. |
| parent | A parent widget for this widget wrapper and the created widget. |
QVariant QgsWidgetWrapper:: config(const QString& key,
const QVariant& defaultVal = QVariant()) const
Use this inside your overridden classes to access the configuration.
| Parameters | |
|---|---|
| key | The configuration option you want to load |
| defaultVal | Default value |
| Returns | the value assigned to this configuration option |
QgsPropertyCollection& QgsWidgetWrapper:: dataDefinedProperties()
Returns a reference to the editor widget's property collection, used for data defined overrides.
const QgsPropertyCollection& QgsWidgetWrapper:: dataDefinedProperties() const
Returns a reference to the editor widget's property collection, used for data defined overrides.
void QgsWidgetWrapper:: notifyAboutToSave()
Notify this widget, that the containing form is about to save and that any pending changes should be pushed to the edit buffer or they might be lost.
void QgsWidgetWrapper:: setConfig(const QVariantMap& config)
Will set the config of this wrapper to the specified config.
| Parameters | |
|---|---|
| config | The config for this wrapper |
void QgsWidgetWrapper:: setContext(const QgsAttributeEditorContext& context)
Set the context in which this widget is shown.
| Parameters | |
|---|---|
| context | context information |
void QgsWidgetWrapper:: setDataDefinedProperties(const QgsPropertyCollection& collection)
Sets the editor widget's property collection, used for data defined overrides.
| Parameters | |
|---|---|
| collection | property collection. Existing properties will be replaced. |
bool QgsWidgetWrapper:: valid() const pure virtual
Returns true if the widget has been properly initialized.
| Returns | Validity status of this widget. |
|---|
This acts as hint for the calling party if this wrapper can be used after initializing it. If it cannot be used this is a hint to the caller that he may try to find another suitable widget type instead.
template<class T>
T* QgsWidgetWrapper:: widget()
Access the widget managed by this wrapper and cast it to a given type Example: QPushButton* pb = wrapper->widget<QPushButton*>();.
| Returns | The widget as template type or NULL, if it cannot be cast to this type. |
|---|
void QgsWidgetWrapper:: contextChanged() signal
Signal when QgsAttributeEditorContext mContext changed.
void QgsWidgetWrapper:: setEnabled(bool enabled) virtual public slot
Is used to enable or disable the edit functionality of the managed widget.
| Parameters | |
|---|---|
| enabled | Enable or Disable? |
By default this will not change the enabled state of the widget
void QgsWidgetWrapper:: setFeature(const QgsFeature& feature) pure virtual public slot
Is called, when the value of the widget needs to be changed.
| Parameters | |
|---|---|
| feature | The new feature |
Update the widget representation to reflect the new value.
QWidget* QgsWidgetWrapper:: createWidget(QWidget* parent) pure virtual protected
This method should create a new widget with the provided parent.
| Parameters | |
|---|---|
| parent | You should set this parent on the created widget. |
| Returns | A new widget |
This will only be called if the form did not already provide a widget, so it is not guaranteed to be called! You should not do initialization stuff, which also has to be done for custom editor widgets inside this method. Things like filling comboboxes and assigning other data which will also be used to make widgets on forms created in the QtDesigner usable should be assigned in initWidget().
void QgsWidgetWrapper:: initWidget(QWidget* editor) virtual protected
This method should initialize the editor widget with runtime data.
| Parameters | |
|---|---|
| editor | The widget which will represent this attribute editor in a form. |
Fill your comboboxes here.
void QgsWidgetWrapper:: aboutToSave() virtual private
Called when the containing attribute form is about to save.
Use this to push any widget states to the edit buffer.