Skip to content

Commit

Permalink
postgres provider: move connection settings to QgsPostgresConn (also f…
Browse files Browse the repository at this point in the history
…ixes #4998 and #4999)
  • Loading branch information
jef-n committed Feb 13, 2012
1 parent cd68a0b commit 2457eb1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
39 changes: 6 additions & 33 deletions src/providers/postgres/qgspgsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl, bool manag
mSearchModeComboBox->setVisible( false );
mSearchModeLabel->setVisible( false );
mSearchTableEdit->setVisible( false );

cbxAllowGeometrylessTables->setDisabled( true );
}
/** Autoconnected SLOTS **/
// Slot for adding a new connection
Expand All @@ -215,33 +213,12 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
if ( QMessageBox::Ok != QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel ) )
return;

QgsPgSourceSelect::deleteConnection( cmbConnections->currentText() );
QgsPostgresConn::deleteConnection( cmbConnections->currentText() );

populateConnectionList();
emit connectionsChanged();
}

void QgsPgSourceSelect::deleteConnection( QString name )
{
QString key = "/Postgresql/connections/" + name;
QSettings settings;
settings.remove( key + "/service" );
settings.remove( key + "/host" );
settings.remove( key + "/port" );
settings.remove( key + "/database" );
settings.remove( key + "/username" );
settings.remove( key + "/password" );
settings.remove( key + "/sslmode" );
settings.remove( key + "/publicOnly" );
settings.remove( key + "/geometryColumnsOnly" );
settings.remove( key + "/allowGeometrylessTables" );
settings.remove( key + "/estimatedMetadata" );
settings.remove( key + "/saveUsername" );
settings.remove( key + "/savePassword" );
settings.remove( key + "/save" );
settings.remove( key );
}

void QgsPgSourceSelect::on_btnSave_clicked()
{
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::PostGIS );
Expand Down Expand Up @@ -277,14 +254,13 @@ void QgsPgSourceSelect::on_btnEdit_clicked()
/** End Autoconnected SLOTS **/

// Remember which database is selected
void QgsPgSourceSelect::on_cmbConnections_activated( int )
void QgsPgSourceSelect::on_cmbConnections_currentIndexChanged( const QString & text )
{
// Remember which database was selected.
QgsPostgresConn::setSelectedConnection( cmbConnections->currentText() );
QgsPostgresConn::setSelectedConnection( text );

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

Expand Down Expand Up @@ -466,11 +442,8 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
{
QApplication::setOverrideCursor( Qt::WaitCursor );

QSettings settings;
QString key = "/PostgreSQL/connections/" + cmbConnections->currentText();

bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly( cmbConnections->currentText() );
bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly( cmbConnections->currentText() );
bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked();

QVector<QgsPostgresLayerProperty> layers;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspgsourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
void on_mSearchTableEdit_textChanged( const QString & text );
void on_mSearchColumnComboBox_currentIndexChanged( const QString & text );
void on_mSearchModeComboBox_currentIndexChanged( const QString & text );
void on_cmbConnections_currentIndexChanged( const QString &text );
void setSql( const QModelIndex& index );
//! Store the selected database
void on_cmbConnections_activated( int );
void setLayerType( QgsPostgresLayerProperty layerProperty );
void on_mTablesTreeView_clicked( const QModelIndex &index );
void on_mTablesTreeView_doubleClicked( const QModelIndex &index );
Expand Down
45 changes: 41 additions & 4 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,6 @@ QgsDataSourceURI QgsPostgresConn::connUri( QString theConnName )
}
QString database = settings.value( key + "/database" ).toString();

//bool publicSchemaOnly = settings.value( key + "/publicOnly", false ).toBool();
//bool geometryColumnsOnly = settings.value( key + "/geometrycolumnsOnly", false ).toBool();
//bool allowGeometrylessTables = settings.value( key + "/allowGeometrylessTables", false ).toBool();

bool useEstimatedMetadata = settings.value( key + "/estimatedMetadata", false ).toBool();
int sslmode = settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt();

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

return uri;
}

bool QgsPostgresConn::publicSchemaOnly( QString theConnName )
{
QSettings settings;
return settings.value( "/PostgreSQL/connections/" + theConnName + "/publicOnly", false ).toBool();
}

bool QgsPostgresConn::geometryColumnsOnly( QString theConnName )
{
QSettings settings;

return settings.value( "/PostgreSQL/connections/" + theConnName + "/geometrycolumnsOnly", false ).toBool();
}

bool QgsPostgresConn::allowGeometrylessTables( QString theConnName )
{
QSettings settings;
return settings.value( "/PostgreSQL/connections/" + theConnName + "/allowGeometrylessTables", false ).toBool();
}

void QgsPostgresConn::deleteConnection( QString theConnName )
{
QSettings settings;

QString key = "/PostgreSQL/connections/" + theConnName;
settings.remove( key + "/service" );
settings.remove( key + "/host" );
settings.remove( key + "/port" );
settings.remove( key + "/database" );
settings.remove( key + "/username" );
settings.remove( key + "/password" );
settings.remove( key + "/sslmode" );
settings.remove( key + "/publicOnly" );
settings.remove( key + "/geometryColumnsOnly" );
settings.remove( key + "/allowGeometrylessTables" );
settings.remove( key + "/estimatedMetadata" );
settings.remove( key + "/saveUsername" );
settings.remove( key + "/savePassword" );
settings.remove( key + "/save" );
settings.remove( key );
}
4 changes: 4 additions & 0 deletions src/providers/postgres/qgspostgresconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class QgsPostgresConn : public QObject
static QString selectedConnection();
static void setSelectedConnection( QString theConnName );
static QgsDataSourceURI connUri( QString theConnName );
static bool publicSchemaOnly( QString theConnName );
static bool geometryColumnsOnly( QString theConnName );
static bool allowGeometrylessTables( QString theConnName );
static void deleteConnection( QString theConnName );

private:
QgsPostgresConn( QString conninfo, bool readOnly );
Expand Down

0 comments on commit 2457eb1

Please sign in to comment.