QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsdatabasetablecombobox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatabasetablecombobox.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 QGSDATABASETABLECOMBOBOX_H
17 #define QGSDATABASETABLECOMBOBOX_H
18 
19 #include <QComboBox>
20 
21 #include "qgis_gui.h"
22 #include "qgis_sip.h"
23 #include <QSortFilterProxyModel>
24 
27 
29 #ifndef SIP_RUN
30 class GUI_EXPORT QgsDatabaseTableComboBoxSortModel: public QSortFilterProxyModel
31 {
32  public:
33  explicit QgsDatabaseTableComboBoxSortModel( QObject *parent = nullptr );
34  protected:
35  bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
36 
37 };
38 #endif
40 
50 class GUI_EXPORT QgsDatabaseTableComboBox : public QWidget
51 {
52  Q_OBJECT
53 
54  public:
55 
64  explicit QgsDatabaseTableComboBox( const QString &provider, const QString &connection, const QString &schema = QString(), QWidget *parent SIP_TRANSFERTHIS = nullptr );
65 
73  explicit QgsDatabaseTableComboBox( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER, const QString &schema = QString(), QWidget *parent SIP_TRANSFERTHIS = nullptr );
74 
79  void setAllowEmptyTable( bool allowEmpty );
80 
85  bool allowEmptyTable() const;
86 
90  QString currentTable() const;
91 
95  QString currentSchema() const;
96 
100  QComboBox *comboBox() { return mComboBox; }
101 
102  public slots:
103 
109  void setTable( const QString &table, const QString &schema = QString() );
110 
116  void setConnectionName( const QString &connection, const QString &provider = QString() );
117 
121  void setSchema( const QString &schema );
122 
126  void refreshTables();
127 
128  signals:
130  void tableChanged( const QString &table, const QString &schema = QString() );
131 
132  private slots:
133  void indexChanged( int i );
134  void rowsChanged();
135 
136  private:
137  void init();
138 
139  bool mAllowEmpty = false;
140  QString mProvider;
141  QString mConnection;
142  QString mSchema;
143  QgsDatabaseTableModel *mModel = nullptr;
144  QSortFilterProxyModel *mSortModel = nullptr;
145  QComboBox *mComboBox = nullptr;
146 };
147 
148 #endif // QGSDATABASETABLECOMBOBOX_H
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
The QgsDatabaseTableComboBox class is a combo box which displays the list of tables for a specific da...
void tableChanged(const QString &table, const QString &schema=QString())
Emitted whenever the currently selected table changes.
QComboBox * comboBox()
Returns the combobox portion of the widget.
A model containing tables from a database connection.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36