Skip to content

Commit c47a645

Browse files
committed
Do not save .qgd file alongside .qgs when it's not used
1 parent 62ba263 commit c47a645

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

python/core/qgsauxiliarystorage.sip.in

+9
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ Duplicates a table and its content.
345345
static QString extension();
346346
%Docstring
347347
Returns the extension used for auxiliary databases.
348+
%End
349+
350+
static bool exists( const QgsProject &project );
351+
%Docstring
352+
Returns true if the auxiliary database yet exists for a project, false otherwise.
353+
354+
:param project: The project for which the database is checked
355+
356+
.. versionadded:: 3.2
348357
%End
349358

350359
};

src/core/qgsauxiliarystorage.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ QString QgsAuxiliaryStorage::extension()
647647
return AS_EXTENSION;
648648
}
649649

650+
bool QgsAuxiliaryStorage::exists( const QgsProject &project )
651+
{
652+
const QFileInfo fileinfo( filenameForProject( project ) );
653+
return fileinfo.exists() && fileinfo.isFile();
654+
}
655+
650656
bool QgsAuxiliaryStorage::exec( const QString &sql, sqlite3 *handler )
651657
{
652658
bool rc = false;

src/core/qgsauxiliarystorage.h

+9
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ class CORE_EXPORT QgsAuxiliaryStorage
377377
*/
378378
static QString extension();
379379

380+
/**
381+
* Returns true if the auxiliary database yet exists for a project, false otherwise.
382+
*
383+
* \param project The project for which the database is checked
384+
*
385+
* \since QGIS 3.2
386+
*/
387+
static bool exists( const QgsProject &project );
388+
380389
private:
381390
spatialite_database_unique_ptr open( const QString &filename = QString() );
382391
spatialite_database_unique_ptr open( const QgsProject &project );

src/core/qgsproject.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,7 @@ void QgsProject::setTrustLayerMetadata( bool trust )
25052505
bool QgsProject::saveAuxiliaryStorage( const QString &filename )
25062506
{
25072507
const QMap<QString, QgsMapLayer *> layers = mapLayers();
2508+
bool empty = true;
25082509
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
25092510
{
25102511
if ( it.value()->type() != QgsMapLayer::VectorLayer )
@@ -2514,10 +2515,15 @@ bool QgsProject::saveAuxiliaryStorage( const QString &filename )
25142515
if ( vl && vl->auxiliaryLayer() )
25152516
{
25162517
vl->auxiliaryLayer()->save();
2518+
empty &= vl->auxiliaryLayer()->auxiliaryFields().isEmpty();
25172519
}
25182520
}
25192521

2520-
if ( !filename.isEmpty() )
2522+
if ( !mAuxiliaryStorage->exists( *this ) && filename.isEmpty() && empty )
2523+
{
2524+
return true; // it's not an error
2525+
}
2526+
else if ( !filename.isEmpty() )
25212527
{
25222528
return mAuxiliaryStorage->saveAs( filename );
25232529
}

0 commit comments

Comments
 (0)