QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsdatabasetablemodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatabasetablemodel.h
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #ifndef QGSDATABASETABLEMODEL_H
17 #define QGSDATABASETABLEMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
22 #include <memory>
23 
24 #include "qgis_core.h"
25 #include "qgis_sip.h"
26 
39 class CORE_EXPORT QgsDatabaseTableModel : public QAbstractItemModel
40 {
41  Q_OBJECT
42 
43  public:
44 
46  enum Role
47  {
48  RoleTableName = Qt::UserRole,
56  };
57 
66  explicit QgsDatabaseTableModel( const QString &provider, const QString &connection, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
67 
75  explicit QgsDatabaseTableModel( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
76 
77  // QAbstractItemModel interface
78  QModelIndex parent( const QModelIndex &child ) const override;
79  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
80  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
81  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
82  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
83 
88  void setAllowEmptyTable( bool allowEmpty );
89 
94  bool allowEmptyTable() const { return mAllowEmpty; }
95 
96  public slots:
97 
101  void refresh();
102 
103  private:
104  void init();
105  std::unique_ptr< QgsAbstractDatabaseProviderConnection > mConnection;
106  QString mSchema;
107  QList<QgsAbstractDatabaseProviderConnection::TableProperty> mTables;
108  bool mAllowEmpty = false;
109 };
110 
111 #endif // QGSDATABASETABLEMODEL_H
QgsDatabaseTableModel::RoleEmpty
@ RoleEmpty
Entry is an empty entry.
Definition: qgsdatabasetablemodel.h:55
QgsDatabaseTableModel::RoleSchema
@ RoleSchema
Table schema.
Definition: qgsdatabasetablemodel.h:49
QgsDatabaseTableModel::RoleComment
@ RoleComment
Comment role.
Definition: qgsdatabasetablemodel.h:51
QgsDatabaseTableModel::RoleTableFlags
@ RoleTableFlags
Table flags role.
Definition: qgsdatabasetablemodel.h:50
QgsDatabaseTableModel::RoleWkbType
@ RoleWkbType
WKB type for primary (first) geometry column in table.
Definition: qgsdatabasetablemodel.h:53
QgsDatabaseTableModel::allowEmptyTable
bool allowEmptyTable() const
Returns true if the model allows the empty table ("not set") choice.
Definition: qgsdatabasetablemodel.h:94
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsDatabaseTableModel
A model containing tables from a database connection.
Definition: qgsdatabasetablemodel.h:40
QgsDatabaseTableModel::RoleCrs
@ RoleCrs
CRS for primary (first) geometry column in table.
Definition: qgsdatabasetablemodel.h:54
QgsDatabaseTableModel::RoleCustomInfo
@ RoleCustomInfo
Custom info variant map role.
Definition: qgsdatabasetablemodel.h:52
qgsabstractdatabaseproviderconnection.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsAbstractDatabaseProviderConnection
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Definition: qgsabstractdatabaseproviderconnection.h:44
QgsDatabaseTableModel::Role
Role
Model roles.
Definition: qgsdatabasetablemodel.h:47