Class: QgsAttributeTableModel¶
A model backed by a QgsVectorLayerCache
which is able to
provide feature/attribute information to a QAbstractItemView.
Is able to generate editor widgets for its QModelIndexes as well. Is mostly referred to as “master model” within this doc and the source.
see <a href=”http://doc.qt.digia.com/qt/model-view-programming.html”>Qt Model View Programming</a>
Class Hierarchy¶
Base classes¶
Enums
Custom model roles. |
|
alias of |
Methods
Returns the number of columns |
|
Returns data on the given index |
|
Returns the context in which this table is shown. |
|
Execute an action |
|
Execute a |
|
Empty extra columns to announce from this model. |
|
Returns the feature attributes at given model index |
|
Gets column from field index |
|
Handles updating the model when the conditional style for a field changes. |
|
Gets field index from column |
|
Returns item flags for the index |
|
Returns header data |
|
Maps feature id to table row |
|
Returns the layer this model uses as backend. |
|
Returns the layer cache this model uses as backend. |
|
Loads the layer into the model Preferably to be called, before using this model as source for any other proxy model |
|
Caches the entire data for one column. |
|
Prefetches the entire data for an expression. |
|
Reloads the model data between indices |
|
Remove rows |
|
Gets the the feature request |
|
Resets the model |
|
Returns the number of rows |
|
Maps row to feature id |
|
Updates data on given index |
|
Sets the context in which this table is shown. |
|
Empty extra columns to announce from this model. |
|
Set a request that will be used to fill this attribute table model. |
|
Sets whether the attribute table will add a visual feedback to cells when an attribute constraint is not met. |
|
Returns whether the attribute table will add a visual feedback to cells when an attribute constraint is not met. |
|
The expression which was used to fill the sorting cache at index cacheIndex. |
|
Swaps two rows |
Signals
Emitted when the model has completely loaded all features. |
|
Emitted when the model has been changed. |
- class qgis.gui.QgsAttributeTableModel[source]¶
Bases:
QAbstractTableModel
- __init__(layerCache: QgsVectorLayerCache | None, parent: QObject | None = None)
Constructor
- Parameters:
layerCache (Optional[QgsVectorLayerCache]) – A layer cache to use as backend
parent (Optional[QObject] = None) – The parent QObject (owner)
- class CustomRole(*values)¶
Bases:
IntEnum
Custom model roles.
Note
Prior to QGIS 3.36 this was available as QgsAttributeTableModel.Role
Added in version 3.36.
FeatureId
: Get the feature id of the feature in this rowAvailable as
QgsAttributeTableModel.FeatureIdRole
in older QGIS releases.FieldIndex
: Get the field index of this columnAvailable as
QgsAttributeTableModel.FieldIndexRole
in older QGIS releases.User
: Start further roles starting from this roleAvailable as
QgsAttributeTableModel.UserRole
in older QGIS releases.Sort
: Role used for sorting start hereAvailable as
QgsAttributeTableModel.SortRole
in older QGIS releases.
- Role¶
alias of
CustomRole
- columnCount(self, parent: QModelIndex = QModelIndex()) int [source]¶
Returns the number of columns
- Parameters:
parent (QModelIndex = QModelIndex()) – parent index
- Return type:
int
- data(self, index: QModelIndex, role: int) Any [source]¶
Returns data on the given index
- Parameters:
index (QModelIndex) – model index
role (int) – data role
- Return type:
Any
- editorContext(self) QgsAttributeEditorContext ¶
Returns the context in which this table is shown. Will be forwarded to any editor widget created when editing data on this model.
- Return type:
- Returns:
The context
- executeAction(self, action: QUuid, idx: QModelIndex)[source]¶
Execute an action
- Parameters:
action (QUuid)
idx (QModelIndex)
- executeMapLayerAction(self, action: QgsMapLayerAction | None, idx: QModelIndex, context: QgsMapLayerActionContext = QgsMapLayerActionContext())[source]¶
Execute a
QgsMapLayerAction
- Parameters:
action (Optional[QgsMapLayerAction])
idx (QModelIndex)
context (
QgsMapLayerActionContext
= QgsMapLayerActionContext())
- extraColumns(self) int [source]¶
Empty extra columns to announce from this model. Any extra columns need to be implemented by proxy models in front of this model.
- Return type:
int
- feature(self, idx: QModelIndex) QgsFeature [source]¶
Returns the feature attributes at given model index
- Return type:
- Returns:
feature attributes at given model index
- Parameters:
idx (QModelIndex)
- fieldCol(self, idx: int) int [source]¶
Gets column from field index
- Parameters:
idx (int)
- Return type:
int
- fieldConditionalStyleChanged(self, fieldName: str | None)[source]¶
Handles updating the model when the conditional style for a field changes.
- Parameters:
fieldName (Optional[str]) – name of field whose conditional style has changed
- fieldIdx(self, col: int) int [source]¶
Gets field index from column
- Parameters:
col (int)
- Return type:
int
- flags(self, index: QModelIndex) Qt.ItemFlags [source]¶
Returns item flags for the index
- Parameters:
index (QModelIndex) – model index
- Return type:
Qt.ItemFlags
- headerData(self, section: int, orientation: Qt.Orientation, role: int = Qt.DisplayRole) Any [source]¶
Returns header data
- Parameters:
section (int) – required section
orientation (Qt.Orientation) – horizontal or vertical orientation
role (int = Qt.DisplayRole) – data role
- Return type:
Any
- idToIndexList(self, id: int) List[QModelIndex] [source]¶
- Parameters:
id (int)
- Return type:
List[QModelIndex]
- idToRow(self, id: int) int [source]¶
Maps feature id to table row
- Parameters:
id (int) – feature id
- Return type:
int
- layer(self) QgsVectorLayer | None [source]¶
Returns the layer this model uses as backend. Retrieved from the layer cache.
- Return type:
Optional[QgsVectorLayer]
- layerCache(self) QgsVectorLayerCache | None [source]¶
Returns the layer cache this model uses as backend.
- Return type:
Optional[QgsVectorLayerCache]
- loadLayer(self)[source]¶
Loads the layer into the model Preferably to be called, before using this model as source for any other proxy model
- prefetchColumnData(self, column: int)[source]¶
Caches the entire data for one column. This should be called prior to sorting, so the data does not have to be fetched for every single comparison. Specify -1 as column to invalidate the cache
- Parameters:
column (int) – The column index of the field to catch
- prefetchSortData(self, expression: str | None, cacheIndex: int = 0)[source]¶
Prefetches the entire data for an
expression
. Based on this cached information the sorting can later be done in a performant way. AcacheIndex
can be specified if multiple caches should be filled. In this case, the caches will be available asQgsAttributeTableModel.SortRole + cacheIndex
.- Parameters:
expression (Optional[str])
cacheIndex (int = 0)
- reload(self, index1: QModelIndex, index2: QModelIndex)[source]¶
Reloads the model data between indices
- Parameters:
index1 (QModelIndex) – start index
index2 (QModelIndex) – end index
- removeRows(self, row: int, count: int, parent: QModelIndex = QModelIndex()) bool [source]¶
Remove rows
- Parameters:
row (int)
count (int)
parent (QModelIndex = QModelIndex())
- Return type:
bool
- request(self) QgsFeatureRequest ¶
Gets the the feature request
- Return type:
- resetModel(self)[source]¶
Resets the model
Alias to
loadLayer()
- rowCount(self, parent: QModelIndex = QModelIndex()) int [source]¶
Returns the number of rows
- Parameters:
parent (QModelIndex = QModelIndex()) – parent index
- Return type:
int
- rowToId(self, row: int) int [source]¶
Maps row to feature id
- Parameters:
row (int) – row number
- Return type:
int
- setData(self, index: QModelIndex, value: Any, role: int = Qt.EditRole) bool [source]¶
Updates data on given index
- Parameters:
index (QModelIndex) – model index
value (Any) – new data value
role (int = Qt.EditRole) – data role
- Return type:
bool
- setEditorContext(self, context: QgsAttributeEditorContext)[source]¶
Sets the context in which this table is shown. Will be forwarded to any editor widget created when editing data on this model.
- Parameters:
context (QgsAttributeEditorContext) – The context
- setExtraColumns(self, extraColumns: int)[source]¶
Empty extra columns to announce from this model. Any extra columns need to be implemented by proxy models in front of this model.
- Parameters:
extraColumns (int)
- setRequest(self, request: QgsFeatureRequest)[source]¶
Set a request that will be used to fill this attribute table model. In contrast to a filter, the request will constrain the data shown without the possibility to dynamically adjust it.
- Parameters:
request (QgsFeatureRequest) – The request to use to fill this table model.
- setShowValidityState(self, show: bool)[source]¶
Sets whether the attribute table will add a visual feedback to cells when an attribute constraint is not met.
Added in version 3.30.
- Parameters:
show (bool)
- showValidityState(self) bool [source]¶
Returns whether the attribute table will add a visual feedback to cells when an attribute constraint is not met.
Added in version 3.30.
- Return type:
bool