QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <memory>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24
25#include <QAbstractItemModel>
26#include <QSortFilterProxyModel>
27
40class CORE_EXPORT QgsDatabaseTableModel : public QAbstractItemModel
41{
42 Q_OBJECT
43
44 public:
45
46 // *INDENT-OFF*
47
55 {
56 TableName SIP_MONKEYPATCH_COMPAT_NAME(RoleTableName) = Qt::UserRole,
57 Schema SIP_MONKEYPATCH_COMPAT_NAME(RoleSchema),
58 TableFlags SIP_MONKEYPATCH_COMPAT_NAME(RoleTableFlags),
59 Comment SIP_MONKEYPATCH_COMPAT_NAME(RoleComment),
60 CustomInfo SIP_MONKEYPATCH_COMPAT_NAME(RoleCustomInfo),
61 WkbType SIP_MONKEYPATCH_COMPAT_NAME(RoleWkbType),
63 Empty SIP_MONKEYPATCH_COMPAT_NAME(RoleEmpty),
64 };
65 Q_ENUM( CustomRole )
66 // *INDENT-ON*
67
68
76 explicit QgsDatabaseTableModel( const QString &provider, const QString &connection, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
77
85 explicit QgsDatabaseTableModel( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER, const QString &schema = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
86
87 // QAbstractItemModel interface
88 QModelIndex parent( const QModelIndex &child ) const override;
89 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
90 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
91 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
92 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
93
98 void setAllowEmptyTable( bool allowEmpty );
99
104 bool allowEmptyTable() const { return mAllowEmpty; }
105
106 public slots:
107
111 void refresh();
112
113 private:
114 void init();
115 std::unique_ptr< QgsAbstractDatabaseProviderConnection > mConnection;
116 QString mSchema;
117 QList<QgsAbstractDatabaseProviderConnection::TableProperty> mTables;
118 bool mAllowEmpty = false;
119};
120
121#endif // QGSDATABASETABLEMODEL_H
Provides common functionality for database based connections.
A model containing tables from a database connection.
QgsDatabaseTableModel(const QString &provider, const QString &connection, const QString &schema=QString(), QObject *parent=nullptr)
Constructor for QgsDatabaseTableModel, for the specified provider and connection name.
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:268
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270