Skip to content

Commit 405f44f

Browse files
author
jef
committedDec 8, 2009
save geometry of postgresql selection dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12373 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+47
-67
lines changed

2 files changed

+47
-67
lines changed
 

‎src/app/qgspgsourceselect.cpp

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,44 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
8484
//for Qt < 4.3.2, passing -1 to include all model columns
8585
//in search does not seem to work
8686
mSearchColumnComboBox->setCurrentIndex( 2 );
87+
88+
restoreGeometry( settings.value( "/Windows/PgSourceSelect/geometry" ).toByteArray() );
8789
}
8890
/** Autoconnected SLOTS **/
8991
// Slot for adding a new connection
9092
void QgsPgSourceSelect::on_btnNew_clicked()
9193
{
92-
addNewConnection();
94+
QgsNewConnection *nc = new QgsNewConnection( this );
95+
96+
if ( nc->exec() )
97+
{
98+
populateConnectionList();
99+
}
93100
}
94101
// Slot for deleting an existing connection
95102
void QgsPgSourceSelect::on_btnDelete_clicked()
96103
{
97-
deleteConnection();
104+
QSettings settings;
105+
QString key = "/Postgresql/connections/" + cmbConnections->currentText();
106+
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
107+
.arg( cmbConnections->currentText() );
108+
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
109+
if ( result == QMessageBox::Ok )
110+
{
111+
settings.remove( key + "/host" );
112+
settings.remove( key + "/database" );
113+
settings.remove( key + "/username" );
114+
settings.remove( key + "/password" );
115+
settings.remove( key + "/port" );
116+
settings.remove( key + "/sslmode" );
117+
settings.remove( key + "/save" );
118+
settings.remove( key );
119+
//if(!success){
120+
// QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText());
121+
//}
122+
cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
123+
setConnectionListPosition();
124+
}
98125
}
99126
// Slot for performing action when the Add button is clicked
100127
void QgsPgSourceSelect::addClicked()
@@ -105,15 +132,23 @@ void QgsPgSourceSelect::addClicked()
105132
// Slot for editing a connection
106133
void QgsPgSourceSelect::on_btnEdit_clicked()
107134
{
108-
editConnection();
135+
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );
136+
137+
if ( nc->exec() )
138+
{
139+
nc->saveConnection();
140+
}
141+
populateConnectionList();
109142
}
110143

111144
/** End Autoconnected SLOTS **/
112145

113146
// Remember which database is selected
114147
void QgsPgSourceSelect::on_cmbConnections_activated( int )
115148
{
116-
dbChanged();
149+
// Remember which database was selected.
150+
QSettings settings;
151+
settings.setValue( "/PostgreSQL/connections/selected", cmbConnections->currentText() );
117152
}
118153

119154
void QgsPgSourceSelect::on_btnBuildQuery_clicked()
@@ -220,6 +255,9 @@ QgsPgSourceSelect::~QgsPgSourceSelect()
220255
delete mColumnTypeThread;
221256
mColumnTypeThread = NULL;
222257
}
258+
259+
QSettings settings;
260+
settings.setValue( "/Windows/PgSourceSelect/geometry", saveGeometry() );
223261
}
224262

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

241-
void QgsPgSourceSelect::addNewConnection()
242-
{
243-
QgsNewConnection *nc = new QgsNewConnection( this );
244-
245-
if ( nc->exec() )
246-
{
247-
populateConnectionList();
248-
}
249-
}
250-
251-
void QgsPgSourceSelect::editConnection()
252-
{
253-
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );
254-
255-
if ( nc->exec() )
256-
{
257-
nc->saveConnection();
258-
}
259-
populateConnectionList();
260-
}
261-
262-
void QgsPgSourceSelect::deleteConnection()
263-
{
264-
QSettings settings;
265-
QString key = "/Postgresql/connections/" + cmbConnections->currentText();
266-
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
267-
.arg( cmbConnections->currentText() );
268-
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
269-
if ( result == QMessageBox::Ok )
270-
{
271-
settings.remove( key + "/host" );
272-
settings.remove( key + "/database" );
273-
settings.remove( key + "/username" );
274-
settings.remove( key + "/password" );
275-
settings.remove( key + "/port" );
276-
settings.remove( key + "/sslmode" );
277-
settings.remove( key + "/save" );
278-
settings.remove( key );
279-
//if(!success){
280-
// QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText());
281-
//}
282-
cmbConnections->removeItem( cmbConnections->currentIndex() ); // populateConnectionList();
283-
setConnectionListPosition();
284-
}
285-
}
286-
287279
QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
288280
{
289281
QString schemaName = mTableModel.itemFromIndex( index.sibling( index.row(), QgsDbTableModel::dbtmSchema ) )->text();
@@ -735,14 +727,6 @@ QString QgsPgSourceSelect::fullDescription( QString schema, QString table,
735727
return full_desc;
736728
}
737729

738-
void QgsPgSourceSelect::dbChanged()
739-
{
740-
// Remember which database was selected.
741-
QSettings settings;
742-
settings.setValue( "/PostgreSQL/connections/selected",
743-
cmbConnections->currentText() );
744-
}
745-
746730
void QgsPgSourceSelect::setConnectionListPosition()
747731
{
748732
QSettings settings;

‎src/app/qgspgsourceselect.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
109109
QgsPgSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
110110
//! Destructor
111111
~QgsPgSourceSelect();
112-
//! Opens the create connection dialog to build a new connection
113-
void addNewConnection();
114-
//! Opens a dialog to edit an existing connection
115-
void editConnection();
116-
//! Deletes the selected connection
117-
void deleteConnection();
118112
//! Populate the connection list combo box
119113
void populateConnectionList();
120114
//! Determines the tables the user selected and closes the dialog
@@ -123,8 +117,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
123117
QStringList selectedTables();
124118
//! Connection info (database, host, user, password)
125119
QString connectionInfo();
126-
// Store the selected database
127-
void dbChanged();
128120

129121
public slots:
130122
void addClicked();
@@ -133,15 +125,19 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
133125
* Once connected, available layers are displayed.
134126
*/
135127
void on_btnConnect_clicked();
128+
//! Opens the create connection dialog to build a new connection
136129
void on_btnNew_clicked();
130+
//! Opens a dialog to edit an existing connection
137131
void on_btnEdit_clicked();
138132
void on_btnBuildQuery_clicked();
133+
//! Deletes the selected connection
139134
void on_btnDelete_clicked();
140135
void on_mSearchOptionsButton_clicked();
141136
void on_mSearchTableEdit_textChanged( const QString & text );
142137
void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
143138
void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
144139
void setSql( const QModelIndex& index );
140+
//! Store the selected database
145141
void on_cmbConnections_activated( int );
146142
void setLayerType( QString schema, QString table, QString column,
147143
QString type );
@@ -191,7 +187,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
191187
QgsDbFilterProxyModel mProxyModel;
192188

193189
QString layerURI( const QModelIndex &index );
194-
QPushButton * mAddButton;
190+
QPushButton *mAddButton;
195191
};
196192

197193

0 commit comments

Comments
 (0)
Please sign in to comment.