Skip to content

Commit

Permalink
Do not save .qgd file alongside .qgs when it's not used
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Apr 6, 2018
1 parent 62ba263 commit c47a645
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions python/core/qgsauxiliarystorage.sip.in
Expand Up @@ -345,6 +345,15 @@ Duplicates a table and its content.
static QString extension(); static QString extension();
%Docstring %Docstring
Returns the extension used for auxiliary databases. Returns the extension used for auxiliary databases.
%End

static bool exists( const QgsProject &project );
%Docstring
Returns true if the auxiliary database yet exists for a project, false otherwise.

:param project: The project for which the database is checked

.. versionadded:: 3.2
%End %End


}; };
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsauxiliarystorage.cpp
Expand Up @@ -647,6 +647,12 @@ QString QgsAuxiliaryStorage::extension()
return AS_EXTENSION; return AS_EXTENSION;
} }


bool QgsAuxiliaryStorage::exists( const QgsProject &project )
{
const QFileInfo fileinfo( filenameForProject( project ) );
return fileinfo.exists() && fileinfo.isFile();
}

bool QgsAuxiliaryStorage::exec( const QString &sql, sqlite3 *handler ) bool QgsAuxiliaryStorage::exec( const QString &sql, sqlite3 *handler )
{ {
bool rc = false; bool rc = false;
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsauxiliarystorage.h
Expand Up @@ -377,6 +377,15 @@ class CORE_EXPORT QgsAuxiliaryStorage
*/ */
static QString extension(); static QString extension();


/**
* Returns true if the auxiliary database yet exists for a project, false otherwise.
*
* \param project The project for which the database is checked
*
* \since QGIS 3.2
*/
static bool exists( const QgsProject &project );

private: private:
spatialite_database_unique_ptr open( const QString &filename = QString() ); spatialite_database_unique_ptr open( const QString &filename = QString() );
spatialite_database_unique_ptr open( const QgsProject &project ); spatialite_database_unique_ptr open( const QgsProject &project );
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsproject.cpp
Expand Up @@ -2505,6 +2505,7 @@ void QgsProject::setTrustLayerMetadata( bool trust )
bool QgsProject::saveAuxiliaryStorage( const QString &filename ) bool QgsProject::saveAuxiliaryStorage( const QString &filename )
{ {
const QMap<QString, QgsMapLayer *> layers = mapLayers(); const QMap<QString, QgsMapLayer *> layers = mapLayers();
bool empty = true;
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it ) for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
{ {
if ( it.value()->type() != QgsMapLayer::VectorLayer ) if ( it.value()->type() != QgsMapLayer::VectorLayer )
Expand All @@ -2514,10 +2515,15 @@ bool QgsProject::saveAuxiliaryStorage( const QString &filename )
if ( vl && vl->auxiliaryLayer() ) if ( vl && vl->auxiliaryLayer() )
{ {
vl->auxiliaryLayer()->save(); vl->auxiliaryLayer()->save();
empty &= vl->auxiliaryLayer()->auxiliaryFields().isEmpty();
} }
} }


if ( !filename.isEmpty() ) if ( !mAuxiliaryStorage->exists( *this ) && filename.isEmpty() && empty )
{
return true; // it's not an error
}
else if ( !filename.isEmpty() )
{ {
return mAuxiliaryStorage->saveAs( filename ); return mAuxiliaryStorage->saveAs( filename );
} }
Expand Down

0 comments on commit c47a645

Please sign in to comment.