Class: QgsDatabaseTableModel¶
- class qgis.core.QgsDatabaseTableModel¶
Bases:
PyQt5.QtCore.QAbstractItemModel
A model containing tables from a database connection.
This class does not automatically subscribe to database updates. Tables are queried from the database initially upon model construction. In order to update the listed tbales,
QgsDatabaseTableModel.refresh()
must be manually called.New in version 3.14.
QgsDatabaseTableModel(provider: str, connection: str, schema: str = ‘’, parent: QObject = None) Constructor for
QgsDatabaseTableModel
, for the specifiedprovider
andconnection
name.The optional
schema
argument can be used to restrict the tables to those from a specific schema.Warning
The
provider
must support the connection API methods in itsQgsProviderMetadata
implementation in order for the model to work correctly.QgsDatabaseTableModel(connection:
QgsAbstractDatabaseProviderConnection
, schema: str = ‘’, parent: QObject = None) Constructor forQgsDatabaseTableModel
, for the specifiedconnection
.The optional
schema
argument can be used to restrict the tables to those from a specific schema.Ownership of
connection
is transferred to the model.Enums
Bases:
enum.IntEnum
alias of
CustomRole
Methods
Returns
True
if the model allows the empty table ("not set") choice.- param parent:
- param index:
- param row:
- param child:
Refreshes the table list by querying the underlying connection.
- param parent:
Sets whether an optional empty table ("not set") option is present in the model.
- class CustomRole(value)¶
Bases:
enum.IntEnum
Custom model roles.
Note
Prior to QGIS 3.36 this was available as QgsDatabaseTableModel.Role
New in version 3.36.
RoleTableName
: Table nameRoleSchema
: Table schemaRoleTableFlags
: Table flags roleRoleComment
: Comment roleRoleCustomInfo
: Custom info variant map roleRoleWkbType
: WKB type for primary (first) geometry column in tableRoleCrs
: CRS for primary (first) geometry column in tableRoleEmpty
: Entry is an empty entry
- baseClass¶
alias of
QgsDatabaseTableModel
- Role¶
alias of
CustomRole
- allowEmptyTable(self) bool ¶
Returns
True
if the model allows the empty table (“not set”) choice.See also
- Return type:
bool
- 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 = QModelIndex()) int ¶
- Parameters:
parent (QModelIndex = QModelIndex()) –
- Return type:
int
- connectNotify(self, QMetaMethod)¶
- createIndex(self, int, int, object: object = 0) QModelIndex ¶
- customEvent(self, QEvent)¶
- data(self, index: QModelIndex, role: int = Qt.DisplayRole) Any ¶
- Parameters:
index (QModelIndex) –
role (int = Qt.DisplayRole) –
- Return type:
Any
- decodeData(self, int, int, QModelIndex, QDataStream) bool ¶
- disconnectNotify(self, QMetaMethod)¶
- encodeData(self, Iterable[QModelIndex], QDataStream)¶
- endInsertColumns(self)¶
- endInsertRows(self)¶
- endMoveColumns(self)¶
- endMoveRows(self)¶
- endRemoveColumns(self)¶
- endRemoveRows(self)¶
- endResetModel(self)¶
- index(self, row: int, column: int, parent: QModelIndex) QModelIndex ¶
- Parameters:
row (int) –
column (int) –
parent (QModelIndex) –
- Return type:
QModelIndex
- isSignalConnected(self, QMetaMethod) bool ¶
- parent(self, child: QModelIndex) QModelIndex ¶
- Parameters:
child (QModelIndex) –
- Return type:
QModelIndex
- persistentIndexList(self) List[QModelIndex] ¶
- receivers(self, PYQT_SIGNAL) int ¶
- refresh(self)¶
Refreshes the table list by querying the underlying connection.
- resetInternalData(self)¶
- rowCount(self, parent: QModelIndex = QModelIndex()) int ¶
- Parameters:
parent (QModelIndex = QModelIndex()) –
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAllowEmptyTable(self, allowEmpty: bool)¶
Sets whether an optional empty table (“not set”) option is present in the model.
See also
- Parameters:
allowEmpty (bool) –
- timerEvent(self, QTimerEvent)¶