Class: QgsEditorWidgetWrapper¶
Manages an editor widget.
Widget and wrapper share the same parent
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.
It can also handle additional fields of a vector layer and would set the widget for their corresponding values and emit valuesChanged signal.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: QgsWidgetWrapper.createWidget()
, QgsWidgetWrapper.valid()
, value()
Class Hierarchy¶
Base classes¶
Manages an editor widget. |
|
Subclasses¶
Wraps a relation reference widget. |
Abstract Methods
Will be used to access the widget's value. |
Methods
Returns the reason why a constraint check has failed (or an empty string if constraint check was successful). |
|
Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization. |
|
Returns whether the constraint result is visible. |
|
Access the default value of the field. |
|
Will call the |
|
Access the field. |
|
Access the field index. |
|
The feature currently being edited, in its current state |
|
Returns |
|
Gets the current constraint status. |
|
Sets whether the constraint result is visible. |
|
Set the feature currently being edited to feature |
|
Update the feature currently being edited by changing its attribute attributeName to attributeValue |
|
Is called when the value of the widget or additional field values needs to be changed. |
|
Update constraint. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsEditorWidgetWrapper. See the FAQ for more details.
Will be used to access the widget's values for potential additional fields handled by the widget |
|
Returns the list of additional fields which the editor handles |
|
Is called in embedded form widgets when an attribute value in the parent form has changed. |
|
Is used to enable or disable the edit functionality of the managed widget. |
|
Will be called when the feature changes |
|
Add a hint text on the widget |
|
Is called when the value of the widget needs to be changed. |
|
Sets the widget to display in an indeterminate "mixed value" state. |
|
This should update the widget with a visual cue if a constraint status changed. |
Static Methods
Will return a wrapper for a given widget |
|
Check if the given widget or one of its parent is a QTableView. |
Signals
Emit this signal when the constraint result visibility changed. |
|
Emit this signal when the constraint status changed. |
|
Emit this signal, whenever the value changed. |
|
Emit this signal, whenever the value changed. |
Attributes
- class qgis.gui.QgsEditorWidgetWrapper[source]¶
Bases:
QgsWidgetWrapper
- __init__(vl: QgsVectorLayer | None, fieldIdx: int, editor: QWidget | None = None, parent: QWidget | None = None)
Create a new widget wrapper
- Parameters:
vl (Optional[QgsVectorLayer]) – The layer on which the field is
fieldIdx (int) – The field which will be controlled
editor (Optional[QWidget] = None) – An editor widget. Can be
None
if one should be autogenerated.parent (Optional[QWidget] = None) – A parent widget for this widget wrapper and the created widget.
- class ConstraintResult¶
Bases:
int
- ConstraintResultFailHard = 1¶
- ConstraintResultFailSoft = 2¶
- ConstraintResultPass = 0¶
- virtual additionalFieldValues(self) List[Any] [source]¶
Will be used to access the widget’s values for potential additional fields handled by the widget
- Return type:
List[Any]
- Returns:
A map of additional field names with their corresponding values
See also
Added in version 3.10.
- virtual additionalFields(self) List[str] [source]¶
Returns the list of additional fields which the editor handles
Added in version 3.10.
- Return type:
List[str]
- constraintFailureReason(self) str [source]¶
Returns the reason why a constraint check has failed (or an empty string if constraint check was successful).
See also
- Return type:
str
- constraintResult(self) QgsEditorWidgetWrapper.ConstraintResult [source]¶
Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization.
- Return type:
- constraintResultVisible(self) bool [source]¶
Returns whether the constraint result is visible.
Returns
True
if the constraint result will be visualized on the widget (with color). This will be disabled when the form is not editable.- Return type:
bool
- signal constraintResultVisibleChanged(visible: bool)[source]¶
Emit this signal when the constraint result visibility changed.
- Parameters:
visible (bool)
- signal constraintStatusChanged(constraint: str, desc: str, err: str, status: QgsEditorWidgetWrapper.ConstraintResult)[source]¶
Emit this signal when the constraint status changed. constraintStatusChanged
- Parameters:
constraint (str) – represented as a string
desc (str) – is the constraint description
err (str) – the error represented as a string. Empty if none.
- defaultValue(self) Any [source]¶
Access the default value of the field.
- Return type:
Any
- Returns:
the default value of the field
See also
layer()
- field(self) QgsField [source]¶
Access the field.
- Return type:
- Returns:
The field you are working on
See also
layer()
- fieldIdx(self) int [source]¶
Access the field index.
- Return type:
int
- Returns:
The index of the field you are working on
See also
layer()
- formFeature(self) QgsFeature [source]¶
The feature currently being edited, in its current state
- Return type:
- Returns:
the feature currently being edited, in its current state
Added in version 3.2.
- static fromWidget(widget: QWidget | None) QgsEditorWidgetWrapper | None [source]¶
Will return a wrapper for a given widget
- Parameters:
widget (Optional[QWidget]) – The widget which was created by a wrapper
- Return type:
Optional[QgsEditorWidgetWrapper]
- Returns:
The wrapper for the widget or
None
- isBlockingCommit(self) bool [source]¶
Returns
True
if the widget is preventing the feature from being committed. This may beTrue
as a result of attribute values failing enforced field constraints.See also
- Return type:
bool
- static isInTable(parent: QWidget | None) bool [source]¶
Check if the given widget or one of its parent is a QTableView.
- Parameters:
parent (Optional[QWidget]) – the widget to check
- Return type:
bool
- Returns:
True
if yes
- isValidConstraint(self) bool [source]¶
Gets the current constraint status.
- Return type:
bool
- Returns:
True
if the constraint is valid or if there’s no constraint,False
otherwise
See also
See also
- virtual parentFormValueChanged(self, attribute: str | None, value: Any)[source]¶
Is called in embedded form widgets when an
attribute
value
in the parent form has changed.The default implementations does nothing. Subclasses should reimplement this method to notify the form widgets that something has changed in case they have filter expressions that depend on the parent form scope.
Added in version 3.14.
- Parameters:
attribute (Optional[str])
value (Any)
- setConstraintResultVisible(self, constraintResultVisible: bool)[source]¶
Sets whether the constraint result is visible.
Controls if the constraint result should be visualized on the widget (with color). This will be disabled when the form is not editable.
- Parameters:
constraintResultVisible (bool) – if constraintResult should be displayed (mostly editable status)
- virtual setEnabled(self, enabled: bool)[source]¶
Is used to enable or disable the edit functionality of the managed widget. By default this will enable or disable the whole widget
- Parameters:
enabled (bool) – Enable or Disable?
- virtual setFeature(self, feature: QgsFeature)[source]¶
Will be called when the feature changes
Is forwarded to the slot
setValues()
- Parameters:
feature (QgsFeature) – The new feature
- setFormFeature(self, feature: QgsFeature)[source]¶
Set the feature currently being edited to
feature
Added in version 3.2.
- Parameters:
feature (QgsFeature)
- setFormFeatureAttribute(self, attributeName: str | None, attributeValue: Any) bool [source]¶
Update the feature currently being edited by changing its attribute
attributeName
toattributeValue
- Return type:
bool
- Returns:
bool
True
on success
Added in version 3.2.
- Parameters:
attributeName (Optional[str])
attributeValue (Any)
- virtual setHint(self, hintText: str | None)[source]¶
Add a hint text on the widget
- Parameters:
hintText (Optional[str]) – The hint text to display
- virtual setValue(self, value: Any)[source]¶
Is called when the value of the widget needs to be changed. Updates the widget representation to reflect the new value.
- Parameters:
value (Any) – The new value of the attribute
Deprecated since version 3.10.
- setValues(self, value: Any, additionalValues: Iterable[Any])[source]¶
Is called when the value of the widget or additional field values needs to be changed. Updates the widget representation to reflect the new values.
Added in version 3.10.
- Parameters:
value (Any)
additionalValues (Iterable[Any])
- virtual showIndeterminateState(self)[source]¶
Sets the widget to display in an indeterminate “mixed value” state.
- updateConstraint(self, featureContext: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet)[source]¶
Update constraint.
- Parameters:
featureContext (
QgsFeature
) – the feature to use to evaluate the constraintconstraintOrigin (QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet) – optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
- updateConstraint(self, layer: QgsVectorLayer | None, index: int, feature: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet)[source]
Update constraint on a feature coming from a specific layer.
- Parameters:
layer (Optional[QgsVectorLayer]) – The vector layer where the feature is defined
index (int) – The index of the field to check
feature (
QgsFeature
) – The feature to use to evaluate the constraintconstraintOrigin (QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet) – Optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
- updateConstraint(self, constraintResult: QgsEditorWidgetWrapper.ConstraintResult, constraintFailureReason: str | None)[source]
Update constraint manually by providing the constraint result value and failure reason(s).
- Parameters:
constraintResult (QgsEditorWidgetWrapper.ConstraintResult) – the constraint result value
constraintFailureReason (Optional[str]) – the constraint failure reason(s) (blank is the result passes)
Added in version 3.36.
- virtual updateConstraintWidgetStatus(self)[source]¶
This should update the widget with a visual cue if a constraint status changed.
By default a stylesheet will be applied on the widget that changes the background color to red.
This can be overwritten in subclasses to allow individual widgets to change the visual cue.
- abstract value(self) Any [source]¶
Will be used to access the widget’s value. Read the value from the widget and return it properly formatted to be saved in the attribute.
If an invalid variant is returned this will be interpreted as no change. Be sure to return a NULL QVariant if it should be set to NULL.
- Return type:
Any
- Returns:
The current value the widget represents
- signal valueChanged(value: object)[source]¶
Emit this signal, whenever the value changed.
- Parameters:
value (object) – The new value
Deprecated since version 3.10: Use valuesChanged signal instead.
- signal valuesChanged(value: object, additionalFieldValues: List[object] = [])[source]¶
Emit this signal, whenever the value changed. It will also return the values for the additional fields handled by the widget
- Parameters:
value (object) – The new value
additionalFieldValues (List[object] = []) – A map of additional field names with their corresponding values
Added in version 3.10.