mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
fixed edit of connections
git-svn-id: http://svn.osgeo.org/qgis/trunk@36 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
1277cbed3b
commit
aee8377388
@ -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);
|
||||
|
@ -2,35 +2,46 @@
|
||||
#include <qsettings.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qmessagebox.h>
|
||||
#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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user