Class: QgsAttributeTableModel¶
- class qgis.gui.QgsAttributeTableModel¶
Bases:
PyQt5.QtCore.QAbstractTableModel
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>
QgsAttributeTableModel(layerCache:
QgsVectorLayerCache
, parent: QObject = None) Constructor- Parameters:
layerCache – A layer cache to use as backend
parent –
The parent QObject (owner)
Methods
beginInsertColumns
beginInsertRows
beginMoveColumns
beginMoveRows
beginRemoveColumns
beginRemoveRows
changePersistentIndex
Returns the number of columns
createIndex
Returns data on the given index
decodeData
Returns the context in which this table is shown.
Execute an action
Execute a
QgsMapLayerAction
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
- param id:
- param id:
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
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- FeatureIdRole = 256¶
- FieldIndexRole = 257¶
- class Role¶
Bases:
int
- SortRole = 259¶
- UserRole = 258¶
- QgsAttributeTableModel.beginInsertColumns(self, QModelIndex, int, int)
- QgsAttributeTableModel.beginInsertRows(self, QModelIndex, int, int)
- QgsAttributeTableModel.beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) -> bool
- QgsAttributeTableModel.beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) -> bool
- QgsAttributeTableModel.beginRemoveColumns(self, QModelIndex, int, int)
- QgsAttributeTableModel.beginRemoveRows(self, QModelIndex, int, int)
- beginResetModel(self)¶
- QgsAttributeTableModel.changePersistentIndex(self, QModelIndex, QModelIndex)
- changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])¶
- childEvent(self, QChildEvent)¶
- columnCount(self, parent: QModelIndex = QModelIndex()) int ¶
Returns the number of columns
- Parameters:
parent (QModelIndex = QModelIndex()) – parent index
- Return type:
int
- connectNotify(self, QMetaMethod)¶
- QgsAttributeTableModel.createIndex(self, int, int, object: object = 0) -> QModelIndex
- customEvent(self, QEvent)¶
- data(self, index: QModelIndex, role: int) Any ¶
Returns data on the given index
- Parameters:
index (QModelIndex) – model index
role (int) – data role
- Return type:
Any
- QgsAttributeTableModel.decodeData(self, int, int, QModelIndex, QDataStream) -> bool
- disconnectNotify(self, QMetaMethod)¶
- 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
- encodeData(self, Iterable[QModelIndex], QDataStream)¶
- endInsertColumns(self)¶
- endInsertRows(self)¶
- endMoveColumns(self)¶
- endMoveRows(self)¶
- endRemoveColumns(self)¶
- endRemoveRows(self)¶
- endResetModel(self)¶
- executeAction(self, action: QUuid, idx: QModelIndex)¶
Execute an action
- Parameters:
action (QUuid) –
idx (QModelIndex) –
- executeMapLayerAction(self, action: QgsMapLayerAction, idx: QModelIndex, context: QgsMapLayerActionContext = QgsMapLayerActionContext())¶
Execute a
QgsMapLayerAction
- Parameters:
action (QgsMapLayerAction) –
idx (QModelIndex) –
context (
QgsMapLayerActionContext
= QgsMapLayerActionContext()) –
- extraColumns(self) int ¶
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 ¶
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 ¶
Gets column from field index
- Parameters:
idx (int) –
- Return type:
int
- fieldConditionalStyleChanged(self, fieldName: str)¶
Handles updating the model when the conditional style for a field changes.
- Parameters:
fieldName (str) – name of field whose conditional style has changed
New in version 2.12.
- fieldIdx(self, col: int) int ¶
Gets field index from column
- Parameters:
col (int) –
- Return type:
int
- finished¶
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
- flags(self, index: QModelIndex) Qt.ItemFlags ¶
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 ¶
Returns header data
- Parameters:
section (int) – required section
orientation (Qt.Orientation) – horizontal or vertical orientation
role (int = Qt.DisplayRole) – data role
- Return type:
Any
- idToIndex(self, id: int) QModelIndex ¶
- Parameters:
id (int) –
- Return type:
QModelIndex
- idToIndexList(self, id: int) List[QModelIndex] ¶
- Parameters:
id (int) –
- Return type:
List[QModelIndex]
- idToRow(self, id: int) int ¶
Maps feature id to table row
- Parameters:
id (int) – feature id
- Return type:
int
- isSignalConnected(self, QMetaMethod) bool ¶
- layer(self) QgsVectorLayer ¶
Returns the layer this model uses as backend. Retrieved from the layer cache.
- Return type:
- layerCache(self) QgsVectorLayerCache ¶
Returns the layer cache this model uses as backend.
- Return type:
- loadLayer(self)¶
Loads the layer into the model Preferably to be called, before using this model as source for any other proxy model
- modelChanged¶
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
- persistentIndexList(self) List[QModelIndex] ¶
- prefetchColumnData(self, column: int)¶
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, cacheIndex: int = 0)¶
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 (str) –
cacheIndex (int = 0) –
- receivers(self, PYQT_SIGNAL) int ¶
- reload(self, index1: QModelIndex, index2: QModelIndex)¶
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 ¶
Remove rows
- Parameters:
row (int) –
count (int) –
parent (QModelIndex = QModelIndex()) –
- Return type:
bool
- request(self) QgsFeatureRequest ¶
Gets the the feature request
- Return type:
- resetInternalData(self)¶
- resetModel(self)¶
Resets the model
Alias to
loadLayer()
- rowCount(self, parent: QModelIndex = QModelIndex()) int ¶
Returns the number of rows
- Parameters:
parent (QModelIndex = QModelIndex()) – parent index
- Return type:
int
- rowToId(self, row: int) int ¶
Maps row to feature id
- Parameters:
row (int) – row number
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setData(self, index: QModelIndex, value: Any, role: int = Qt.EditRole) bool ¶
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)¶
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)¶
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)¶
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)¶
Sets whether the attribute table will add a visual feedback to cells when an attribute constraint is not met.
New in version 3.30.
- Parameters:
show (bool) –
- showValidityState(self) bool ¶
Returns whether the attribute table will add a visual feedback to cells when an attribute constraint is not met.
New in version 3.30.
- Return type:
bool
- sortCacheExpression(self, cacheIndex: int = 0) str ¶
The expression which was used to fill the sorting cache at index
cacheIndex
.See also
- Parameters:
cacheIndex (int = 0) –
- Return type:
str
- swapRows(self, a: int, b: int)¶
Swaps two rows
- Parameters:
a (int) – first row
b (int) – second row
- timerEvent(self, QTimerEvent)¶