00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QGSDBSOURCESELECT_H
00019 #define QGSDBSOURCESELECT_H
00020 #include "ui_qgsdbsourceselectbase.h"
00021 #include "qgisgui.h"
00022 #include "qgsdbfilterproxymodel.h"
00023 #include "qgsdbtablemodel.h"
00024
00025 extern "C"
00026 {
00027 #include <libpq-fe.h>
00028 }
00029
00030 #include <QThread>
00031
00032 #include <vector>
00033 #include <list>
00034 #include <utility>
00035
00036 #include <QMap>
00037 #include <QPair>
00038 #include <QIcon>
00039
00040 class QStringList;
00041 class QTableWidgetItem;
00042 class QgsGeomColumnTypeThread;
00043 class QgisApp;
00051 class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
00052 {
00053 Q_OBJECT
00054 public:
00055
00057 QgsDbSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
00059 ~QgsDbSourceSelect();
00061 void addNewConnection();
00063 void editConnection();
00065 void deleteConnection();
00067 void populateConnectionList();
00069 void addTables();
00071 QStringList selectedTables();
00073 QString connectionInfo();
00074
00075 void dbChanged();
00076
00077
00078 static QString makeGeomQuery( QString schema, QString table, QString column );
00079
00080 public slots:
00084 void on_btnConnect_clicked();
00085 void on_btnAdd_clicked();
00086 void on_btnNew_clicked();
00087 void on_btnEdit_clicked();
00088 void on_btnDelete_clicked();
00089 void on_mSearchOptionsButton_clicked();
00090 void on_mSearchTableEdit_textChanged( const QString & text );
00091 void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
00092 void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
00093 void setSql( const QModelIndex& index );
00094 void on_btnHelp_clicked();
00095 void on_cmbConnections_activated( int );
00096 void setLayerType( QString schema, QString table, QString column,
00097 QString type );
00099 void setSearchExpression( const QString& regexp );
00100
00101 private:
00102 enum columns
00103 {
00104 dbssType = 0,
00105 dbssDetail,
00106 dbssSql,
00107 dbssColumns
00108 };
00109
00110 typedef std::pair<QString, QString> geomPair;
00111 typedef std::list<geomPair > geomCol;
00112
00113 bool getGeometryColumnInfo( PGconn *pd,
00114 geomCol& details,
00115 bool searchGeometryColumnsOnly,
00116 bool searchPublicOnly );
00117
00119 bool getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly, bool searchPublicOnly );
00120
00121
00122 void addSearchGeometryColumn( const QString &schema, const QString &table, const QString &column );
00123
00124
00125
00126 void setConnectionListPosition();
00127
00128 void showHelp();
00129
00130
00131 QString fullDescription( QString schema, QString table, QString column, QString type );
00132
00133 QStringList mColumnLabels;
00134
00135 QgsGeomColumnTypeThread* mColumnTypeThread;
00136 QString m_connectionInfo;
00137 QStringList m_selectedTables;
00138
00139 QMap<QString, QPair<QString, QIcon> > mLayerIcons;
00140 PGconn *pd;
00141 static const int context_id = 939347163;
00143 QgsDbTableModel mTableModel;
00144 QgsDbFilterProxyModel mProxyModel;
00145 };
00146
00147
00148
00149
00150
00151
00152
00153
00154 class QgsGeomColumnTypeThread : public QThread
00155 {
00156 Q_OBJECT
00157 public:
00158
00159 void setConnInfo( QString s );
00160 void addGeometryColumn( QString schema, QString table, QString column );
00161
00162
00163
00164
00165
00166
00167 virtual void run() { getLayerTypes(); }
00168 void getLayerTypes();
00169
00170 signals:
00171 void setLayerType( QString schema, QString table, QString column,
00172 QString type );
00173
00174 public slots:
00175 void stop();
00176
00177
00178 private:
00179 QString mConnInfo;
00180 bool mStopped;
00181 std::vector<QString> schemas, tables, columns;
00182 };
00183
00184 #endif // QGSDBSOURCESELECT_H