From 57ac8f888e00beca47c5665df42b0a3602ce8887 Mon Sep 17 00:00:00 2001 From: jef Date: Sun, 13 Dec 2009 22:09:22 +0000 Subject: [PATCH] fix #2276 git-svn-id: http://svn.osgeo.org/qgis/trunk@12442 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/app/qgspgsourceselect.cpp | 44 ++++----- src/app/qgspgsourceselect.h | 5 +- src/app/qgsspatialitesourceselect.cpp | 40 +++----- src/app/qgsspatialitesourceselect.h | 11 +-- src/plugins/spit/qgsspit.cpp | 34 ++++--- src/plugins/spit/qgsspitbase.ui | 129 ++++++++++++-------------- 6 files changed, 120 insertions(+), 143 deletions(-) diff --git a/src/app/qgspgsourceselect.cpp b/src/app/qgspgsourceselect.cpp index 87041411823e..3e649846cd08 100644 --- a/src/app/qgspgsourceselect.cpp +++ b/src/app/qgspgsourceselect.cpp @@ -46,7 +46,7 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl ) mAddButton = new QPushButton( tr( "&Add" ) ); buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole ); - connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addClicked() ) ); + connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addTables() ) ); mAddButton->setEnabled( false ); populateConnectionList(); @@ -110,27 +110,20 @@ void QgsPgSourceSelect::on_btnDelete_clicked() QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" ) .arg( cmbConnections->currentText() ); QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel ); - if ( result == QMessageBox::Ok ) - { - settings.remove( key + "/host" ); - settings.remove( key + "/database" ); - settings.remove( key + "/username" ); - settings.remove( key + "/password" ); - settings.remove( key + "/port" ); - settings.remove( key + "/sslmode" ); - settings.remove( key + "/save" ); - settings.remove( key ); - //if(!success){ - // QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText()); - //} - cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList(); - setConnectionListPosition(); - } -} -// Slot for performing action when the Add button is clicked -void QgsPgSourceSelect::addClicked() -{ - addTables(); + if ( result != QMessageBox::Ok ) + return; + + settings.remove( key + "/host" ); + settings.remove( key + "/database" ); + settings.remove( key + "/username" ); + settings.remove( key + "/password" ); + settings.remove( key + "/port" ); + settings.remove( key + "/sslmode" ); + settings.remove( key + "/publicOnly" ); + settings.remove( key + "/geometryColumnsOnly" ); + settings.remove( key + "/save" ); + + populateConnectionList(); } // Slot for editing a connection @@ -280,7 +273,13 @@ void QgsPgSourceSelect::populateConnectionList() ++it; } settings.endGroup(); + setConnectionListPosition(); + + btnEdit->setDisabled( cmbConnections->count() == 0 ); + btnDelete->setDisabled( cmbConnections->count() == 0 ); + btnConnect->setDisabled( cmbConnections->count() == 0 ); + cmbConnections->setDisabled( cmbConnections->count() == 0 ); } QString QgsPgSourceSelect::layerURI( const QModelIndex &index ) @@ -337,6 +336,7 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index ) return uri; } +// Slot for performing action when the Add button is clicked void QgsPgSourceSelect::addTables() { m_selectedTables.clear(); diff --git a/src/app/qgspgsourceselect.h b/src/app/qgspgsourceselect.h index ea75a2c4ccfa..fe9bab984c43 100644 --- a/src/app/qgspgsourceselect.h +++ b/src/app/qgspgsourceselect.h @@ -111,15 +111,14 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase ~QgsPgSourceSelect(); //! Populate the connection list combo box void populateConnectionList(); - //! Determines the tables the user selected and closes the dialog - void addTables(); //! String list containing the selected tables QStringList selectedTables(); //! Connection info (database, host, user, password) QString connectionInfo(); public slots: - void addClicked(); + //! Determines the tables the user selected and closes the dialog + void addTables(); /*! Connects to the database using the stored connection parameters. * Once connected, available layers are displayed. diff --git a/src/app/qgsspatialitesourceselect.cpp b/src/app/qgsspatialitesourceselect.cpp index 4720e703915f..6d78bb49150d 100644 --- a/src/app/qgsspatialitesourceselect.cpp +++ b/src/app/qgsspatialitesourceselect.cpp @@ -71,19 +71,6 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags mSearchColumnComboBox->setCurrentIndex( 1 ); } -/** Autoconnected SLOTS **/ -// Slot for adding a new connection -void QgsSpatiaLiteSourceSelect::on_btnNew_clicked() -{ - addNewConnection(); -} - -// Slot for deleting an existing connection -void QgsSpatiaLiteSourceSelect::on_btnDelete_clicked() -{ - deleteConnection(); -} - // Slot for performing action when the Add button is clicked void QgsSpatiaLiteSourceSelect::addClicked() { @@ -297,9 +284,14 @@ void QgsSpatiaLiteSourceSelect::populateConnectionList() } settings.endGroup(); setConnectionListPosition(); + + btnConnect->setDisabled( cmbConnections->count() == 0 ); + btnDelete->setDisabled( cmbConnections->count() == 0 ); + + cmbConnections->setDisabled( cmbConnections->count() == 0 ); } -void QgsSpatiaLiteSourceSelect::addNewConnection() +void QgsSpatiaLiteSourceSelect::on_btnNew_clicked() { // Retrieve last used project dir from persistent settings sqlite3 *handle; @@ -335,7 +327,8 @@ void QgsSpatiaLiteSourceSelect::addNewConnection() populateConnectionList(); } -void QgsSpatiaLiteSourceSelect::deleteConnection() +// Slot for deleting an existing connection +void QgsSpatiaLiteSourceSelect::on_btnDelete_clicked() { QSettings settings; QString subKey = cmbConnections->currentText(); @@ -347,16 +340,13 @@ void QgsSpatiaLiteSourceSelect::deleteConnection() QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" ).arg( subKey ); QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel ); - if ( result == QMessageBox::Ok ) - { - settings.remove( key + "/sqlitepath" ); - settings.remove( key ); - //if(!success){ - // QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText()); - //} - cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList(); - setConnectionListPosition(); - } + if ( result != QMessageBox::Ok ) + return; + + settings.remove( key + "/sqlitepath" ); + settings.remove( key ); + + populateConnectionList(); } void QgsSpatiaLiteSourceSelect::addTables() diff --git a/src/app/qgsspatialitesourceselect.h b/src/app/qgsspatialitesourceselect.h index 18394410ed8d..522ba4261060 100644 --- a/src/app/qgsspatialitesourceselect.h +++ b/src/app/qgsspatialitesourceselect.h @@ -60,14 +60,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource //! Constructor QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags fl = QgisGui::ModalDialogFlags ); //! Destructor - ~QgsSpatiaLiteSourceSelect() - { - ; - } - //! Opens the create connection dialog to build a new connection - void addNewConnection(); - //! Deletes the selected connection - void deleteConnection(); + ~QgsSpatiaLiteSourceSelect() {} //! Populate the connection list combo box void populateConnectionList(); //! Determines the tables the user selected and closes the dialog @@ -85,7 +78,9 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsSpatiaLiteSource */ void on_btnConnect_clicked(); void addClicked(); + //! Opens the create connection dialog to build a new connection void on_btnNew_clicked(); + //! Deletes the selected connection void on_btnDelete_clicked(); void on_mSearchOptionsButton_clicked(); void on_mSearchTableEdit_textChanged( const QString & text ); diff --git a/src/plugins/spit/qgsspit.cpp b/src/plugins/spit/qgsspit.cpp index 8b221b0bf8a2..0691231304f5 100644 --- a/src/plugins/spit/qgsspit.cpp +++ b/src/plugins/spit/qgsspit.cpp @@ -115,6 +115,12 @@ void QgsSpit::populateConnectionList() ++it; } settings.endGroup(); + + btnConnect->setDisabled( cmbConnections->count() == 0 ); + btnEdit->setDisabled( cmbConnections->count() == 0 ); + btnRemove->setDisabled( cmbConnections->count() == 0 ); + + cmbConnections->setDisabled( cmbConnections->count() == 0 ); } void QgsSpit::newConnection() @@ -141,19 +147,21 @@ void QgsSpit::removeConnection() QString key = "/PostgreSQL/connections/" + cmbConnections->currentText(); QString msg = tr( "Are you sure you want to remove the [%1] connection and all associated settings?" ).arg( cmbConnections->currentText() ); QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel ); - if ( result == QMessageBox::Ok ) - { - settings.remove( key + "/host" ); - settings.remove( key + "/database" ); - settings.remove( key + "/port" ); - settings.remove( key + "/username" ); - settings.remove( key + "/password" ); - settings.remove( key + "/sslmode" ); - settings.remove( key + "/save" ); - settings.remove( key ); - - cmbConnections->removeItem( cmbConnections->currentIndex() ); - } + if ( result != QMessageBox::Ok ) + return; + + settings.remove( key + "/host" ); + settings.remove( key + "/database" ); + settings.remove( key + "/port" ); + settings.remove( key + "/username" ); + settings.remove( key + "/password" ); + settings.remove( key + "/sslmode" ); + settings.remove( key + "/publicOnly" ); + settings.remove( key + "/geometryColumnsOnly" ); + settings.remove( key + "/save" ); + settings.remove( key ); + + populateConnectionList(); } void QgsSpit::addFile() diff --git a/src/plugins/spit/qgsspitbase.ui b/src/plugins/spit/qgsspitbase.ui index 3b83d08f641b..3efb9be638ce 100644 --- a/src/plugins/spit/qgsspitbase.ui +++ b/src/plugins/spit/qgsspitbase.ui @@ -44,27 +44,8 @@ PostgreSQL connections - - - 11 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + @@ -74,57 +55,61 @@ - - - - Edit the current PostGIS connection - - - Edit the current PostGIS connection - - - Edit - - - - - - - Remove the current PostGIS connection - - - Remove the current PostGIS connection - - - Remove - - - - - - - Create a new PostGIS connection - - - Create a new PostGIS connection - - - New - - - - - - - Connect to PostGIS - - - Connect to PostGIS - - - Connect - - + + + + + + Connect to PostGIS + + + Connect to PostGIS + + + Connect + + + + + + + Create a new PostGIS connection + + + Create a new PostGIS connection + + + New + + + + + + + Edit the current PostGIS connection + + + Edit the current PostGIS connection + + + Edit + + + + + + + Remove the current PostGIS connection + + + Remove the current PostGIS connection + + + Remove + + + +