Class: QgsAttributeTableFilterModel¶
A proxy model for filtering an attribute table model.
Class Hierarchy¶
Base classes¶
Base class for feature models. |
- class qgis.gui.QgsAttributeTableFilterModel[source]¶
Bases:
QSortFilterProxyModel,QgsFeatureModel- __init__(canvas: QgsMapCanvas | None, sourceModel: QgsAttributeTableModel | None, parent: QObject | None = None)
Make sure, the master model is already loaded, so the selection will get synchronized.
- Parameters:
parent (Optional[QObject] = None) – parent object (owner)
sourceModel (Optional[QgsAttributeTableModel]) – The
QgsAttributeTableModelto use as source (mostly referred to as master model)canvas (Optional[QgsMapCanvas]) – The mapCanvas. Used to identify the currently visible features.
- class ColumnType¶
Bases:
int
- ColumnTypeActionButton = 1¶
- ColumnTypeField = 0¶
- class CustomRole(*values)¶
Bases:
IntEnumThe additional roles defined by this filter model. The values of these roles start just after the roles defined by
QgsAttributeTableModelso 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.TypeRolein 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]¶
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.
- fidToIndexList(self, fid: int) List[QModelIndex][source]¶
- Parameters:
fid (int)
- Return type:
List[QModelIndex]
- virtual filterAcceptsRow(self, sourceRow: int, sourceParent: QModelIndex) bool[source]¶
Returns
Trueif 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[source]¶
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.
- 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:
- filteredFeatures(self) Any[source]¶
Gets a list of currently filtered feature ids
- Return type:
- 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
- virtual 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:
Trueif 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
expressionand thecontextto 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:
expression (QgsExpression)
context (QgsExpressionContext)
- 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
- virtual 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
- virtual 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: Optional[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 )
- signal sortColumnChanged[source]¶
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.
- sortExpression(self) str[source]¶
The expression which is used to sort the attribute table.
- Return type:
str
- signal visibleReloaded[source]¶
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.