QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QComboBox>
23#include <QSortFilterProxyModel>
24
27
29#ifndef SIP_RUN
30class GUI_EXPORT QgsDatabaseTableComboBoxSortModel : public QSortFilterProxyModel
31{
32 Q_OBJECT
33 public:
34 explicit QgsDatabaseTableComboBoxSortModel( QObject *parent = nullptr );
35
36 protected:
37 bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
38};
39#endif
41
51class GUI_EXPORT QgsDatabaseTableComboBox : public QWidget
52{
53 Q_OBJECT
54
55 public:
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
Provides common functionality for database based connections.
void tableChanged(const QString &table, const QString &schema=QString())
Emitted whenever the currently selected table changes.
QString currentSchema() const
Returns the schema of the current table selected in the combo box.
QComboBox * comboBox()
Returns the combobox portion of the widget.
bool allowEmptyTable() const
Returns true if the combobox allows the empty table ("not set") choice.
void setAllowEmptyTable(bool allowEmpty)
Sets whether an optional empty table ("not set") option is present in the combobox.
QgsDatabaseTableComboBox(const QString &provider, const QString &connection, const QString &schema=QString(), QWidget *parent=nullptr)
Constructor for QgsDatabaseTableComboBox, for the specified provider and connection.
QString currentTable() const
Returns the name of the current table selected in the combo box.
A model containing tables from a database connection.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36