Skip to content
Permalink
Browse files

Make storage of projects in postgres opt-in for each connection

  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 42969a4 commit e80f604b43d09a0e9c7f43ebff9ccbfe47c74345
@@ -69,6 +69,7 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
cb_geometryColumnsOnly_clicked();

cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
cb_projectsInDatabase->setChecked( settings.value( key + "/projectsInDatabase", false ).toBool() );

cbxSSLmode->setCurrentIndex( cbxSSLmode->findData( settings.enumValue( key + "/sslmode", QgsDataSourceUri::SslPrefer ) ) );

@@ -156,6 +157,7 @@ void QgsPgNewConnection::accept()
settings.setValue( baseKey + "/saveUsername", mAuthSettings->storeUsernameIsChecked( ) && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", mAuthSettings->storePasswordIsChecked( ) && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() );
settings.setValue( baseKey + "/projectsInDatabase", cb_projectsInDatabase->isChecked() );

// remove old save setting
settings.remove( baseKey + "/save" );
@@ -1815,6 +1815,12 @@ bool QgsPostgresConn::allowGeometrylessTables( const QString &connName )
return settings.value( "/PostgreSQL/connections/" + connName + "/allowGeometrylessTables", false ).toBool();
}

bool QgsPostgresConn::allowProjectsInDatabase( const QString &connName )
{
QgsSettings settings;
return settings.value( "/PostgreSQL/connections/" + connName + "/projectsInDatabase", false ).toBool();
}

void QgsPostgresConn::deleteConnection( const QString &connName )
{
QgsSettings settings;
@@ -346,6 +346,7 @@ class QgsPostgresConn : public QObject
static bool geometryColumnsOnly( const QString &connName );
static bool dontResolveType( const QString &connName );
static bool allowGeometrylessTables( const QString &connName );
static bool allowProjectsInDatabase( const QString &connName );
static void deleteConnection( const QString &connName );

//! A connection needs to be locked when it uses transactions, see QgsPostgresConn::{begin,commit,rollback}
@@ -576,7 +576,8 @@ QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()

QgsPostgresConnPool::instance()->releaseConnection( conn );

if ( QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" ) )
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" );
if ( QgsPostgresConn::allowProjectsInDatabase( mConnectionName ) && storage )
{
QgsPostgresProjectUri postUri;
postUri.connInfo = uri;
@@ -38,6 +38,8 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q

connect( mCboConnection, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPostgresProjectStorageDialog::populateSchemas );

mLblProjectsNotAllowed->setVisible( false );

// populate connections
mCboConnection->addItems( QgsPostgresConn::connectionList() );

@@ -74,6 +76,11 @@ void QgsPostgresProjectStorageDialog::populateSchemas()
QString name = mCboConnection->currentText();
QgsDataSourceUri uri = QgsPostgresConn::connUri( name );

bool projectsAllowed = QgsPostgresConn::allowProjectsInDatabase( name );
mLblProjectsNotAllowed->setVisible( !projectsAllowed );
if ( !projectsAllowed )
return;

QApplication::setOverrideCursor( Qt::WaitCursor );

QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( uri.connectionInfo( false ) );
@@ -220,6 +220,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_projectsInDatabase">
<property name="text">
<string>Allow saving/loading QGIS projects in the database</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<height>307</height>
<width>552</width>
<height>442</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -45,6 +45,19 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="mLblProjectsNotAllowed">
<property name="text">
<string>Storage of QGIS projects is not enabled for this database connection.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

0 comments on commit e80f604

Please sign in to comment.
You can’t perform that action at this time.