~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgsdbsourceselect.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          qgdbsourceselect.h  -  description
3
 
                             -------------------
4
 
    begin                : Sat Jun 22 2002
5
 
    copyright            : (C) 2002 by Gary E.Sherman
6
 
    email                : sherman at mrcc.com
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
/* $Id: qgsdbsourceselect.h 5718 2006-08-21 11:17:49Z g_j_m $ */
18
 
#ifndef QGSDBSOURCESELECT_H
19
 
#define QGSDBSOURCESELECT_H
20
 
#include "ui_qgsdbsourceselectbase.h"
21
 
#include "qgisgui.h"
22
 
extern "C"
23
 
{
24
 
#include <libpq-fe.h>
25
 
}
26
 
 
27
 
#include <QThread>
28
 
 
29
 
#include <vector>
30
 
#include <list>
31
 
#include <utility>
32
 
 
33
 
#include <QMap>
34
 
#include <QPair>
35
 
#include <QIcon>
36
 
 
37
 
class QStringList;
38
 
class QTableWidgetItem;
39
 
class QgsGeomColumnTypeThread;
40
 
class QgisApp;
41
 
/*! \class QgsDbSourceSelect
42
 
 * \brief Dialog to create connections and add tables from PostgresQL.
43
 
 *
44
 
 * This dialog allows the user to define and save connection information
45
 
 * for PostGIS enabled PostgresQL databases. The user can then connect and add 
46
 
 * tables from the database to the map canvas.
47
 
 */
48
 
class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase 
49
 
{
50
 
  Q_OBJECT
51
 
 public:
52
 
 
53
 
    //! Constructor
54
 
    QgsDbSourceSelect(QgisApp *app, Qt::WFlags fl = QgisGui::ModalDialogFlags);
55
 
    //! Destructor
56
 
    ~QgsDbSourceSelect();
57
 
    //! Opens the create connection dialog to build a new connection
58
 
    void addNewConnection();
59
 
    //! Opens a dialog to edit an existing connection
60
 
    void editConnection();
61
 
    //! Deletes the selected connection
62
 
    void deleteConnection();
63
 
    //! Populate the connection list combo box
64
 
    void populateConnectionList();
65
 
    //! Determines the tables the user selected and closes the dialog
66
 
    void addTables();
67
 
    //! String list containing the selected tables
68
 
    QStringList selectedTables();
69
 
    //! Connection info (database, host, user, password)
70
 
    QString connInfo();
71
 
    //! Return the name of the selected encoding (e.g. UTf-8, ISO-8559-1, etc/)
72
 
    QString encoding();
73
 
    // Store the selected database
74
 
    void dbChanged();
75
 
    // Utility function to construct the query for finding out the
76
 
    // geometry type of a column
77
 
    static QString makeGeomQuery(QString schema, QString table, QString column);
78
 
 
79
 
    public slots:
80
 
    /*! Connects to the database using the stored connection parameters. 
81
 
    * Once connected, available layers are displayed.
82
 
    */
83
 
      void on_btnConnect_clicked();
84
 
      void on_btnAdd_clicked();
85
 
      void on_btnNew_clicked();
86
 
      void on_btnEdit_clicked();
87
 
      void on_btnDelete_clicked();
88
 
      void on_lstTables_itemDoubleClicked(QTableWidgetItem *);
89
 
      void setSql(QTableWidgetItem *);
90
 
      void on_btnHelp_clicked();
91
 
      void on_cmbConnections_activated(int);
92
 
      void setLayerType(QString schema, QString table, QString column,
93
 
                        QString type);
94
 
 private:
95
 
 
96
 
    typedef std::pair<QString, QString> geomPair;
97
 
    typedef std::list<geomPair > geomCol;
98
 
 
99
 
    bool getGeometryColumnInfo(PGconn *pd, 
100
 
                               geomCol& details, 
101
 
                               bool searchGeometryColumnsOnly,
102
 
                               bool searchPublicOnly);
103
 
    // Set the position of the database connection list to the last
104
 
    // used one. 
105
 
    void setConnectionListPosition();
106
 
    // Show the context help for the dialog
107
 
    void showHelp();
108
 
    // Combine the schema, table and column data into a single string
109
 
    // useful for display to the user
110
 
    QString fullDescription(QString schema, QString table, QString column);
111
 
    // The column labels
112
 
    QStringList mColumnLabels;
113
 
    // Our thread for doing long running queries
114
 
    QgsGeomColumnTypeThread* mColumnTypeThread;
115
 
    QString m_connInfo;
116
 
    QStringList m_selectedTables;
117
 
    // Storage for the range of layer type icons
118
 
    QMap<QString, QPair<QString, QIcon> > mLayerIcons;
119
 
    //! Pointer to the qgis application mainwindow
120
 
    QgisApp *qgisApp;
121
 
    PGconn *pd;
122
 
    static const int context_id = 939347163;
123
 
};
124
 
 
125
 
 
126
 
// Perhaps this class should be in its own file??
127
 
//
128
 
// A class that determines the geometry type of a given database 
129
 
// schema.table.column, with the option of doing so in a separate
130
 
// thread.
131
 
 
132
 
class QgsGeomColumnTypeThread : public QThread
133
 
{
134
 
  Q_OBJECT
135
 
 public:
136
 
 
137
 
  void setConnInfo(QString s);
138
 
  void setGeometryColumn(QString schema, QString table, QString column);
139
 
 
140
 
  // These functions get the layer types and pass that information out
141
 
  // by emitting the setLayerType() signal. The getLayerTypes()
142
 
  // function does the actual work, but use the run() function if you
143
 
  // want the work to be done as a separate thread from the calling
144
 
  // process. 
145
 
  virtual void run() { getLayerTypes(); }
146
 
  void getLayerTypes();
147
 
 
148
 
  signals:
149
 
  void setLayerType(QString schema, QString table, QString column,
150
 
                    QString type);
151
 
 
152
 
 private:
153
 
  QString mConnInfo;
154
 
  std::vector<QString> schemas, tables, columns;
155
 
};
156
 
 
157
 
#endif // QGSDBSOURCESELECT_H