Skip to content

Commit 4de591b

Browse files
author
g_j_m
committed
- Thread option actually creates a thread now
- Efficiency improvements (mostly caching of data) - Bug fix for incorrect table display when changing databases - Close PG connections when a new one is created - Recgonise more PG geometry types - Icon for PG GEOMETRY geometry types git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5043 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 998c01d commit 4de591b

File tree

3 files changed

+60
-40
lines changed

3 files changed

+60
-40
lines changed
964 Bytes
Loading

src/gui/qgsdbsourceselect.cpp

+57-40
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ email : sherman at mrcc.com
3131
#include <QTextOStream>
3232
#include <QTableWidgetItem>
3333
#include <QHeaderView>
34+
#include <QStringList>
3435

3536
#include <cassert>
3637
#include <iostream>
3738

3839
QgsDbSourceSelect::QgsDbSourceSelect(QgisApp *app, Qt::WFlags fl)
39-
: QDialog(app, fl), qgisApp(app), mColumnTypeThread(NULL)
40+
: QDialog(app, fl), qgisApp(app), mColumnTypeThread(NULL), pd(0)
4041
{
4142
setupUi(this);
4243
btnAdd->setEnabled(false);
@@ -104,11 +105,12 @@ QgsDbSourceSelect::QgsDbSourceSelect(QgisApp *app, Qt::WFlags fl)
104105

105106
// Do some things that couldn't be done in designer
106107
lstTables->horizontalHeader()->setStretchLastSection(true);
107-
QStringList labels;
108108
// Set the column count to 3 for the type, name, and sql
109109
lstTables->setColumnCount(3);
110-
labels += tr("Type"); labels += tr("Name"); labels += tr("Sql");
111-
lstTables->setHorizontalHeaderLabels(labels);
110+
mColumnLabels += tr("Type");
111+
mColumnLabels += tr("Name");
112+
mColumnLabels += tr("Sql");
113+
lstTables->setHorizontalHeaderLabels(mColumnLabels);
112114
lstTables->verticalHeader()->hide();
113115
}
114116
/** Autoconnected SLOTS **/
@@ -324,43 +326,65 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
324326
{
325327
m_connInfo = connString; //host + " " + database + " " + username + " " + password;
326328
//qDebug(m_connInfo);
329+
// Tidy up an existing connection if one exists.
330+
if (pd != 0)
331+
PQfinish(pd);
332+
327333
pd = PQconnectdb(m_connInfo.toLocal8Bit().data());
328334
// std::cout << pd->ErrorMessage();
329335
if (PQstatus(pd) == CONNECTION_OK)
330336
{
331-
// create the pixmaps for the layer types
332-
QString myThemePath = QgsApplication::themePath();
333-
mLayerIcons.insert(QString("POINT"),
334-
qMakePair(tr("Point layer"),
335-
QIcon(myThemePath+"/mIconPointLayer.png")));
336-
mLayerIcons.insert(QString("MULTIPOINT"),
337-
qMakePair(tr("Multi-point layer"),
338-
QIcon(myThemePath+"/mIconPointLayer.png")));
339-
mLayerIcons.insert(QString("LINESTRING"),
340-
qMakePair(tr("Linestring layer"),
341-
QIcon(myThemePath+"/mIconLineLayer.png")));
342-
mLayerIcons.insert(QString("MULTILINESTRING"),
343-
qMakePair(tr("Multi-linestring layer"),
344-
QIcon(myThemePath+"/mIconLineLayer.png")));
345-
mLayerIcons.insert(QString("POLYGON"),
346-
qMakePair(tr("Polygon layer"),
347-
QIcon(myThemePath+"/mIconPolygonLayer.png")));
348-
mLayerIcons.insert(QString("MULTIPOLYGON"),
349-
qMakePair(tr("Multi-polygon layer"),
350-
QIcon(myThemePath+"/mIconPolygonLayer.png")));
351-
mLayerIcons.insert(QString("WAITING"),
352-
qMakePair(tr("Waiting for layer type"),
353-
QIcon(myThemePath+"/mIconWaitingForLayerType.png")));
354-
mLayerIcons.insert(QString("UNKNOWN"),
355-
qMakePair(tr("Unknown layer type"),
356-
QIcon(myThemePath+"/mIconUnknownLayerType.png")));
357-
337+
// create the pixmaps for the layer types if we haven't already
338+
// done so.
339+
if (mLayerIcons.count() == 0)
340+
{
341+
QString myThemePath = QgsApplication::themePath();
342+
mLayerIcons.insert("POINT",
343+
qMakePair(tr("Point layer"),
344+
QIcon(myThemePath+"/mIconPointLayer.png")));
345+
mLayerIcons.insert("MULTIPOINT",
346+
qMakePair(tr("Multi-point layer"),
347+
mLayerIcons.value("POINT").second));
348+
349+
mLayerIcons.insert("LINESTRING",
350+
qMakePair(tr("Linestring layer"),
351+
QIcon(myThemePath+"/mIconLineLayer.png")));
352+
mLayerIcons.insert("MULTILINESTRING",
353+
qMakePair(tr("Multi-linestring layer"),
354+
mLayerIcons.value("LINESTRING").second));
355+
356+
mLayerIcons.insert("POLYGON",
357+
qMakePair(tr("Polygon layer"),
358+
QIcon(myThemePath+"/mIconPolygonLayer.png")));
359+
mLayerIcons.insert("MULTIPOLYGON",
360+
qMakePair(tr("Multi-polygon layer"),
361+
mLayerIcons.value("POLYGON").second));
362+
363+
mLayerIcons.insert("GEOMETRY",
364+
qMakePair(tr("Mixed geometry layer"),
365+
QIcon(myThemePath+"/mIconGeometryLayer.png")));
366+
mLayerIcons.insert("GEOMETRYCOLLECTION",
367+
qMakePair(tr("Geometry collection layer"),
368+
mLayerIcons.value("GEOMETRY").second));
369+
370+
mLayerIcons.insert("WAITING",
371+
qMakePair(tr("Waiting for layer type"),
372+
QIcon(myThemePath+"/mIconWaitingForLayerType.png")));
373+
mLayerIcons.insert("UNKNOWN",
374+
qMakePair(tr("Unknown layer type"),
375+
QIcon(myThemePath+"/mIconUnknownLayerType.png")));
376+
}
358377
//qDebug("Connection succeeded");
359378
// tell the DB that we want text encoded in UTF8
360379
PQsetClientEncoding(pd, "UNICODE");
361380

362-
// clear the existing entries
381+
// Here's an annoying thing... calling clear() removes the
382+
// header items too, so we need to reinstate them after calling
383+
// clear().
363384
lstTables->clear();
385+
lstTables->setRowCount(0);
386+
lstTables->setHorizontalHeaderLabels(mColumnLabels);
387+
364388
// get the list of suitable tables and columns and populate the UI
365389
geomCol details;
366390
if (getGeometryColumnInfo(pd, details))
@@ -395,13 +419,6 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
395419
lstTables->setItem(row, 1, textItem);
396420
}
397421
}
398-
// For some reason not clear to me, the table header labels
399-
// set in the constructor have reverted to '1', '2', and '3'
400-
// by here. Hence we reset them. This seems like a bug in Qt
401-
// (4.1.1).
402-
QStringList labels;
403-
labels += tr("Type"); labels += tr("Name"); labels += tr("Sql");
404-
lstTables->setHorizontalHeaderLabels(labels);
405422

406423
// And tidy up the columns & rows
407424
lstTables->resizeColumnsToContents();
@@ -420,7 +437,7 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
420437
// completes, nor the qgis process ending before the
421438
// thread completes, nor does the thread know to stop working
422439
// when the user chooses a layer.
423-
// mColumnTypeThread->run();
440+
//mColumnTypeThread->start();
424441

425442
// do it in this process for the moment.
426443
mColumnTypeThread->getLayerTypes();

src/gui/qgsdbsourceselect.h

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C"
3333
#include <QPair>
3434
#include <QIcon>
3535

36+
class QStringList;
3637
class QTableWidgetItem;
3738
class QgsGeomColumnTypeThread;
3839
class QgisApp;
@@ -103,6 +104,8 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
103104
// Combine the schema, table and column data into a single string
104105
// useful for display to the user
105106
QString fullDescription(QString schema, QString table, QString column);
107+
// The column labels
108+
QStringList mColumnLabels;
106109
// Our thread for doing long running queries
107110
QgsGeomColumnTypeThread* mColumnTypeThread;
108111
QString m_connInfo;

0 commit comments

Comments
 (0)