QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
45 // *INDENT-OFF*
46
54 {
55 TableName SIP_MONKEYPATCH_COMPAT_NAME(RoleTableName) = Qt::UserRole,
56 Schema SIP_MONKEYPATCH_COMPAT_NAME(RoleSchema),
57 TableFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleTableFlags),
58 Comment SIP_MONKEYPATCH_COMPAT_NAME(RoleComment),
59 CustomInfo SIP_MONKEYPATCH_COMPAT_NAME(RoleCustomInfo),
60 WkbType SIP_MONKEYPATCH_COMPAT_NAME(RoleWkbType),
61 Crs SIP_MONKEYPATCH_COMPAT_NAME(RoleCrs),
62 Empty SIP_MONKEYPATCH_COMPAT_NAME(RoleEmpty),
63 };
64 Q_ENUM( CustomRole )
65 // *INDENT-ON*
66
67
75 explicit QgsDatabaseTableModel( const QString &provider, const QString &connection, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
76
84 explicit QgsDatabaseTableModel( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
85
86 // QAbstractItemModel interface
87 QModelIndex parent( const QModelIndex &child ) const override;
88 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
89 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
90 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
91 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
92
97 void setAllowEmptyTable( bool allowEmpty );
98
103 bool allowEmptyTable() const { return mAllowEmpty; }
104
105 public slots:
106
110 void refresh();
111
112 private:
113 void init();
114 std::unique_ptr< QgsAbstractDatabaseProviderConnection > mConnection;
115 QString mSchema;
116 QList<QgsAbstractDatabaseProviderConnection::TableProperty> mTables;
117 bool mAllowEmpty = false;
118};
119
120#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.
CustomRole
Custom model roles.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273