Skip to content
Permalink
Browse files
postgres provider: move connection settings to QgsPostgresConn (also f…
…ixes #4998 and #4999)
  • Loading branch information
jef-n committed Feb 13, 2012
1 parent cd68a0b commit 2457eb1c2370ec252212f6951274b2b7aa32267f
@@ -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
@@ -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 );
@@ -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 );
}

@@ -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;
@@ -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 );
@@ -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();

@@ -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 );
}
@@ -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 );

0 comments on commit 2457eb1

Please sign in to comment.