QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
39class 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
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
A model containing tables from a database connection.
bool allowEmptyTable() const
Returns true if the model allows the empty table ("not set") choice.
@ RoleWkbType
WKB type for primary (first) geometry column in table.
@ RoleEmpty
Entry is an empty entry.
@ RoleCrs
CRS for primary (first) geometry column in table.
@ RoleCustomInfo
Custom info variant map role.
@ RoleTableFlags
Table flags role.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36