src/app/qgsdbsourceselect.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgdbsourceselect.h  -  description
00003                              -------------------
00004     begin                : Sat Jun 22 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 /* $Id: qgsdbsourceselect.h 9502 2008-10-20 20:24:36Z timlinux $ */
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     // Store the selected database
00075     void dbChanged();
00076     // Utility function to construct the query for finding out the
00077     // geometry type of a column
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     // queue another query for the thread
00122     void addSearchGeometryColumn( const QString &schema, const QString &table, const QString &column );
00123 
00124     // Set the position of the database connection list to the last
00125     // used one.
00126     void setConnectionListPosition();
00127     // Show the context help for the dialog
00128     void showHelp();
00129     // Combine the schema, table and column data into a single string
00130     // useful for display to the user
00131     QString fullDescription( QString schema, QString table, QString column, QString type );
00132     // The column labels
00133     QStringList mColumnLabels;
00134     // Our thread for doing long running queries
00135     QgsGeomColumnTypeThread* mColumnTypeThread;
00136     QString m_connectionInfo;
00137     QStringList m_selectedTables;
00138     // Storage for the range of layer type icons
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 // Perhaps this class should be in its own file??
00149 //
00150 // A class that determines the geometry type of a given database
00151 // schema.table.column, with the option of doing so in a separate
00152 // thread.
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     // These functions get the layer types and pass that information out
00163     // by emitting the setLayerType() signal. The getLayerTypes()
00164     // function does the actual work, but use the run() function if you
00165     // want the work to be done as a separate thread from the calling
00166     // process.
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

Generated on Tue Oct 28 16:51:26 2008 for Quantum GIS API Documentation by  doxygen 1.5.1