File tree 4 files changed +31
-1
lines changed
4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -345,6 +345,15 @@ Duplicates a table and its content.
345
345
static QString extension();
346
346
%Docstring
347
347
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
348
357
%End
349
358
350
359
};
Original file line number Diff line number Diff line change @@ -647,6 +647,12 @@ QString QgsAuxiliaryStorage::extension()
647
647
return AS_EXTENSION;
648
648
}
649
649
650
+ bool QgsAuxiliaryStorage::exists ( const QgsProject &project )
651
+ {
652
+ const QFileInfo fileinfo ( filenameForProject ( project ) );
653
+ return fileinfo.exists () && fileinfo.isFile ();
654
+ }
655
+
650
656
bool QgsAuxiliaryStorage::exec ( const QString &sql, sqlite3 *handler )
651
657
{
652
658
bool rc = false ;
Original file line number Diff line number Diff line change @@ -377,6 +377,15 @@ class CORE_EXPORT QgsAuxiliaryStorage
377
377
*/
378
378
static QString extension ();
379
379
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
+
380
389
private:
381
390
spatialite_database_unique_ptr open ( const QString &filename = QString() );
382
391
spatialite_database_unique_ptr open ( const QgsProject &project );
Original file line number Diff line number Diff line change @@ -2505,6 +2505,7 @@ void QgsProject::setTrustLayerMetadata( bool trust )
2505
2505
bool QgsProject::saveAuxiliaryStorage ( const QString &filename )
2506
2506
{
2507
2507
const QMap<QString, QgsMapLayer *> layers = mapLayers ();
2508
+ bool empty = true ;
2508
2509
for ( auto it = layers.constBegin (); it != layers.constEnd (); ++it )
2509
2510
{
2510
2511
if ( it.value ()->type () != QgsMapLayer::VectorLayer )
@@ -2514,10 +2515,15 @@ bool QgsProject::saveAuxiliaryStorage( const QString &filename )
2514
2515
if ( vl && vl->auxiliaryLayer () )
2515
2516
{
2516
2517
vl->auxiliaryLayer ()->save ();
2518
+ empty &= vl->auxiliaryLayer ()->auxiliaryFields ().isEmpty ();
2517
2519
}
2518
2520
}
2519
2521
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 () )
2521
2527
{
2522
2528
return mAuxiliaryStorage ->saveAs ( filename );
2523
2529
}
You can’t perform that action at this time.
0 commit comments