Skip to content

Commit

Permalink
Make storage of projects in postgres opt-in for each connection
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 42969a4 commit e80f604
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/providers/postgres/qgspgnewconnection.cpp
Expand Up @@ -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 ) ) );

Expand Down Expand Up @@ -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" );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresconn.h
Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/providers/postgres/qgspostgresprojectstoragedialog.cpp
Expand Up @@ -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() );

Expand Down Expand Up @@ -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 ) );
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgspgnewconnectionbase.ui
Expand Up @@ -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">
Expand Down
17 changes: 15 additions & 2 deletions src/ui/qgspostgresprojectstoragedialog.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit e80f604

Please sign in to comment.