Class: QgsAttributeTableFilterModel

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAttributeTableFilterModel

Base classes

QSortFilterProxyModel

QAbstractProxyModel

QAbstractItemModel

QObject

QgsFeatureModel

Enums

CustomRole

The additional roles defined by this filter model.

Role

alias of CustomRole

Methods

actionColumnIndex

Gets the index of the first column that contains an action widget.

connectFilterModeConnections

Disconnect the connections set for the new filterMode

disconnectFilterModeConnections

Disconnect the connections set for the current filterMode

extentsChanged

Is called upon every change of the visible extents on the map canvas.

fidToIndexList

filterAcceptsRow

Returns True if the source row will be accepted

filterExpression

Returns the stored filter expression string.

filterFeatures

Updates the filtered features in the filter model.

filterMode

The current filterModel

filteredFeatures

Gets a list of currently filtered feature ids

generateListOfVisibleFeatures

Updates the list of currently visible features on the map canvas.

layer

Returns the layer this filter acts on.

layerCache

Returns the layerCache this filter acts on.

lessThan

Used by the sorting algorithm.

mapCanvas

Returns the map canvas

mapFromMaster

mapToMaster

masterModel

Returns the table model this filter is using

rowToId

Returns the feature id for a given model index.

selectedOnTop

Returns if selected features are currently shown on top

setAttributeTableConfig

Set the attribute table configuration to control which fields are shown, in which order they are shown as well as if and where an action column is shown.

setFilterExpression

Set the expression and the context to be stored in case of the features need to be filtered again (like on filter or on main model data change).

setFilterMode

Set the filter mode the filter will use.

setFilteredFeatures

Specify a list of features, which the filter will accept.

setSelectedOnTop

Changes the sort order of the features.

setSourceModel

Set the attribute table model that backs this model

sort

Sort by the given column using the given order.

sortExpression

The expression which is used to sort the attribute table.

Signals

featuresFiltered

Emitted when the filtering of the features has been done

filterError

Emitted when an error occurred while filtering features

sortColumnChanged

Emitted whenever the sort column is changed

visibleReloaded

Emitted when the the visible features on extend are reloaded (the list is created)

Attributes

ColumnTypeActionButton

ColumnTypeField

ShowAll

ShowEdited

ShowFilteredList

ShowInvalid

ShowSelected

ShowVisible

class qgis.gui.QgsAttributeTableFilterModel(canvas: QgsMapCanvas | None, sourceModel: QgsAttributeTableModel | None, parent: QObject | None = None)[source]

Bases: QSortFilterProxyModel, QgsFeatureModel

class ColumnType

Bases: int

ColumnTypeActionButton = 1
ColumnTypeField = 0
class CustomRole(*values)

Bases: IntEnum

The additional roles defined by this filter model. The values of these roles start just after the roles defined by QgsAttributeTableModel so they do not conflict.

Note

Prior to QGIS 3.36 this was available as QgsAttributeTableFilterModel.Role

Added in version 3.36.

  • Type:

    Available as QgsAttributeTableFilterModel.TypeRole in older QGIS releases.

class FilterMode

Bases: int

Role

alias of CustomRole

ShowAll = 0
ShowEdited = 4
ShowFilteredList = 3
ShowInvalid = 5
ShowSelected = 1
ShowVisible = 2
actionColumnIndex(self) int[source]

Gets the index of the first column that contains an action widget. Returns -1 if none is defined.

Return type:

int

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

Disconnect the connections set for the new filterMode

Parameters:

filterMode (QgsAttributeTableFilterModel.FilterMode)

disconnectFilterModeConnections(self)[source]

Disconnect the connections set for the current filterMode

extentsChanged(self)[source]

Is called upon every change of the visible extents on the map canvas. When a change is signalled, the filter is updated and invalidated if needed.

Deprecated since version 3.10.3: Made private as reloadVisible().

signal featuresFiltered[source]

Emitted when the filtering of the features has been done

fidToIndexList(self, fid: int) List[QModelIndex][source]
Parameters:

fid (int)

Return type:

List[QModelIndex]

filterAcceptsRow(self, sourceRow: int, sourceParent: QModelIndex) bool[source]

Returns True if the source row will be accepted

Parameters:
  • sourceRow (int) – row from the source model

  • sourceParent (QModelIndex) – parent index in the source model

Return type:

bool

signal filterError(errorMessage: str)[source]

Emitted when an error occurred while filtering features

Added in version 3.18.

Parameters:

errorMessage (str)

filterExpression(self) str[source]

Returns the stored filter expression string.

Added in version 3.28.0.

Return type:

str

filterFeatures(self)[source]

Updates the filtered features in the filter model. It is called when the data of the main table or the filter expression changed.

Added in version 3.10.3.

filterMode(self) QgsAttributeTableFilterModel.FilterMode[source]

The current filterModel

Return type:

QgsAttributeTableFilterModel.FilterMode

filteredFeatures(self) Any[source]

Gets a list of currently filtered feature ids

Return type:

Any

Returns:

A list of feature ids

generateListOfVisibleFeatures(self)[source]

Updates the list of currently visible features on the map canvas. Is called automatically when the filter mode is adjusted or the extents changed.

layer(self) QgsVectorLayer | None[source]

Returns the layer this filter acts on.

Return type:

Optional[QgsVectorLayer]

Returns:

Abovementioned layer

layerCache(self) QgsVectorLayerCache | None[source]

Returns the layerCache this filter acts on.

Return type:

Optional[QgsVectorLayerCache]

Returns:

The layer cache

lessThan(self, left: QModelIndex, right: QModelIndex) bool[source]

Used by the sorting algorithm. Compares the two model indices. Will also consider the selection state of the feature in case selected features are to be shown on top.

Parameters:
  • left (QModelIndex)

  • right (QModelIndex)

Return type:

bool

mapCanvas(self) QgsMapCanvas | None[source]

Returns the map canvas

Return type:

Optional[QgsMapCanvas]

mapFromMaster(self, sourceIndex: QModelIndex) QModelIndex[source]
Parameters:

sourceIndex (QModelIndex)

Return type:

QModelIndex

mapToMaster(self, proxyIndex: QModelIndex) QModelIndex[source]
Parameters:

proxyIndex (QModelIndex)

Return type:

QModelIndex

masterModel(self) QgsAttributeTableModel | None[source]

Returns the table model this filter is using

Return type:

Optional[QgsAttributeTableModel]

Returns:

the table model in quesion

rowToId(self, row: QModelIndex) int[source]

Returns the feature id for a given model index.

Parameters:

row (QModelIndex) – A model index of the row in question

Return type:

int

Returns:

The feature id of the feature visible in the provided row

selectedOnTop(self) bool[source]

Returns if selected features are currently shown on top

Return type:

bool

Returns:

True if selected are shown on top

setAttributeTableConfig(self, config: QgsAttributeTableConfig)[source]

Set the attribute table configuration to control which fields are shown, in which order they are shown as well as if and where an action column is shown.

Parameters:

config (QgsAttributeTableConfig) – attribute table config

setFilterExpression(self, expression: QgsExpression, context: QgsExpressionContext)[source]

Set the expression and the context to be stored in case of the features need to be filtered again (like on filter or on main model data change).

Added in version 3.10.3.

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

Set the filter mode the filter will use.

Parameters:

filterMode (QgsAttributeTableFilterModel.FilterMode) – Sets the current mode of the filter

setFilteredFeatures(self, ids: Any)[source]

Specify a list of features, which the filter will accept. The filter mode will automatically be adjusted to show only these features (ShowFilteredList).

Parameters:

ids (Any) – The list of feature ids which will be accepted by the filter

setSelectedOnTop(self, selectedOnTop: bool)[source]

Changes the sort order of the features. If set to True, selected features will be sorted on top, regardless of the current sort column

Parameters:

selectedOnTop (bool) – Specify, if selected features should be sorted on top

setSourceModel(self, sourceModel: QgsAttributeTableModel | None)[source]

Set the attribute table model that backs this model

Parameters:

sourceModel (Optional[QgsAttributeTableModel]) – The model

sort(self, column: int, order: Qt.SortOrder = Qt.AscendingOrder)[source]

Sort by the given column using the given order. Prefetches all the data from the layer to speed up sorting.

Parameters:
  • column (int) – The column which should be sorted

  • order (Qt.SortOrder = Qt.AscendingOrder) – The order ( Qt.AscendingOrder or Qt.DescendingOrder )

sort(self, expression: str | None, order: Qt.SortOrder = Qt.AscendingOrder)[source]

Sort by the given expression using the given order. Prefetches all the data from the layer to speed up sorting.

Parameters:
  • expression (Optional[str]) – The expression which should be used for sorting

  • order (Qt.SortOrder = Qt.AscendingOrder) – The order ( Qt.AscendingOrder or Qt.DescendingOrder )

signal sortColumnChanged(column: int, order: Qt.SortOrder)[source]

Emitted whenever the sort column is changed

Parameters:
  • column (int) – The sort column

  • order (Qt.SortOrder) – The sort order

sortExpression(self) str[source]

The expression which is used to sort the attribute table.

Return type:

str

signal visibleReloaded[source]

Emitted when the the visible features on extend are reloaded (the list is created)