Class: QgsAttributeTableFilterModel

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

Bases: PyQt5.QtCore.QSortFilterProxyModel, QgsFeatureModel

Make sure, the master model is already loaded, so the selection will get synchronized.

Parameters:
class ColumnType

Bases: int

baseClass

alias of QgsAttributeTableFilterModel

ColumnTypeActionButton = 1
ColumnTypeField = 0
class FilterMode

Bases: int

baseClass

alias of QgsAttributeTableFilterModel

class Role

Bases: int

ShowAll = 0
ShowEdited = 4
ShowFilteredList = 3
ShowSelected = 1
ShowVisible = 2
TypeRole = 258
actionColumnIndex(self) int

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

Return type:

int

beginInsertColumns(self, QModelIndex, int, int)
beginInsertRows(self, QModelIndex, int, int)
beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) bool
beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) bool
beginRemoveColumns(self, QModelIndex, int, int)
beginRemoveRows(self, QModelIndex, int, int)
beginResetModel(self)
changePersistentIndex(self, QModelIndex, QModelIndex)
changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])
childEvent(self, QChildEvent)
columnCount(self, parent: QModelIndex) int
Parameters:

parent (QModelIndex) –

Return type:

int

connectFilterModeConnections(self, filterMode: QgsAttributeTableFilterModel.FilterMode)

Disconnect the connections set for the new filterMode

Parameters:

filterMode (QgsAttributeTableFilterModel.FilterMode) –

connectNotify(self, QMetaMethod)
createIndex(self, int, int, object: object = 0) QModelIndex
customEvent(self, QEvent)
data(self, index: QModelIndex, role: int) Any
Parameters:
  • index (QModelIndex) –

  • role (int) –

Return type:

Any

decodeData(self, int, int, QModelIndex, QDataStream) bool
disconnectFilterModeConnections(self)

Disconnect the connections set for the current filterMode

disconnectNotify(self, QMetaMethod)
encodeData(self, Iterable[QModelIndex], QDataStream)
endInsertColumns(self)
endInsertRows(self)
endMoveColumns(self)
endMoveRows(self)
endRemoveColumns(self)
endRemoveRows(self)
endResetModel(self)
extentsChanged(self)

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 QGIS: 3.10.3 - made private as reloadVisible()

featuresFiltered

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

fidToIndex(self, fid: int) QModelIndex
Parameters:

fid (int) –

Return type:

QModelIndex

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

fid (int) –

Return type:

List[QModelIndex]

filterAcceptsColumn(self, int, QModelIndex) bool
filterAcceptsRow(self, sourceRow: int, sourceParent: QModelIndex) bool

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

filterError

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

filterExpression(self) str

Returns the stored filter expression string.

New in version 3.28.0.

Return type:

str

filterFeatures(self)

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

New in version 3.10.3.

filterMode(self) QgsAttributeTableFilterModel.FilterMode

The current filterModel

Return type:

QgsAttributeTableFilterModel.FilterMode

filteredFeatures(self) object

Gets a list of currently filtered feature ids

Return type:

object

Returns:

A list of feature ids

flags(self, index: QModelIndex) Qt.ItemFlags
Parameters:

index (QModelIndex) –

Return type:

Qt.ItemFlags

generateListOfVisibleFeatures(self)

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

headerData(self, section: int, orientation: Qt.Orientation, role: int) Any
Parameters:
  • section (int) –

  • orientation (Qt.Orientation) –

  • role (int) –

Return type:

Any

invalidateFilter(self)
isSignalConnected(self, QMetaMethod) bool
layer(self) QgsVectorLayer

Returns the layer this filter acts on.

Return type:

QgsVectorLayer

Returns:

Abovementioned layer

layerCache(self) QgsVectorLayerCache

Returns the layerCache this filter acts on.

Return type:

QgsVectorLayerCache

Returns:

The layer cache

lessThan(self, left: QModelIndex, right: QModelIndex) bool

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

Returns the map canvas

Return type:

QgsMapCanvas

mapFromMaster(self, sourceIndex: QModelIndex) QModelIndex
Parameters:

sourceIndex (QModelIndex) –

Return type:

QModelIndex

mapFromSource(self, sourceIndex: QModelIndex) QModelIndex
Parameters:

sourceIndex (QModelIndex) –

Return type:

QModelIndex

mapToMaster(self, proxyIndex: QModelIndex) QModelIndex
Parameters:

proxyIndex (QModelIndex) –

Return type:

QModelIndex

mapToSource(self, proxyIndex: QModelIndex) QModelIndex
Parameters:

proxyIndex (QModelIndex) –

Return type:

QModelIndex

masterModel(self) QgsAttributeTableModel

Returns the table model this filter is using

Return type:

QgsAttributeTableModel

Returns:

the table model in quesion

persistentIndexList(self) List[QModelIndex]
receivers(self, PYQT_SIGNAL) int
resetInternalData(self)
rowToId(self, row: QModelIndex) int

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

Returns if selected features are currently shown on top

Return type:

bool

Returns:

True if selected are shown on top

sender(self) QObject
senderSignalIndex(self) int
setAttributeTableConfig(self, config: QgsAttributeTableConfig)

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)

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).

New in version 3.10.3.

Parameters:
setFilterMode(self, filterMode: QgsAttributeTableFilterModel.FilterMode)

Set the filter mode the filter will use.

Parameters:

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

setFilteredFeatures(self, ids: object)

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 (object) – The list of feature ids which will be accepted by the filter

setSelectedOnTop(self, selectedOnTop: bool)

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)

Set the attribute table model that backs this model

Parameters:

sourceModel (QgsAttributeTableModel) – The model

New in version 2.0.

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

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, order: Qt.SortOrder = Qt.AscendingOrder) Sort by the given expression using the given order. Prefetches all the data from the layer to speed up sorting.

Parameters:
  • expression – The expression which should be used for sorting

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

sortColumnChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

sortExpression(self) str

The expression which is used to sort the attribute table.

Return type:

str

timerEvent(self, QTimerEvent)
visibleReloaded

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL