Class: QgsDatabaseTableModel

class qgis.core.QgsDatabaseTableModel(provider: str, connection: str, schema: str = '', parent: QObject = None)

Bases: PyQt5.QtCore.QAbstractItemModel

Constructor for QgsDatabaseTableModel, for the specified provider and connection 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 its QgsProviderMetadata implementation in order for the model to work correctly.

QgsDatabaseTableModel(connection: QgsAbstractDatabaseProviderConnection, schema: str = ‘’, parent: QObject = None) Constructor for QgsDatabaseTableModel, for the specified connection.

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.

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.

Parameters
  • provider (str) –

  • connection (str) –

  • schema (str = '') –

  • parent

class Role

Bases: int

RoleComment = 259
RoleCrs = 262
RoleCustomInfo = 260
RoleEmpty = 263
RoleSchema = 257
RoleTableFlags = 258
RoleTableName = 256
RoleWkbType = 261
allowEmptyTable(self) → bool

Returns True if the model allows the empty table (“not set”) choice.

Return type

bool

beginInsertColumns()
beginInsertRows()
beginMoveColumns()
beginMoveRows()
beginRemoveColumns()
beginRemoveRows()
beginResetModel()
changePersistentIndex()
changePersistentIndexList()
childEvent()
columnCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

int

connectNotify()
createIndex()
customEvent()
data(self, index: QModelIndex, role: int = Qt.DisplayRole) → Any
Parameters
  • index (QModelIndex) –

  • role (int = Qt.DisplayRole) –

Return type

Any

decodeData()
disconnectNotify()
encodeData()
endInsertColumns()
endInsertRows()
endMoveColumns()
endMoveRows()
endRemoveColumns()
endRemoveRows()
endResetModel()
index(self, row: int, column: int, parent: QModelIndex) → QModelIndex
Parameters
  • row (int) –

  • column (int) –

  • parent (QModelIndex) –

Return type

QModelIndex

isSignalConnected()
parent(self, child: QModelIndex) → QModelIndex
Parameters

child (QModelIndex) –

Return type

QModelIndex

persistentIndexList()
receivers()
refresh(self)

Refreshes the table list by querying the underlying connection.

resetInternalData()
rowCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

int

sender()
senderSignalIndex()
setAllowEmptyTable(self, allowEmpty: bool)

Sets whether an optional empty table (“not set”) option is present in the model.

Parameters

allowEmpty (bool) –

timerEvent()