1
/***************************************************************************
2
qgdbsourceselect.h - description
4
begin : Sat Jun 22 2002
5
copyright : (C) 2002 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************/
9
/***************************************************************************
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. *
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"
38
class QTableWidgetItem;
39
class QgsGeomColumnTypeThread;
41
/*! \class QgsDbSourceSelect
42
* \brief Dialog to create connections and add tables from PostgresQL.
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.
48
class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
54
QgsDbSourceSelect(QgisApp *app, Qt::WFlags fl = QgisGui::ModalDialogFlags);
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
67
//! String list containing the selected tables
68
QStringList selectedTables();
69
//! Connection info (database, host, user, password)
71
//! Return the name of the selected encoding (e.g. UTf-8, ISO-8559-1, etc/)
73
// Store the selected database
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);
80
/*! Connects to the database using the stored connection parameters.
81
* Once connected, available layers are displayed.
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,
96
typedef std::pair<QString, QString> geomPair;
97
typedef std::list<geomPair > geomCol;
99
bool getGeometryColumnInfo(PGconn *pd,
101
bool searchGeometryColumnsOnly,
102
bool searchPublicOnly);
103
// Set the position of the database connection list to the last
105
void setConnectionListPosition();
106
// Show the context help for the dialog
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);
112
QStringList mColumnLabels;
113
// Our thread for doing long running queries
114
QgsGeomColumnTypeThread* mColumnTypeThread;
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
122
static const int context_id = 939347163;
126
// Perhaps this class should be in its own file??
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
132
class QgsGeomColumnTypeThread : public QThread
137
void setConnInfo(QString s);
138
void setGeometryColumn(QString schema, QString table, QString column);
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
145
virtual void run() { getLayerTypes(); }
146
void getLayerTypes();
149
void setLayerType(QString schema, QString table, QString column,
154
std::vector<QString> schemas, tables, columns;
157
#endif // QGSDBSOURCESELECT_H