Class: QgsEditorWidgetWrapper¶
-
class
qgis.gui.
QgsEditorWidgetWrapper
(vl: QgsVectorLayer, fieldIdx: int, editor: QWidget = None, parent: QWidget = None)¶ Bases:
qgis._gui.QgsWidgetWrapper
Create a new widget wrapper
- Parameters
vl – The layer on which the field is
fieldIdx – The field which will be controlled
editor – An editor widget. Can be NULL if one should be autogenerated.
parent – A parent widget for this widget wrapper and the created widget.
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.
Enums
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 value() method to determine the emitted value
Access the field.
Access the field index.
The feature currently being edited, in its current state
Will return a wrapper for a given widget
Returns true if the widget is preventing the feature from being committed.
Check if the given widget or one of its parent is a QTableView.
Gets the current constraint status.
Sets whether the constraint result is visible.
Is used to enable or disable the edit functionality of the managed widget.
Will be called when the feature changes
Set the feature currently being edited to
feature
Update the feature currently being edited by changing its attribute
attributeName
toattributeValue
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.
Update constraint.
This should update the widget with a visual cue if a constraint status changed.
Will be used to access the widget’s value.
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.
Attributes
-
class
ConstraintResult
¶ Bases:
int
-
ConstraintResultFailHard
= 1¶
-
ConstraintResultFailSoft
= 2¶
-
ConstraintResultPass
= 0¶
-
childEvent
()¶
-
connectNotify
()¶
-
constraintFailureReason
(self) → str¶ Returns the reason why a constraint check has failed (or an empty string if constraint check was successful).
See also
New in version 3.0.
-
constraintResult
(self) → QgsEditorWidgetWrapper.ConstraintResult¶ Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization.
New in version 3.0.
-
constraintResultVisible
(self) → bool¶ 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.
New in version 3.0.
-
constraintResultVisibleChanged
¶ Emit this signal when the constraint result visibility changed. [signal]
-
constraintStatusChanged
¶ Emit this signal when the constraint status changed. constraintStatusChanged
- Parameters
constraint – represented as a string
desc – is the constraint description
err – the error represented as a string. Empty if none.
status – [signal]
-
createWidget
()¶
-
customEvent
()¶
-
defaultValue
(self) → Any¶ Access the default value of the field.
- Returns
the default value of the field
See also
layer()
-
disconnectNotify
()¶
-
emitValueChanged
(self)¶ Will call the value() method to determine the emitted value
-
field
(self) → QgsField¶ Access the field.
- Returns
The field you are working on
See also
layer()
-
fieldIdx
(self) → int¶ Access the field index.
- Returns
The index of the field you are working on
See also
layer()
-
formFeature
(self) → QgsFeature¶ The feature currently being edited, in its current state
- Returns
the feature currently being edited, in its current state
New in version 3.2.
-
fromWidget
(widget: QWidget) → QgsEditorWidgetWrapper¶ 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
-
initWidget
()¶
-
isBlockingCommit
(self) → bool¶ Returns true if the widget is preventing the feature from being committed. This may be true as a result of attribute values failing enforced field constraints.
See also
New in version 3.0.
-
isInTable
(parent: QWidget) → bool¶ Check if the given widget or one of its parent is a QTableView.
- Parameters
parent – the widget to check
- Returns
true if yes
-
isSignalConnected
()¶
-
isValidConstraint
(self) → bool¶ Gets the current constraint status.
- Returns
true if the constraint is valid or if there’s no constraint, false otherwise
See also
See also
New in version 2.16.
-
receivers
()¶
-
sender
()¶
-
senderSignalIndex
()¶
-
setConstraintResultVisible
(self, constraintResultVisible: bool)¶ 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 – if constraintResult should be displayed (mostly editable status)
New in version 3.0.
-
setEnabled
(self, enabled: bool)¶ 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 – Enable or Disable?
-
setFeature
(self, feature: QgsFeature)¶ Will be called when the feature changes
Is forwarded to the slot setValue()
- Parameters
feature – The new feature
-
setFormFeature
(self, feature: QgsFeature)¶ Set the feature currently being edited to
feature
New in version 3.2.
-
setFormFeatureAttribute
(self, attributeName: str, attributeValue: Any) → bool¶ Update the feature currently being edited by changing its attribute
attributeName
toattributeValue
- Returns
bool true on success
New in version 3.2.
-
setHint
(self, hintText: str)¶ Add a hint text on the widget
- Parameters
hintText – The hint text to display
New in version 3.0.
-
setValue
(self, value: Any)¶ Is called, when the value of the widget needs to be changed. Update the widget representation to reflect the new value.
- Parameters
value – The new value of the attribute
-
showIndeterminateState
(self)¶ Sets the widget to display in an indeterminate “mixed value” state.
New in version 2.16.
-
timerEvent
()¶
-
updateConstraint
(self, featureContext: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet)¶ Update constraint.
- Parameters
featureContext – the feature to use to evaluate the constraint
constraintOrigin – optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
New in version 2.16.
updateConstraint(self, layer: QgsVectorLayer, index: int, feature: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet) Update constraint on a feature coming from a specific layer.
- Parameters
layer – The vector layer where the feature is defined
index – The index of the field to check
feature – The feature to use to evaluate the constraint
constraintOrigin – Optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
New in version 3.0.
-
updateConstraintWidgetStatus
(self)¶ 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.
New in version 2.16.
-
value
(self) → Any¶ 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.
- Returns
The current value the widget represents
-
valueChanged
¶ Emit this signal, whenever the value changed.
- Parameters
value – The new value [signal]