Skip to content
Permalink
Browse files

save geometry of postgresql selection dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12373 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 8, 2009
1 parent 3fd8df7 commit 405f44fd60ecc45e99f7e47598824a2ed6c31b9f
Showing with 47 additions and 67 deletions.
  1. +42 −58 src/app/qgspgsourceselect.cpp
  2. +5 −9 src/app/qgspgsourceselect.h
@@ -84,17 +84,44 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
//for Qt < 4.3.2, passing -1 to include all model columns
//in search does not seem to work
mSearchColumnComboBox->setCurrentIndex( 2 );

restoreGeometry( settings.value( "/Windows/PgSourceSelect/geometry" ).toByteArray() );
}
/** Autoconnected SLOTS **/
// Slot for adding a new connection
void QgsPgSourceSelect::on_btnNew_clicked()
{
addNewConnection();
QgsNewConnection *nc = new QgsNewConnection( this );

if ( nc->exec() )
{
populateConnectionList();
}
}
// Slot for deleting an existing connection
void QgsPgSourceSelect::on_btnDelete_clicked()
{
deleteConnection();
QSettings settings;
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 + "/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()
@@ -105,15 +132,23 @@ void QgsPgSourceSelect::addClicked()
// Slot for editing a connection
void QgsPgSourceSelect::on_btnEdit_clicked()
{
editConnection();
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );

if ( nc->exec() )
{
nc->saveConnection();
}
populateConnectionList();
}

/** End Autoconnected SLOTS **/

// Remember which database is selected
void QgsPgSourceSelect::on_cmbConnections_activated( int )
{
dbChanged();
// Remember which database was selected.
QSettings settings;
settings.setValue( "/PostgreSQL/connections/selected", cmbConnections->currentText() );
}

void QgsPgSourceSelect::on_btnBuildQuery_clicked()
@@ -220,6 +255,9 @@ QgsPgSourceSelect::~QgsPgSourceSelect()
delete mColumnTypeThread;
mColumnTypeThread = NULL;
}

QSettings settings;
settings.setValue( "/Windows/PgSourceSelect/geometry", saveGeometry() );
}

void QgsPgSourceSelect::populateConnectionList()
@@ -238,52 +276,6 @@ void QgsPgSourceSelect::populateConnectionList()
setConnectionListPosition();
}

void QgsPgSourceSelect::addNewConnection()
{
QgsNewConnection *nc = new QgsNewConnection( this );

if ( nc->exec() )
{
populateConnectionList();
}
}

void QgsPgSourceSelect::editConnection()
{
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );

if ( nc->exec() )
{
nc->saveConnection();
}
populateConnectionList();
}

void QgsPgSourceSelect::deleteConnection()
{
QSettings settings;
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 + "/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();
}
}

QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
{
QString schemaName = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmSchema ) )->text();
@@ -735,14 +727,6 @@ QString QgsPgSourceSelect::fullDescription( QString schema, QString table,
return full_desc;
}

void QgsPgSourceSelect::dbChanged()
{
// Remember which database was selected.
QSettings settings;
settings.setValue( "/PostgreSQL/connections/selected",
cmbConnections->currentText() );
}

void QgsPgSourceSelect::setConnectionListPosition()
{
QSettings settings;
@@ -109,12 +109,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
QgsPgSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
//! Destructor
~QgsPgSourceSelect();
//! Opens the create connection dialog to build a new connection
void addNewConnection();
//! Opens a dialog to edit an existing connection
void editConnection();
//! Deletes the selected connection
void deleteConnection();
//! Populate the connection list combo box
void populateConnectionList();
//! Determines the tables the user selected and closes the dialog
@@ -123,8 +117,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
QStringList selectedTables();
//! Connection info (database, host, user, password)
QString connectionInfo();
// Store the selected database
void dbChanged();

public slots:
void addClicked();
@@ -133,15 +125,19 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
* Once connected, available layers are displayed.
*/
void on_btnConnect_clicked();
//! Opens the create connection dialog to build a new connection
void on_btnNew_clicked();
//! Opens a dialog to edit an existing connection
void on_btnEdit_clicked();
void on_btnBuildQuery_clicked();
//! Deletes the selected connection
void on_btnDelete_clicked();
void on_mSearchOptionsButton_clicked();
void on_mSearchTableEdit_textChanged( const QString & text );
void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
void setSql( const QModelIndex& index );
//! Store the selected database
void on_cmbConnections_activated( int );
void setLayerType( QString schema, QString table, QString column,
QString type );
@@ -191,7 +187,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
QgsDbFilterProxyModel mProxyModel;

QString layerURI( const QModelIndex &index );
QPushButton * mAddButton;
QPushButton *mAddButton;
};


0 comments on commit 405f44f

Please sign in to comment.
You can’t perform that action at this time.