[QGIS Commit] r8367 - trunk/qgis/src/plugins/spit
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Apr 17 11:10:44 EDT 2008
Author: jef
Date: 2008-04-17 11:10:44 -0400 (Thu, 17 Apr 2008)
New Revision: 8367
Removed:
trunk/qgis/src/plugins/spit/qgsconnectiondialog.cpp
trunk/qgis/src/plugins/spit/qgsconnectiondialog.h
trunk/qgis/src/plugins/spit/qgsconnectiondialogbase.ui
Modified:
trunk/qgis/src/plugins/spit/CMakeLists.txt
trunk/qgis/src/plugins/spit/qgsspit.cpp
trunk/qgis/src/plugins/spit/qgsspit.h
trunk/qgis/src/plugins/spit/qgsspitbase.ui
Log:
spit plugin update
Modified: trunk/qgis/src/plugins/spit/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/spit/CMakeLists.txt 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/CMakeLists.txt 2008-04-17 15:10:44 UTC (rev 8367)
@@ -4,7 +4,7 @@
SET (SPIT_SRCS
qgsspit.cpp
- qgsconnectiondialog.cpp
+ ../../app/qgsnewconnection.cpp
qgspgutil.cpp
qgsshapefile.cpp
)
@@ -20,7 +20,7 @@
)
SET (SPIT_UIS
- qgsconnectiondialogbase.ui
+ ../../ui/qgsnewconnectionbase.ui
qgsspitbase.ui
../../ui/qgsmessageviewer.ui
)
@@ -28,7 +28,7 @@
SET (SPIT_EXE_MOC_HDRS
qgsspit.h
qgsshapefile.h
- qgsconnectiondialog.h
+ ../../app/qgsnewconnection.h
)
SET (SPIT_PLUGIN_MOC_HDRS
@@ -54,6 +54,8 @@
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/raster ../../core/renderer ../../core/symbology
../../gui
+ ../../ui
+ ../../app
..
${POSTGRES_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
Deleted: trunk/qgis/src/plugins/spit/qgsconnectiondialog.cpp
===================================================================
--- trunk/qgis/src/plugins/spit/qgsconnectiondialog.cpp 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsconnectiondialog.cpp 2008-04-17 15:10:44 UTC (rev 8367)
@@ -1,100 +0,0 @@
-/***************************************************************************
- qgsconnectiondialog.cpp - description
- -------------------
- begin : Thu Dec 10 2003
- copyright : (C) 2003 by Denis Antipov
- email :
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-// $Id$
-
-#include <iostream>
-
-#include <QSettings>
-#include <QMessageBox>
-
-extern "C"
-{
- #include <libpq-fe.h>
-}
-
-#include "qgsconnectiondialog.h"
-#include "qgsmessageviewer.h"
-#include "qgsdatasourceuri.h"
-
-QgsConnectionDialog::QgsConnectionDialog(QWidget *parent, const QString& connName, Qt::WFlags fl)
- : QDialog(parent, fl)
-{
- setupUi(this);
- if (!connName.isEmpty()) {
- QSettings settings;
- QString key = "/PostgreSQL/connections/" + connName;
- txtHost->setText(settings.readEntry(key + "/host"));
- txtDatabase->setText(settings.readEntry(key + "/database"));
- if(settings.readEntry(key + "/port").length() ==0){
- txtPort->setText("5432");
- }
- else {
- txtPort->setText(settings.readEntry(key + "/port"));
- }
- txtUsername->setText(settings.readEntry(key + "/username"));
- if(settings.readEntry(key + "/save") == "true"){
- txtPassword->setText(settings.readEntry(key + "/password"));
- chkStorePassword->setChecked(true);
- }
- txtName->setText(connName);
- }
-}
-
-QgsConnectionDialog::~QgsConnectionDialog()
-{
-
-}
-
-
-void QgsConnectionDialog::testConnection()
-{
- QgsDataSourceURI uri;
- uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
- PGconn *pd = PQconnectdb((const char *) uri.connInfo() );
-
- if (PQstatus(pd) == CONNECTION_OK) {
- // Database successfully opened; we can now issue SQL commands.
- QMessageBox::information(this, tr("Test connection"), tr("Connection to ") + txtDatabase->text() + tr(" was successfull"));
- } else {
- QMessageBox::information(this, tr("Test connection"), tr("Connection failed - Check settings and try again "));
- }
-
- PQfinish(pd);
-}
-
-void QgsConnectionDialog::saveConnection()
-{
- QSettings settings;
- QString baseKey = "/PostgreSQL/connections/";
- baseKey += txtName->text();
- settings.writeEntry(baseKey + "/host", txtHost->text());
- settings.writeEntry(baseKey + "/database", txtDatabase->text());
- settings.writeEntry(baseKey + "/port", txtPort->text());
- settings.writeEntry(baseKey + "/username", txtUsername->text());
- settings.writeEntry(baseKey + "/password", txtPassword->text());
- if(chkStorePassword->isChecked()) settings.writeEntry(baseKey + "/save", "true");
- else settings.writeEntry(baseKey + "/save", "false");
- accept();
-}
-
-void QgsConnectionDialog::helpInfo(){
- QString message = tr("General Interface Help:\n\n");
- QgsMessageViewer * e = new QgsMessageViewer(this);
- e->setMessageAsPlainText(message);
- e->exec(); // deletes itself on close
-}
Deleted: trunk/qgis/src/plugins/spit/qgsconnectiondialog.h
===================================================================
--- trunk/qgis/src/plugins/spit/qgsconnectiondialog.h 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsconnectiondialog.h 2008-04-17 15:10:44 UTC (rev 8367)
@@ -1,45 +0,0 @@
-/***************************************************************************
- qgsconnectiondialog.h - description
- -------------------
- begin : Thu Dec 10 2003
- copyright : (C) 2003 by Denis Antipov
- email :
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#ifndef QGSCONNECTIONDIALOG_H
-#define QGSCONNECTIONDIALOG_H
-
-// $Id$
-
-#include "ui_qgsconnectiondialogbase.h"
-#include "qgisgui.h"
-
-class QgsConnectionDialog : public QDialog, private Ui::QgsConnectionDialogBase
-{
- Q_OBJECT
- public:
-
- QgsConnectionDialog(QWidget *parent = 0, const QString& connName = QString::null, Qt::WFlags fl = QgisGui::ModalDialogFlags);
- ~QgsConnectionDialog();
- void testConnection();
- void saveConnection();
- void helpInfo();
-
-public slots:
-
- void on_buttonBox_accepted() { saveConnection(); }
- void on_buttonBox_rejected() { reject(); }
- void on_buttonBox_helpRequested() { helpInfo(); }
- void on_btnConnect_clicked() { testConnection(); }
-};
-
-#endif
Deleted: trunk/qgis/src/plugins/spit/qgsconnectiondialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/spit/qgsconnectiondialogbase.ui 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsconnectiondialogbase.ui 2008-04-17 15:10:44 UTC (rev 8367)
@@ -1,196 +0,0 @@
-<ui version="4.0" >
- <class>QgsConnectionDialogBase</class>
- <widget class="QDialog" name="QgsConnectionDialogBase" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>348</width>
- <height>332</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Create a New PostGIS connection</string>
- </property>
- <property name="sizeGripEnabled" >
- <bool>true</bool>
- </property>
- <property name="modal" >
- <bool>true</bool>
- </property>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QGroupBox" name="groupBox" >
- <property name="title" >
- <string>Connection Information</string>
- </property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="1" column="0" >
- <layout class="QHBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QCheckBox" name="chkStorePassword" >
- <property name="text" >
- <string>Save Password</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="btnConnect" >
- <property name="text" >
- <string>Test Connect</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="0" column="0" >
- <layout class="QHBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QLabel" name="TextLabel1_2" >
- <property name="text" >
- <string>Name</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="TextLabel1" >
- <property name="text" >
- <string>Host</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="TextLabel2" >
- <property name="text" >
- <string>Database</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="TextLabel2_2" >
- <property name="text" >
- <string>Port</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="TextLabel3" >
- <property name="text" >
- <string>Username</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="TextLabel3_2" >
- <property name="text" >
- <string>Password</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item>
- <widget class="QLineEdit" name="txtName" >
- <property name="toolTip" >
- <string>Name of the new connection</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="txtHost" />
- </item>
- <item>
- <widget class="QLineEdit" name="txtDatabase" />
- </item>
- <item>
- <widget class="QLineEdit" name="txtPort" >
- <property name="text" >
- <string>5432</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="txtUsername" />
- </item>
- <item>
- <widget class="QLineEdit" name="txtPassword" >
- <property name="echoMode" >
- <enum>QLineEdit::Password</enum>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <layoutdefault spacing="6" margin="11" />
- <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
- <tabstops>
- <tabstop>txtName</tabstop>
- <tabstop>txtHost</tabstop>
- <tabstop>txtDatabase</tabstop>
- <tabstop>txtPort</tabstop>
- <tabstop>txtUsername</tabstop>
- <tabstop>txtPassword</tabstop>
- <tabstop>chkStorePassword</tabstop>
- <tabstop>btnConnect</tabstop>
- <tabstop>buttonBox</tabstop>
- </tabstops>
- <resources/>
- <connections/>
-</ui>
Modified: trunk/qgis/src/plugins/spit/qgsspit.cpp
===================================================================
--- trunk/qgis/src/plugins/spit/qgsspit.cpp 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsspit.cpp 2008-04-17 15:10:44 UTC (rev 8367)
@@ -28,6 +28,7 @@
#include <QTextCodec>
#include <QList>
#include <QTableWidgetItem>
+#include <QInputDialog>
#include <iostream>
@@ -35,7 +36,7 @@
#include "qgspgutil.h"
#include "qgsspit.h"
-#include "qgsconnectiondialog.h"
+#include "qgsnewconnection.h"
#include "qgsdatasourceuri.h"
#include "qgsmessageviewer.h"
#include "spiticon.xpm"
@@ -85,9 +86,8 @@
txtPrimaryKeyName->setText("gid");
schema_list << "public";
- gl_key = "/PostgreSQL/connections/";
- getSchema();
-
+ conn = NULL;
+
// Install a delegate that provides the combo box widget for
// changing the schema (but there can only be one delegate per
// table, so it also provides edit widgets for the textual columns).
@@ -102,6 +102,8 @@
QgsSpit::~QgsSpit()
{
+ if(conn)
+ PQfinish(conn);
}
void QgsSpit::populateConnectionList()
@@ -119,25 +121,22 @@
void QgsSpit::newConnection()
{
- QgsConnectionDialog * con = new QgsConnectionDialog( this, tr("New Connection") );
+ QgsNewConnection *nc = new QgsNewConnection(this);
- if ( con->exec() )
+ if (nc->exec())
{
populateConnectionList();
- getSchema();
}
- delete con;
}
void QgsSpit::editConnection()
{
- QgsConnectionDialog * con = new QgsConnectionDialog( this, cmbConnections->currentText() );
- if ( con->exec() )
+ QgsNewConnection *nc = new QgsNewConnection(this, cmbConnections->currentText());
+
+ if (nc->exec())
{
- con->saveConnection();
- getSchema();
+ nc->saveConnection();
}
- delete con;
}
void QgsSpit::removeConnection()
@@ -155,8 +154,7 @@
settings.removeEntry( key + "/password" );
settings.removeEntry( key + "/save" );
- cmbConnections->removeItem( cmbConnections->currentItem() );
- getSchema();
+ cmbConnections->removeItem( cmbConnections->currentItem() );
}
}
@@ -379,35 +377,65 @@
e->exec(); // deletes itself on close
}
-PGconn* QgsSpit::checkConnection()
+void QgsSpit::dbConnect()
{
+ if(conn)
+ {
+ PQfinish(conn);
+ conn=NULL;
+ }
+
QSettings settings;
- PGconn * pd;
- bool result = true;
QString connName = cmbConnections->currentText();
if ( connName.isEmpty() )
{
QMessageBox::warning( this, tr("Import Shapefiles"), tr("You need to specify a Connection first") );
- result = false;
+ return;
}
- else
+
+ QString key = "/PostgreSQL/connections/" + connName;
+ QString database = settings.readEntry(key + "/database");
+ QString username = settings.readEntry(key + "/username");
+ QString password = settings.readEntry(key + "/password");
+
+ bool makeConnection = true;
+
+ if ( password.isEmpty() )
{
+ // get password from user
+ password = QInputDialog::getText(tr("Password for ") + username,
+ tr("Please enter your password:"),
+ QLineEdit::Password, QString::null, &makeConnection, this);
+ }
+
+ if(makeConnection)
+ {
+ // allow null password entry in case its valid for the database
QgsDataSourceURI uri;
- uri.setConnection( settings.readEntry( gl_key + connName + "/host" ),
- settings.readEntry( gl_key + connName + "/port" ),
- settings.readEntry( gl_key + connName + "/database" ),
- settings.readEntry( gl_key + connName + "/username" ),
- settings.readEntry( gl_key + connName + "/password" ) );
+ uri.setConnection( settings.readEntry(key + "/host"),
+ settings.readEntry(key + "/port"),
+ database,
+ settings.readEntry(key + "/username"),
+ password );
+
+ conn = PQconnectdb( ( const char * ) uri.connInfo() );
+ }
- pd = PQconnectdb( ( const char * ) uri.connInfo() );
-
- if ( PQstatus( pd ) != CONNECTION_OK )
- {
- QMessageBox::warning( this, tr("Import Shapefiles"), tr("Connection failed - Check settings and try again") );
- result = false;
+ if( conn==NULL || PQstatus(conn)!=CONNECTION_OK )
+ {
+ QMessageBox::warning( this, tr("Import Shapefiles"), tr("Connection failed - Check settings and try again") );
+ if(conn) {
+ PQfinish(conn);
+ conn=0;
}
+ }
- int errcode=PQsetClientEncoding(pd, QString("UNICODE").toLocal8Bit());
+ schema_list.clear();
+ schema_list << "public";
+
+ if(conn)
+ {
+ int errcode=PQsetClientEncoding(conn, QString("UNICODE").toLocal8Bit());
if(errcode==0)
{
QgsDebugMsg("encoding successfully set");
@@ -420,48 +448,29 @@
{
QgsDebugMsg("undefined return value from encoding setting");
}
- }
- if (result )
- {
// Check that the database actually has postgis in it.
QString sql1 = "SELECT postgis_lib_version()"; // available from v 0.9.0 onwards
QString sql2 = "SELECT postgis_version()"; // depreciated
- PGresult* ver = PQexec(pd, sql1.toUtf8() );
+ PGresult* ver = PQexec(conn, sql1.toUtf8() );
if ( PQresultStatus(ver) != PGRES_TUPLES_OK)
{
// In case the version of postgis is older than 0.9.0, try the
// depreciated call before erroring out.
PQclear(ver);
- ver = PQexec(pd, sql2.toUtf8() );
+ ver = PQexec(conn, sql2.toUtf8() );
if ( PQresultStatus(ver) != PGRES_TUPLES_OK)
{
QMessageBox::warning( this, tr("PostGIS not available"),
tr("<p>The chosen database does not have PostGIS installed, "
"but this is required for storage of spatial data.</p>"));
- return NULL;
}
}
- return pd;
- }
- else
- return NULL;
-}
-void QgsSpit::getSchema()
-{
- QSettings settings;
- schema_list.clear();
- schema_list << "public";
- PGconn* pd = checkConnection();
- if ( pd != NULL )
- {
- QString connName = cmbConnections->currentText();
- QString user = settings.readEntry( gl_key + connName + "/username" );
QString schemaSql = QString( "select nspname from pg_namespace,pg_user where nspowner=usesysid and usename=%1" )
- .arg( QgsPgUtil::quotedValue(user) );
- PGresult *schemas = PQexec( pd, schemaSql.toUtf8() );
+ .arg( QgsPgUtil::quotedValue(username) );
+ PGresult *schemas = PQexec( conn, schemaSql.toUtf8() );
// get the schema names
if ( PQresultStatus( schemas ) == PGRES_TUPLES_OK )
{
@@ -474,8 +483,6 @@
PQclear( schemas );
}
- PQfinish(pd);
-
// install a new delegate with an updated schema list (rather than
// update the existing delegate because delegates don't seem able to
// store modifiable data).
@@ -487,15 +494,6 @@
cmbSchema->setCurrentIndex( 0 ); // index 0 is always "public"
}
-void QgsSpit::updateSchema()
-{
- // install a new delegate with an updated schema list (rather than
- // update the existing delegate because delegates don't seem able to
- // store modifiable data).
- ShapefileTableDelegate* delegate = new ShapefileTableDelegate(tblShapefiles, schema_list);
- tblShapefiles->setItemDelegate(delegate);
-}
-
void QgsSpit::import()
{
QList<QTableWidgetItem*> selected = tblShapefiles->selectedItems();
@@ -505,15 +503,14 @@
QString connName = cmbConnections->currentText();
QSettings settings;
bool canceled = false;
- PGconn* pd = checkConnection();
- QString query;
+ QString query;
if ( total_features == 0 )
{
QMessageBox::warning( this, tr("Import Shapefiles"),
tr("You need to add shapefiles to the list first") );
}
- else if ( pd != NULL )
+ else if ( conn != NULL )
{
PGresult * res;
QProgressDialog pro( tr("Importing files"), tr("Cancel"),
@@ -585,7 +582,7 @@
query = QString("SELECT f_table_name FROM geometry_columns WHERE f_table_name=%1 AND f_table_schema=%2")
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text()) )
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text()) );
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
rel_exists1 = ( PQntuples( res ) > 0 );
if ( PQresultStatus( res ) != PGRES_TUPLES_OK )
@@ -605,7 +602,7 @@
query = QString("SELECT tablename FROM pg_tables WHERE tablename=%1 AND schemaname=%2")
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) )
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) );
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
rel_exists2 = ( PQntuples( res ) > 0 );
@@ -628,7 +625,7 @@
// begin session
query = "BEGIN";
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -649,7 +646,7 @@
if ( tblShapefiles->item( i, ColDBSCHEMA )->text() != "public" )
query += QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) + ",";
query += QgsPgUtil::quotedValue( "public" );
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
@@ -684,7 +681,7 @@
query = QString("DROP TABLE %1")
.arg( QgsPgUtil::quotedIdentifier( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) );
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -709,7 +706,7 @@
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text()) );
QStringList columns;
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if( PQresultStatus( res ) != PGRES_TUPLES_OK )
{
for(int i=0; i<PQntuples(res); i++)
@@ -724,7 +721,7 @@
.arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) )
.arg( QgsPgUtil::quotedValue( columns[i] ) );
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -742,7 +739,7 @@
else
{
query = "ROLLBACK";
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -762,16 +759,17 @@
int temp_progress = pro.value();
canceled = false;
- QString dbname = settings.readEntry( gl_key + connName + "/database" );
+ QString key = "/PostgreSQL/connections/" + connName;
+ QString dbname = settings.readEntry( key + "/database" );
QString schema = tblShapefiles->item( i, ColDBSCHEMA )->text();
QString srid = QString( "%1" ).arg( spinSrid->value() );
QString errorText;
- bool layerInserted = fileList[i]->insertLayer(dbname, schema, txtPrimaryKeyName->text(), txtGeomName->text(), srid, pd, pro, canceled, errorText );
+ bool layerInserted = fileList[i]->insertLayer(dbname, schema, txtPrimaryKeyName->text(), txtGeomName->text(), srid, conn, pro, canceled, errorText );
if ( layerInserted && !canceled )
{ // if file has been imported successfully
query = "COMMIT";
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -805,7 +803,7 @@
QString errTxt = error + "\n" + errorText;
QMessageBox::warning( this, tr("Import Shapefiles"), errTxt );
query = "ROLLBACK";
- res = PQexec( pd, query.toUtf8() );
+ res = PQexec( conn, query.toUtf8() );
if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
QString err = PQresultErrorMessage( res );
@@ -822,27 +820,18 @@
break;
}
}
- PQfinish( pd );
if(successes==count)
accept();
else
QMessageBox::information( &pro, tr("Import Shapefiles"), QString( tr("%1 of %2 shapefiles could not be imported.") ).arg(count-successes).arg(count) );
}
-}
-
-void QgsSpit::editShapefile(int row, int col, int button, const QPoint& mousePos)
-{
- // FIXME Is this necessary any more?
- /*
- if (ColFEATURECLASS == col || ColDBRELATIONNAME == col)
+ else
{
- tblShapefiles->editCell(row, col, FALSE);
+ QMessageBox::warning( this, tr("Import Shapefiles"), tr("You need to specify a Connection first") );
}
- */
}
-
QWidget *ShapefileTableDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & index) const
Modified: trunk/qgis/src/plugins/spit/qgsspit.h
===================================================================
--- trunk/qgis/src/plugins/spit/qgsspit.h 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsspit.h 2008-04-17 15:10:44 UTC (rev 8367)
@@ -44,7 +44,7 @@
//! Populate the list of available database connections
void populateConnectionList();
//! Connect to the selected database
- void dbConnect() {};
+ void dbConnect();
//! Return a list of selected tables
QStringList selectedTables();
//! Return the connection info
@@ -67,13 +67,8 @@
void useDefaultGeom();
//! Show brief help
void helpInfo();
- //! Get schemas available in the database
- void getSchema();
- void updateSchema();
//! Import shapefiles into PostgreSQL
void import();
- //! Edit import properties of a shapefile in the queue
- void editShapefile( int, int, int, const QPoint & );
public slots:
@@ -95,7 +90,6 @@
void on_tblShapefiles_itemClicked(QTableWidgetItem* item)
{ tblShapefiles->editItem(item); }
// When the user changes the selected connection, update the schema list
- void on_cmbConnections_activated(int) { getSchema(); }
void on_chkUseDefaultSrid_toggled(bool) { useDefaultSrid(); }
void on_chkUseDefaultGeom_toggled(bool) { useDefaultGeom(); }
@@ -120,7 +114,7 @@
QString defGeom;
int defaultSridValue;
QString defaultGeomValue;
- QString gl_key;
+ PGconn *conn;
};
// We want to provide combo boxes in the table of shape files to
Modified: trunk/qgis/src/plugins/spit/qgsspitbase.ui
===================================================================
--- trunk/qgis/src/plugins/spit/qgsspitbase.ui 2008-04-17 15:07:48 UTC (rev 8366)
+++ trunk/qgis/src/plugins/spit/qgsspitbase.ui 2008-04-17 15:10:44 UTC (rev 8367)
@@ -55,7 +55,7 @@
</property>
<layout class="QGridLayout" >
<property name="margin" >
- <number>9</number>
+ <number>11</number>
</property>
<property name="spacing" >
<number>6</number>
@@ -122,6 +122,19 @@
</property>
</widget>
</item>
+ <item row="1" column="0" >
+ <widget class="QPushButton" name="btnConnect" >
+ <property name="toolTip" >
+ <string>Connect to PostGIS</string>
+ </property>
+ <property name="whatsThis" >
+ <string>Connect to PostGIS</string>
+ </property>
+ <property name="text" >
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
More information about the QGIS-commit
mailing list