Skip to content

Commit

Permalink
save geometry of postgresql selection dialog
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12373 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 8, 2009
1 parent bcb2211 commit 3f37e9e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 67 deletions.
100 changes: 42 additions & 58 deletions src/app/qgspgsourceselect.cpp
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -220,6 +255,9 @@ QgsPgSourceSelect::~QgsPgSourceSelect()
delete mColumnTypeThread;
mColumnTypeThread = NULL;
}

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

void QgsPgSourceSelect::populateConnectionList()
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 5 additions & 9 deletions src/app/qgspgsourceselect.h
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -191,7 +187,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
QgsDbFilterProxyModel mProxyModel;

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


Expand Down

0 comments on commit 3f37e9e

Please sign in to comment.