From aee8377388d0bb7311a436ffb54bd55695ad77c9 Mon Sep 17 00:00:00 2001 From: gsherman Date: Sat, 20 Jul 2002 22:09:32 +0000 Subject: [PATCH] fixed edit of connections git-svn-id: http://svn.osgeo.org/qgis/trunk@36 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgsdbsourceselect.cpp | 14 ++++------- src/qgsnewconnection.cpp | 49 ++++++++++++++++++++++++--------------- src/qgsnewconnection.h | 2 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/qgsdbsourceselect.cpp b/src/qgsdbsourceselect.cpp index cfcebb84861..3cbb1c5db38 100644 --- a/src/qgsdbsourceselect.cpp +++ b/src/qgsdbsourceselect.cpp @@ -33,16 +33,10 @@ void QgsDbSourceSelect::addNewConnection(){ } void QgsDbSourceSelect::editConnection(){ - QgsNewConnection *nc = new QgsNewConnection(); - // populate the fields with the stored setting parameters - QSettings settings; + QgsNewConnection *nc = new QgsNewConnection(cmbConnections->currentText()); - QString key = "/Qgis/connections/" + cmbConnections->currentText(); - QString host = settings.readEntry(key+"/host"); - QString database = settings.readEntry(key+"/database"); - QString username = settings.readEntry(key+"/username"); - QString password = settings.readEntry(key+"/password"); if(nc->exec()){ + nc->saveConnection(); } } void QgsDbSourceSelect::addTables(){ @@ -56,7 +50,7 @@ void QgsDbSourceSelect::addTables(){ void QgsDbSourceSelect::dbConnect(){ // populate the table list QSettings settings; - + QString key = "/Qgis/connections/" + cmbConnections->currentText(); QString host = "host="+settings.readEntry(key+"/host"); QString database = "dbname="+settings.readEntry(key+"/database"); @@ -67,6 +61,8 @@ void QgsDbSourceSelect::dbConnect(){ PgDatabase *pd = new PgDatabase((const char *)m_connInfo); cout << pd->ErrorMessage(); if(pd->Status()==CONNECTION_OK){ + // clear the existing entries + lstTables->clear(); // create the pixmaps for the layer types QPixmap pxPoint; pxPoint = QPixmap(point_layer_xpm); diff --git a/src/qgsnewconnection.cpp b/src/qgsnewconnection.cpp index a2e21da3a4f..a31ef93bc2e 100644 --- a/src/qgsnewconnection.cpp +++ b/src/qgsnewconnection.cpp @@ -2,35 +2,46 @@ #include #include #include +#include "libpq++.h" #include "qgsnewconnection.h" -QgsNewConnection::QgsNewConnection():QgsNewConnectionBase(){ +QgsNewConnection::QgsNewConnection(QString connName):QgsNewConnectionBase(){ + if(!connName.isEmpty()){ + // populate the dialog with the information stored for the connection + // populate the fields with the stored setting parameters + QSettings settings; + + QString key = "/Qgis/connections/" +connName; + txtHost->setText(settings.readEntry(key+"/host")); + txtDatabase->setText(settings.readEntry(key+"/database")); + txtUsername->setText(settings.readEntry(key+"/username")); + txtPassword->setText(settings.readEntry(key+"/password")); + txtName->setText(connName); + } } QgsNewConnection::~QgsNewConnection(){ } void QgsNewConnection::testConnection(){ - QSqlDatabase *testCon = QSqlDatabase::addDatabase("QPSQL7","testconnection"); - if(testCon){ - testCon->setDatabaseName(txtDatabase->text()); - testCon->setUserName(txtUsername->text()); - testCon->setPassword(txtPassword->text()); - testCon->setHostName(txtHost->text()); - if ( testCon->open() ) { - // Database successfully opened; we can now issue SQL commands. - QMessageBox::information(this,"Test connection","Connection to " + - txtDatabase->text() + " was successfull"); - }else{ - QMessageBox::information(this,"Test connection", - "Connection failed - Check settings and try again "); - } - + // following line uses Qt SQL plugin - currently not used + // QSqlDatabase *testCon = QSqlDatabase::addDatabase("QPSQL7","testconnection"); + QString connInfo = "host=" + txtHost->text() +" dbname=" + txtDatabase->text() + " user=" + txtUsername->text() + " password=" + txtPassword->text(); + PgDatabase *pd = new PgDatabase((const char *)connInfo); +cout << pd->ErrorMessage(); + if(pd->Status()==CONNECTION_OK){ + // Database successfully opened; we can now issue SQL commands. + QMessageBox::information(this,"Test connection","Connection to " + + txtDatabase->text() + " was successfull"); + }else{ + QMessageBox::information(this,"Test connection", + "Connection failed - Check settings and try again "); } - // testCon->close(); - //delete testCon; + delete pd; + - // } + + void QgsNewConnection::saveConnection(){ QSettings settings; diff --git a/src/qgsnewconnection.h b/src/qgsnewconnection.h index 65e895a0af2..d2190e9d16d 100644 --- a/src/qgsnewconnection.h +++ b/src/qgsnewconnection.h @@ -9,7 +9,7 @@ class QgsNewConnection : public QgsNewConnectionBase { public: //! Constructor - QgsNewConnection(); + QgsNewConnection(QString connName= QString::null); //! Destructor ~QgsNewConnection(); //! Tests the connection using the parameters supplied