Class: QgsAbstractRelationEditorWidget

Base class to build new relation widgets.

Added in version 3.18.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAbstractRelationEditorWidget

Base classes

QWidget

QObject

QPaintDevice

Subclasses

QgsRelationEditorWidget

The default relation widget in QGIS.

Methods

addFeature

Adds new features with given geometry

afterSetRelationFeature

A hook called right after setRelationFeature() is executed, but before updateUi() is called.

afterSetRelations

A hook called right after setRelations() is executed, but before updateUi() is called.

beforeSetRelationFeature

A hook called right before setRelationFeature() is executed.

beforeSetRelations

A hook called right before setRelations() is executed.

config

Returns the widget configuration

deleteFeature

Delete a feature with given fid

deleteFeatures

Deletes the features with fids

duplicateFeature

Duplicates a feature

duplicateFeatures

Duplicates features

editorContext

Returns the attribute editor context.

feature

Returns the widget's current feature If the widget is in multiedit mode only the first is returned

features

Returns the widget's current features

forceSuppressFormPopup

Determines the force suppress form popup status that is configured for this widget

label

Determines the label of this element

linkFeature

Links a new feature to the relation

multiEditModeActive

Returns true if editing multiple features at a time

nmRelation

Returns the nm relation

nmRelationId

Determines the relation id of the second relation involved in an N:M relation.

onLinkFeatureDlgAccepted

Called when the link feature dialog is confirmed by the user

parentFormValueChanged

Called when an attribute value in the parent widget has changed to newValue

relation

Returns the relation

saveEdits

Saves the current modifications in the relation

setConfig

Defines the widget configuration

setEditorContext

Sets the editor context

setFeature

Sets the feature being edited and updates the UI unless update is set to False

setForceSuppressFormPopup

Sets force suppress form popup status with forceSuppressFormPopup configured for this widget

setLabel

Sets label for this element If it's empty it takes the relation id as label

setMultiEditFeatureIds

Set multiple feature to edit simultaneously.

setNmRelationId

Sets nmRelationId for the relation id of the second relation involved in an N:M relation.

setRelationFeature

Sets the relation and the feature

setRelations

Sets the relation(s) for this widget If only one relation is set, it will act as a simple 1:N relation widget If both relations are set, it will act as an N:M relation widget inserting and deleting entries on the intermediate table as required.

setShowLabel

Defines if a title label should be shown for this widget.

setTitle

Sets the title of the widget, if it is wrapped within a QgsCollapsibleGroupBox

showEvent

Refresh the UI when the widget becomes visible

showLabel

Defines if a title label should be shown for this widget.

toggleEditing

Toggles editing state of the widget

unlinkFeature

Unlinks a feature with given fid

unlinkFeatures

Unlinks the features with fids

updateTitle

Updates the title contents to reflect the current state of the widget

updateUi

A hook called every time the state of the relation editor widget has changed via calling its set* methods or slots, e.g. changed relation, added feature, etc.

Signals

relatedFeaturesChanged

Emit this signal, whenever the related features changed.

class qgis.gui.QgsAbstractRelationEditorWidget[source]

Bases: QWidget

__init__(config: Dict[str, Any], parent: QWidget | None = None)

Constructor

Parameters:
  • config (Dict[str, Any])

  • parent (Optional[QWidget] = None)

addFeature(self, geometry: QgsGeometry = QgsGeometry()) Any[source]

Adds new features with given geometry

Added in version 3.24.

Parameters:

geometry (QgsGeometry = QgsGeometry())

Return type:

Any

afterSetRelationFeature(self)[source]

A hook called right after setRelationFeature() is executed, but before updateUi() is called. Used to update the UI once setting the relation feature is done. Check QgsRealationEditorWidget as an example.

afterSetRelations(self)[source]

A hook called right after setRelations() is executed, but before updateUi() is called. Used to update the UI once setting the relations is done. Check QgsRealationEditorWidget as an example.

beforeSetRelationFeature(self, newRelation: QgsRelation, newFeature: QgsFeature)[source]

A hook called right before setRelationFeature() is executed. Used to update the UI once setting the relation feature is done. Check QgsRealationEditorWidget as an example.

Parameters:
beforeSetRelations(self, newRelation: QgsRelation, newNmRelation: QgsRelation)[source]

A hook called right before setRelations() is executed. Used to manipulate UI once setting the relations is done. Check QgsRealationEditorWidget as an example.

Parameters:
config(self) Dict[str, Any][source]

Returns the widget configuration

Return type:

Dict[str, Any]

deleteFeature(self, fid: int = int())[source]

Delete a feature with given fid

Parameters:

fid (int = int())

deleteFeatures(self, fids: Any)[source]

Deletes the features with fids

Parameters:

fids (Any)

duplicateFeature(self, fid: int)[source]

Duplicates a feature

Parameters:

fid (int)

duplicateFeatures(self, fids: Any)[source]

Duplicates features

Parameters:

fids (Any)

editorContext(self) QgsAttributeEditorContext[source]

Returns the attribute editor context.

Return type:

QgsAttributeEditorContext

feature(self) QgsFeature[source]

Returns the widget’s current feature If the widget is in multiedit mode only the first is returned

See also

features()

Return type:

QgsFeature

features(self) List[QgsFeature]

Returns the widget’s current features

Added in version 3.24.

Return type:

List[QgsFeature]

forceSuppressFormPopup(self) bool[source]

Determines the force suppress form popup status that is configured for this widget

Return type:

bool

label(self) str[source]

Determines the label of this element

Deprecated since version 3.20: Label is handled directly in QgsAttributeForm.

Return type:

str

linkFeature(self, filterExpression: str | None = '')[source]

Links a new feature to the relation

Parameters:

filterExpression (Optional[str] = '') – to filter the available features in the link dialog since QGIS 3.40

multiEditModeActive(self) bool[source]

Returns true if editing multiple features at a time

Added in version 3.24.

Return type:

bool

nmRelation(self) QgsRelation[source]

Returns the nm relation

Added in version 3.18.

Return type:

QgsRelation

nmRelationId(self) Any[source]

Determines the relation id of the second relation involved in an N:M relation.

Return type:

Any

onLinkFeatureDlgAccepted(self)[source]

Called when the link feature dialog is confirmed by the user

parentFormValueChanged(self, attribute: str | None, newValue: Any)[source]

Called when an attribute value in the parent widget has changed to newValue

Parameters:
  • attribute (Optional[str])

  • newValue (Any)

signal relatedFeaturesChanged[source]

Emit this signal, whenever the related features changed. This happens for example when related features are added, removed, linked or unlinked.

Added in version 3.22.

relation(self) QgsRelation[source]

Returns the relation

Added in version 3.18.

Return type:

QgsRelation

saveEdits(self)[source]

Saves the current modifications in the relation

setConfig(self, config: Dict[str, Any])[source]

Defines the widget configuration

Parameters:

config (Dict[str, Any])

setEditorContext(self, context: QgsAttributeEditorContext)[source]

Sets the editor context

Note

if context cadDockWidget is null, it won’t be possible to digitize the geometry of a referencing feature from this widget

Parameters:

context (QgsAttributeEditorContext)

setFeature(self, feature: QgsFeature, update: bool = True)[source]

Sets the feature being edited and updates the UI unless update is set to False

Parameters:
setForceSuppressFormPopup(self, forceSuppressFormPopup: bool)[source]

Sets force suppress form popup status with forceSuppressFormPopup configured for this widget

Parameters:

forceSuppressFormPopup (bool)

setLabel(self, label: str | None = '')[source]

Sets label for this element If it’s empty it takes the relation id as label

Parameters:

label (Optional[str] = '')

setMultiEditFeatureIds(self, fids: Any)[source]

Set multiple feature to edit simultaneously.

Parameters:

fids (Any) – Multiple Id of features to edit

Added in version 3.24.

setNmRelationId(self, nmRelationId: Any = None)[source]

Sets nmRelationId for the relation id of the second relation involved in an N:M relation. If it’s empty, then it’s considered as a 1:M relationship.

Parameters:

nmRelationId (Any = None)

setRelationFeature(self, relation: QgsRelation, feature: QgsFeature)[source]

Sets the relation and the feature

Parameters:
setRelations(self, relation: QgsRelation, nmrelation: QgsRelation)[source]

Sets the relation(s) for this widget If only one relation is set, it will act as a simple 1:N relation widget If both relations are set, it will act as an N:M relation widget inserting and deleting entries on the intermediate table as required.

Parameters:
  • relation (QgsRelation) – Relation referencing the edited table

  • nmrelation (QgsRelation) – Optional reference from the referencing table to a 3rd N:M table

setShowLabel(self, showLabel: bool)[source]

Defines if a title label should be shown for this widget.

Deprecated since version 3.20: Label is handled directly in QgsAttributeForm.

Parameters:

showLabel (bool)

setTitle(self, title: str | None)[source]

Sets the title of the widget, if it is wrapped within a QgsCollapsibleGroupBox

Deprecated since version 3.20: Label is handled directly in QgsAttributeForm.

Parameters:

title (Optional[str])

showEvent(self, a0: QShowEvent | None)[source]

Refresh the UI when the widget becomes visible

Parameters:

a0 (Optional[QShowEvent])

showLabel(self) bool[source]

Defines if a title label should be shown for this widget.

Deprecated since version 3.20: Label is handled directly in QgsAttributeForm.

Return type:

bool

toggleEditing(self, state: bool)[source]

Toggles editing state of the widget

Parameters:

state (bool)

unlinkFeature(self, fid: int = int())[source]

Unlinks a feature with given fid

Parameters:

fid (int = int())

unlinkFeatures(self, fids: Any)[source]

Unlinks the features with fids

Parameters:

fids (Any)

updateTitle(self)[source]

Updates the title contents to reflect the current state of the widget

Deprecated since version 3.20: Label is handled directly in QgsAttributeForm.

updateUi(self)[source]

A hook called every time the state of the relation editor widget has changed via calling its set* methods or slots, e.g. changed relation, added feature, etc. Should be used to refresh the UI regarding the new data. Check QgsRealationEditorWidget as an example.