QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Types | Public Slots | Public Member Functions | List of all members
QgsDatabaseTableModel Class Reference

A model containing tables from a database connection. More...

#include <qgsdatabasetablemodel.h>

Inheritance diagram for QgsDatabaseTableModel:
Inheritance graph
[legend]

Public Types

enum class  CustomRole : int {
  TableName = Qt::UserRole , Schema , TableFlags , Comment ,
  CustomInfo , WkbType , Crs , Empty
}
 Custom model roles. More...
 

Public Slots

void refresh ()
 Refreshes the table list by querying the underlying connection.
 

Public Member Functions

 QgsDatabaseTableModel (const QString &provider, const QString &connection, const QString &schema=QString(), QObject *parent=nullptr)
 Constructor for QgsDatabaseTableModel, for the specified provider and connection name.
 
 QgsDatabaseTableModel (QgsAbstractDatabaseProviderConnection *connection, const QString &schema=QString(), QObject *parent=nullptr)
 Constructor for QgsDatabaseTableModel, for the specified connection.
 
bool allowEmptyTable () const
 Returns true if the model allows the empty table ("not set") choice.
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent) const override
 
QModelIndex parent (const QModelIndex &child) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
void setAllowEmptyTable (bool allowEmpty)
 Sets whether an optional empty table ("not set") option is present in the model.
 

Detailed Description

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.

Since
QGIS 3.14

Definition at line 39 of file qgsdatabasetablemodel.h.

Member Enumeration Documentation

◆ CustomRole

enum class QgsDatabaseTableModel::CustomRole : int
strong

Custom model roles.

Note
Prior to QGIS 3.36 this was available as QgsDatabaseTableModel::Role
Since
QGIS 3.36
Enumerator
TableName 

Table name.

Schema 

Table schema.

TableFlags 

Table flags role.

Comment 

Comment role.

CustomInfo 

Custom info variant map role.

WkbType 

WKB type for primary (first) geometry column in table.

Crs 

CRS for primary (first) geometry column in table.

Empty 

Entry is an empty entry.

Definition at line 53 of file qgsdatabasetablemodel.h.

Constructor & Destructor Documentation

◆ QgsDatabaseTableModel() [1/2]

QgsDatabaseTableModel::QgsDatabaseTableModel ( const QString &  provider,
const QString &  connection,
const QString &  schema = QString(),
QObject *  parent = nullptr 
)
explicit

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.

Definition at line 23 of file qgsdatabasetablemodel.cpp.

◆ QgsDatabaseTableModel() [2/2]

QgsDatabaseTableModel::QgsDatabaseTableModel ( QgsAbstractDatabaseProviderConnection connection,
const QString &  schema = QString(),
QObject *  parent = nullptr 
)
explicit

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.

Definition at line 35 of file qgsdatabasetablemodel.cpp.

Member Function Documentation

◆ allowEmptyTable()

bool QgsDatabaseTableModel::allowEmptyTable ( ) const
inline

Returns true if the model allows the empty table ("not set") choice.

See also
setAllowEmptyTable()

Definition at line 103 of file qgsdatabasetablemodel.h.

◆ columnCount()

int QgsDatabaseTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 65 of file qgsdatabasetablemodel.cpp.

◆ data()

QVariant QgsDatabaseTableModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 72 of file qgsdatabasetablemodel.cpp.

◆ index()

QModelIndex QgsDatabaseTableModel::index ( int  row,
int  column,
const QModelIndex &  parent 
) const
override

Definition at line 170 of file qgsdatabasetablemodel.cpp.

◆ parent()

QModelIndex QgsDatabaseTableModel::parent ( const QModelIndex &  child) const
override

Definition at line 50 of file qgsdatabasetablemodel.cpp.

◆ refresh

void QgsDatabaseTableModel::refresh ( )
slot

Refreshes the table list by querying the underlying connection.

Definition at line 199 of file qgsdatabasetablemodel.cpp.

◆ rowCount()

int QgsDatabaseTableModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 57 of file qgsdatabasetablemodel.cpp.

◆ setAllowEmptyTable()

void QgsDatabaseTableModel::setAllowEmptyTable ( bool  allowEmpty)

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

See also
allowEmptyTable()

Definition at line 180 of file qgsdatabasetablemodel.cpp.


The documentation for this class was generated from the following files: