Skip to content

Commit e80f604

Browse files
committedApr 7, 2018
Make storage of projects in postgres opt-in for each connection
1 parent 42969a4 commit e80f604

7 files changed

+40
-3
lines changed
 

‎src/providers/postgres/qgspgnewconnection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
6969
cb_geometryColumnsOnly_clicked();
7070

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

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

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

160162
// remove old save setting
161163
settings.remove( baseKey + "/save" );

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,12 @@ bool QgsPostgresConn::allowGeometrylessTables( const QString &connName )
18151815
return settings.value( "/PostgreSQL/connections/" + connName + "/allowGeometrylessTables", false ).toBool();
18161816
}
18171817

1818+
bool QgsPostgresConn::allowProjectsInDatabase( const QString &connName )
1819+
{
1820+
QgsSettings settings;
1821+
return settings.value( "/PostgreSQL/connections/" + connName + "/projectsInDatabase", false ).toBool();
1822+
}
1823+
18181824
void QgsPostgresConn::deleteConnection( const QString &connName )
18191825
{
18201826
QgsSettings settings;

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class QgsPostgresConn : public QObject
346346
static bool geometryColumnsOnly( const QString &connName );
347347
static bool dontResolveType( const QString &connName );
348348
static bool allowGeometrylessTables( const QString &connName );
349+
static bool allowProjectsInDatabase( const QString &connName );
349350
static void deleteConnection( const QString &connName );
350351

351352
//! A connection needs to be locked when it uses transactions, see QgsPostgresConn::{begin,commit,rollback}

‎src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
576576

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

579-
if ( QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" ) )
579+
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" );
580+
if ( QgsPostgresConn::allowProjectsInDatabase( mConnectionName ) && storage )
580581
{
581582
QgsPostgresProjectUri postUri;
582583
postUri.connInfo = uri;

‎src/providers/postgres/qgspostgresprojectstoragedialog.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q
3838

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

41+
mLblProjectsNotAllowed->setVisible( false );
42+
4143
// populate connections
4244
mCboConnection->addItems( QgsPostgresConn::connectionList() );
4345

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

79+
bool projectsAllowed = QgsPostgresConn::allowProjectsInDatabase( name );
80+
mLblProjectsNotAllowed->setVisible( !projectsAllowed );
81+
if ( !projectsAllowed )
82+
return;
83+
7784
QApplication::setOverrideCursor( Qt::WaitCursor );
7885

7986
QgsPostgresConn *conn = QgsPostgresConnPool::instance()->acquireConnection( uri.connectionInfo( false ) );

‎src/ui/qgspgnewconnectionbase.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@
220220
</property>
221221
</widget>
222222
</item>
223+
<item>
224+
<widget class="QCheckBox" name="cb_projectsInDatabase">
225+
<property name="text">
226+
<string>Allow saving/loading QGIS projects in the database</string>
227+
</property>
228+
</widget>
229+
</item>
223230
<item>
224231
<spacer name="verticalSpacer">
225232
<property name="orientation">

‎src/ui/qgspostgresprojectstoragedialog.ui

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>463</width>
10-
<height>307</height>
9+
<width>552</width>
10+
<height>442</height>
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout">
@@ -45,6 +45,19 @@
4545
</item>
4646
</layout>
4747
</item>
48+
<item>
49+
<widget class="QLabel" name="mLblProjectsNotAllowed">
50+
<property name="text">
51+
<string>Storage of QGIS projects is not enabled for this database connection.</string>
52+
</property>
53+
<property name="alignment">
54+
<set>Qt::AlignCenter</set>
55+
</property>
56+
<property name="wordWrap">
57+
<bool>true</bool>
58+
</property>
59+
</widget>
60+
</item>
4861
<item>
4962
<spacer name="verticalSpacer">
5063
<property name="orientation">

0 commit comments

Comments
 (0)
Please sign in to comment.