Class: QgsDualView

This widget is used to show the attributes of a set of features of a QgsVectorLayer. The attributes can be edited. It supports two different layouts: the table layout, in which the attributes for the features are shown in a table and the editor layout, where the features are shown as a selectable list and the attributes for the currently selected feature are shown in a form.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsDualView

Base classes

QStackedWidget

QFrame

QWidget

QObject

QPaintDevice

Methods

attributeTableConfig

The config used for the attribute table.

cancelProgress

Cancel the progress dialog (if any)

copyCellContent

Copy the content of the selected cell in the clipboard.

featureCount

Returns the number of features on the layer.

filterFeatures

Sets the expression and Updates the filtered features in the filter model.

filterMode

Gets the filter mode

filteredFeatureCount

Returns the number of features which are currently visible, according to the filter restrictions

filteredFeatures

Gets a list of currently visible feature ids.

init

Has to be called to initialize the dual view.

masterModel

Returns the model which has the information about all features (not only filtered)

openConditionalStyles

parentFormValueChanged

Called in embedded forms when an attribute value in the parent form has changed.

saveEditChanges

saveEditChanges

setAttributeTableConfig

Set the attribute table config which should be used to control the appearance of the attribute table.

setCurrentEditSelection

Set the current edit selection in the AttributeEditor mode.

setFeatureSelectionManager

Set the feature selection model

setFilterMode

Set the filter mode

setFilteredFeatures

Set a list of currently visible features

setMultiEditEnabled

Sets whether multi edit mode is enabled.

setRequest

Set the request

setSelectedOnTop

Toggle the selectedOnTop flag.

setSortExpression

Set the expression used for sorting the table and feature list.

setView

Change the current view mode.

sortExpression

Gets the expression used for sorting the table and feature list.

tableView

Returns the table view

toggleSearchMode

Toggles whether search mode should be enabled in the form.

view

Returns the current view mode.

Static Methods

requiredAttributes

Returns the list of required attributes according to the attribute table configuration of the layer, only visible attributes and virtual fields referenced fields are returned.

Signals

displayExpressionChanged

Emitted whenever the display expression is successfully changed

filterChanged

Emitted whenever the filter changes

filterExpressionSet

Emitted when a filter expression is set using the view.

formModeChanged

Emitted when the form changes mode.

showContextMenuExternally

Emitted when selecting context menu on the feature list to create the context menu individually

Attributes

AttributeEditor

AttributeTable

NoAction

PanToFeature

ZoomToFeature

class qgis.gui.QgsDualView[source]

Bases: QStackedWidget

__init__(parent: QWidget | None = None)

Constructor

Parameters:

parent (Optional[QWidget] = None) – The parent widget

AttributeEditor = 1
AttributeTable = 0
class FeatureListBrowsingAction

Bases: int

NoAction = 0
PanToFeature = 1
class ViewMode

Bases: int

ZoomToFeature = 2
attributeTableConfig(self) QgsAttributeTableConfig[source]

The config used for the attribute table.

Return type:

QgsAttributeTableConfig

Returns:

The config used for the attribute table.

cancelProgress(self)[source]

Cancel the progress dialog (if any)

copyCellContent(self)[source]

Copy the content of the selected cell in the clipboard.

signal displayExpressionChanged(expression: str)[source]

Emitted whenever the display expression is successfully changed

Parameters:

expression (str) – The expression that was applied

featureCount(self) int[source]

Returns the number of features on the layer.

Return type:

int

Returns:

Number of features

signal filterChanged[source]

Emitted whenever the filter changes

signal filterExpressionSet(expression: str, type: QgsAttributeForm.FilterType)[source]

Emitted when a filter expression is set using the view.

Parameters:
filterFeatures(self, filterExpression: QgsExpression, context: QgsExpressionContext)[source]

Sets the expression and Updates the filtered features in the filter model. It is called when the filter expression changed.

Added in version 3.10.3.

Parameters:
filterMode(self) QgsAttributeTableFilterModel.FilterMode[source]

Gets the filter mode

Return type:

QgsAttributeTableFilterModel.FilterMode

Returns:

the filter mode

filteredFeatureCount(self) int[source]

Returns the number of features which are currently visible, according to the filter restrictions

Return type:

int

Returns:

Number of features

filteredFeatures(self) Any[source]

Gets a list of currently visible feature ids.

Return type:

Any

signal formModeChanged(mode: QgsAttributeEditorContext.Mode)[source]

Emitted when the form changes mode.

Parameters:

mode (QgsAttributeEditorContext.Mode) – new mode

init(self, layer: QgsVectorLayer | None, mapCanvas: QgsMapCanvas | None, request: QgsFeatureRequest = QgsFeatureRequest(), context: QgsAttributeEditorContext = QgsAttributeEditorContext(), loadFeatures: bool = True, showFirstFeature: bool = True)[source]

Has to be called to initialize the dual view.

Parameters:
  • layer (Optional[QgsVectorLayer]) – The layer which should be used to fetch features

  • mapCanvas (Optional[QgsMapCanvas]) – The mapCanvas (used for the FilterMode QgsAttributeTableFilterModel.ShowVisible)

  • request (QgsFeatureRequest = QgsFeatureRequest()) – Use a modified request to limit the shown features

  • context (QgsAttributeEditorContext = QgsAttributeEditorContext()) – The context in which this view is shown

  • loadFeatures (bool = True) – whether to initially load all features into the view. If set to False, limited features can later be loaded using setFilterMode()

  • showFirstFeature (bool = True) – whether to initially show the first feature form upon initializing the dual view

masterModel(self) QgsAttributeTableModel | None[source]

Returns the model which has the information about all features (not only filtered)

Return type:

Optional[QgsAttributeTableModel]

Returns:

The master model

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

Called in embedded forms when an attribute value in the parent form has changed.

Notify the form widgets that something has changed in case they have filter expression that depend on the parent form scope.

Added in version 3.14.

Parameters:
  • attribute (Optional[str])

  • value (Any)

static requiredAttributes(layer: QgsVectorLayer | None) List[int][source]

Returns the list of required attributes according to the attribute table configuration of the layer, only visible attributes and virtual fields referenced fields are returned.

Added in version 3.32.

Parameters:

layer (Optional[QgsVectorLayer])

Return type:

List[int]

saveEditChanges(self) bool[source]
saveEditChanges(None) None
Return type:

bool

Returns:

True if the saving was OK. False is possible due to connected validation logic.

setAttributeTableConfig(self, config: QgsAttributeTableConfig)[source]

Set the attribute table config which should be used to control the appearance of the attribute table.

Parameters:

config (QgsAttributeTableConfig)

setCurrentEditSelection(self, fids: Any)[source]

Set the current edit selection in the AttributeEditor mode.

Parameters:

fids (Any) – A list of edited features (Currently only one at a time is supported)

setFeatureSelectionManager(self, featureSelectionManager: QgsIFeatureSelectionManager | None)[source]

Set the feature selection model

Parameters:

featureSelectionManager (Optional[QgsIFeatureSelectionManager]) – the feature selection model

setFilterMode(self, filterMode: QgsAttributeTableFilterModel.FilterMode)[source]

Set the filter mode

Parameters:

filterMode (QgsAttributeTableFilterModel.FilterMode)

setFilteredFeatures(self, filteredFeatures: Any)[source]

Set a list of currently visible features

Parameters:

filteredFeatures (Any) – A list of feature ids

Deprecated since version 3.40: Since filterFeatures is handled in the attribute filter model itself.

setMultiEditEnabled(self, enabled: bool)[source]

Sets whether multi edit mode is enabled.

Parameters:

enabled (bool)

setRequest(self, request: QgsFeatureRequest)[source]

Set the request

Parameters:

request (QgsFeatureRequest) – The request

setSelectedOnTop(self, selectedOnTop: bool)[source]

Toggle the selectedOnTop flag. If enabled, selected features will be moved to top.

Parameters:

selectedOnTop (bool) – True: Show selected features on top. False: Use defined sorting column.

setSortExpression(self, sortExpression: str | None, sortOrder: Qt.SortOrder = Qt.AscendingOrder)[source]

Set the expression used for sorting the table and feature list.

Parameters:
  • sortExpression (Optional[str])

  • sortOrder (Qt.SortOrder = Qt.AscendingOrder)

setView(self, view: QgsDualView.ViewMode)[source]

Change the current view mode.

Parameters:

view (QgsDualView.ViewMode) – The view mode to set

See also

view()

signal showContextMenuExternally(menu: QgsActionMenu, fid: QgsFeatureId)[source]

Emitted when selecting context menu on the feature list to create the context menu individually

Parameters:
  • menu (QgsActionMenu) – context menu

  • fid (QgsFeatureId) – feature id of the selected feature

sortExpression(self) str[source]

Gets the expression used for sorting the table and feature list.

Return type:

str

tableView(self) QgsAttributeTableView | None[source]

Returns the table view

Return type:

Optional[QgsAttributeTableView]

Returns:

The table view

toggleSearchMode(self, enabled: bool)[source]

Toggles whether search mode should be enabled in the form.

Parameters:

enabled (bool) – set to True to switch on search mode

view(self) QgsDualView.ViewMode[source]

Returns the current view mode.

See also

setView()

Return type:

QgsDualView.ViewMode