Skip to content

Commit 2457eb1

Browse files
committed
postgres provider: move connection settings to QgsPostgresConn (also fixes #4998 and #4999)
1 parent cd68a0b commit 2457eb1

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

src/providers/postgres/qgspgsourceselect.cpp

+6-33
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl, bool manag
192192
mSearchModeComboBox->setVisible( false );
193193
mSearchModeLabel->setVisible( false );
194194
mSearchTableEdit->setVisible( false );
195-
196-
cbxAllowGeometrylessTables->setDisabled( true );
197195
}
198196
/** Autoconnected SLOTS **/
199197
// Slot for adding a new connection
@@ -215,33 +213,12 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
215213
if ( QMessageBox::Ok != QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel ) )
216214
return;
217215

218-
QgsPgSourceSelect::deleteConnection( cmbConnections->currentText() );
216+
QgsPostgresConn::deleteConnection( cmbConnections->currentText() );
219217

220218
populateConnectionList();
221219
emit connectionsChanged();
222220
}
223221

224-
void QgsPgSourceSelect::deleteConnection( QString name )
225-
{
226-
QString key = "/Postgresql/connections/" + name;
227-
QSettings settings;
228-
settings.remove( key + "/service" );
229-
settings.remove( key + "/host" );
230-
settings.remove( key + "/port" );
231-
settings.remove( key + "/database" );
232-
settings.remove( key + "/username" );
233-
settings.remove( key + "/password" );
234-
settings.remove( key + "/sslmode" );
235-
settings.remove( key + "/publicOnly" );
236-
settings.remove( key + "/geometryColumnsOnly" );
237-
settings.remove( key + "/allowGeometrylessTables" );
238-
settings.remove( key + "/estimatedMetadata" );
239-
settings.remove( key + "/saveUsername" );
240-
settings.remove( key + "/savePassword" );
241-
settings.remove( key + "/save" );
242-
settings.remove( key );
243-
}
244-
245222
void QgsPgSourceSelect::on_btnSave_clicked()
246223
{
247224
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::PostGIS );
@@ -277,14 +254,13 @@ void QgsPgSourceSelect::on_btnEdit_clicked()
277254
/** End Autoconnected SLOTS **/
278255

279256
// Remember which database is selected
280-
void QgsPgSourceSelect::on_cmbConnections_activated( int )
257+
void QgsPgSourceSelect::on_cmbConnections_currentIndexChanged( const QString & text )
281258
{
282259
// Remember which database was selected.
283-
QgsPostgresConn::setSelectedConnection( cmbConnections->currentText() );
260+
QgsPostgresConn::setSelectedConnection( text );
284261

285262
cbxAllowGeometrylessTables->blockSignals( true );
286-
QSettings settings;
287-
cbxAllowGeometrylessTables->setChecked( settings.value( "/PostgreSQL/connections/" + cmbConnections->currentText() + "/allowGeometrylessTables", false ).toBool() );
263+
cbxAllowGeometrylessTables->setChecked( QgsPostgresConn::allowGeometrylessTables( text ) );
288264
cbxAllowGeometrylessTables->blockSignals( false );
289265
}
290266

@@ -466,11 +442,8 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
466442
{
467443
QApplication::setOverrideCursor( Qt::WaitCursor );
468444

469-
QSettings settings;
470-
QString key = "/PostgreSQL/connections/" + cmbConnections->currentText();
471-
472-
bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
473-
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
445+
bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly( cmbConnections->currentText() );
446+
bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly( cmbConnections->currentText() );
474447
bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked();
475448

476449
QVector<QgsPostgresLayerProperty> layers;

src/providers/postgres/qgspgsourceselect.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
103103
void on_mSearchTableEdit_textChanged( const QString & text );
104104
void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
105105
void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
106+
void on_cmbConnections_currentIndexChanged( const QString &text );
106107
void setSql( const QModelIndex& index );
107108
//! Store the selected database
108-
void on_cmbConnections_activated( int );
109109
void setLayerType( QgsPostgresLayerProperty layerProperty );
110110
void on_mTablesTreeView_clicked( const QModelIndex &index );
111111
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );

src/providers/postgres/qgspostgresconn.cpp

+41-4
Original file line numberDiff line numberDiff line change
@@ -1365,10 +1365,6 @@ QgsDataSourceURI QgsPostgresConn::connUri( QString theConnName )
13651365
}
13661366
QString database = settings.value( key + "/database" ).toString();
13671367

1368-
//bool publicSchemaOnly = settings.value( key + "/publicOnly", false ).toBool();
1369-
//bool geometryColumnsOnly = settings.value( key + "/geometrycolumnsOnly", false ).toBool();
1370-
//bool allowGeometrylessTables = settings.value( key + "/allowGeometrylessTables", false ).toBool();
1371-
13721368
bool useEstimatedMetadata = settings.value( key + "/estimatedMetadata", false ).toBool();
13731369
int sslmode = settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt();
13741370

@@ -1408,3 +1404,44 @@ QgsDataSourceURI QgsPostgresConn::connUri( QString theConnName )
14081404

14091405
return uri;
14101406
}
1407+
1408+
bool QgsPostgresConn::publicSchemaOnly( QString theConnName )
1409+
{
1410+
QSettings settings;
1411+
return settings.value( "/PostgreSQL/connections/" + theConnName + "/publicOnly", false ).toBool();
1412+
}
1413+
1414+
bool QgsPostgresConn::geometryColumnsOnly( QString theConnName )
1415+
{
1416+
QSettings settings;
1417+
1418+
return settings.value( "/PostgreSQL/connections/" + theConnName + "/geometrycolumnsOnly", false ).toBool();
1419+
}
1420+
1421+
bool QgsPostgresConn::allowGeometrylessTables( QString theConnName )
1422+
{
1423+
QSettings settings;
1424+
return settings.value( "/PostgreSQL/connections/" + theConnName + "/allowGeometrylessTables", false ).toBool();
1425+
}
1426+
1427+
void QgsPostgresConn::deleteConnection( QString theConnName )
1428+
{
1429+
QSettings settings;
1430+
1431+
QString key = "/PostgreSQL/connections/" + theConnName;
1432+
settings.remove( key + "/service" );
1433+
settings.remove( key + "/host" );
1434+
settings.remove( key + "/port" );
1435+
settings.remove( key + "/database" );
1436+
settings.remove( key + "/username" );
1437+
settings.remove( key + "/password" );
1438+
settings.remove( key + "/sslmode" );
1439+
settings.remove( key + "/publicOnly" );
1440+
settings.remove( key + "/geometryColumnsOnly" );
1441+
settings.remove( key + "/allowGeometrylessTables" );
1442+
settings.remove( key + "/estimatedMetadata" );
1443+
settings.remove( key + "/saveUsername" );
1444+
settings.remove( key + "/savePassword" );
1445+
settings.remove( key + "/save" );
1446+
settings.remove( key );
1447+
}

src/providers/postgres/qgspostgresconn.h

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class QgsPostgresConn : public QObject
181181
static QString selectedConnection();
182182
static void setSelectedConnection( QString theConnName );
183183
static QgsDataSourceURI connUri( QString theConnName );
184+
static bool publicSchemaOnly( QString theConnName );
185+
static bool geometryColumnsOnly( QString theConnName );
186+
static bool allowGeometrylessTables( QString theConnName );
187+
static void deleteConnection( QString theConnName );
184188

185189
private:
186190
QgsPostgresConn( QString conninfo, bool readOnly );

0 commit comments

Comments
 (0)