Skip to content
Permalink
Browse files

Do not save .qgd file alongside .qgs when it's not used

  • Loading branch information
pblottiere committed Apr 6, 2018
1 parent 62ba263 commit c47a6457b8c944b3cfc04acf391ff1917deaaf4b
@@ -345,6 +345,15 @@ Duplicates a table and its content.
static QString extension();
%Docstring
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

};
@@ -647,6 +647,12 @@ QString QgsAuxiliaryStorage::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 rc = false;
@@ -377,6 +377,15 @@ class CORE_EXPORT QgsAuxiliaryStorage
*/
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:
spatialite_database_unique_ptr open( const QString &filename = QString() );
spatialite_database_unique_ptr open( const QgsProject &project );
@@ -2505,6 +2505,7 @@ void QgsProject::setTrustLayerMetadata( bool trust )
bool QgsProject::saveAuxiliaryStorage( const QString &filename )
{
const QMap<QString, QgsMapLayer *> layers = mapLayers();
bool empty = true;
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
{
if ( it.value()->type() != QgsMapLayer::VectorLayer )
@@ -2514,10 +2515,15 @@ bool QgsProject::saveAuxiliaryStorage( const QString &filename )
if ( vl && vl->auxiliaryLayer() )
{
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 );
}

0 comments on commit c47a645

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