mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-10 00:13:55 -04:00
Set GPKG-stored project dirty when removed
if it's the current project Fixes #30550
This commit is contained in:
parent
3ff8ca5736
commit
e4ea247c6a
@ -29,6 +29,7 @@
|
|||||||
#include "qgsreadwritecontext.h"
|
#include "qgsreadwritecontext.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsogrutils.h"
|
#include "qgsogrutils.h"
|
||||||
|
#include "qgsproject.h"
|
||||||
|
|
||||||
|
|
||||||
static bool _parseMetadataDocument( const QJsonDocument &doc, QgsProjectStorage::Metadata &metadata )
|
static bool _parseMetadataDocument( const QJsonDocument &doc, QgsProjectStorage::Metadata &metadata )
|
||||||
@ -354,7 +355,12 @@ bool QgsGeoPackageProjectStorage::removeProject( const QString &uri )
|
|||||||
errCause = QObject::tr( "Could not remove project %1: %2" ).arg( uri, errCause );
|
errCause = QObject::tr( "Could not remove project %1: %2" ).arg( uri, errCause );
|
||||||
QgsMessageLog::logMessage( errCause, QStringLiteral( "OGR" ), Qgis::MessageLevel::Warning );
|
QgsMessageLog::logMessage( errCause, QStringLiteral( "OGR" ), Qgis::MessageLevel::Warning );
|
||||||
}
|
}
|
||||||
return errCause.isEmpty();
|
else if ( QgsProject::instance()->fileName() == uri )
|
||||||
|
{
|
||||||
|
QgsMessageLog::logMessage( QStringLiteral( "Current project was removed from storage, marking it dirty." ), QStringLiteral( "OGR" ), Qgis::MessageLevel::Warning );
|
||||||
|
QgsProject::instance()->setDirty( true );
|
||||||
|
}
|
||||||
|
return errCause.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsGeoPackageProjectStorage::renameProject( const QString &uri, const QString &uriNew )
|
bool QgsGeoPackageProjectStorage::renameProject( const QString &uri, const QString &uriNew )
|
||||||
|
@ -1261,6 +1261,30 @@ class TestQgsProject(unittest.TestCase):
|
|||||||
p.setTransformContext(ctx)
|
p.setTransformContext(ctx)
|
||||||
self.assertEqual(len(spy), 1)
|
self.assertEqual(len(spy), 1)
|
||||||
|
|
||||||
|
def testGpkgDirtyingWhenRemovedFromStorage(self):
|
||||||
|
"""Test that when a GPKG stored project is removed from the storage it is marked dirty"""
|
||||||
|
|
||||||
|
with TemporaryDirectory() as d:
|
||||||
|
path = os.path.join(d, 'relative_paths_gh30387.gpkg')
|
||||||
|
copyfile(os.path.join(TEST_DATA_DIR, 'projects', 'relative_paths_gh30387.gpkg'), path)
|
||||||
|
project = QgsProject.instance()
|
||||||
|
# Project URI
|
||||||
|
uri = 'geopackage://{}?projectName=relative_project'.format(path)
|
||||||
|
project.setFileName(uri)
|
||||||
|
self.assertTrue(project.write())
|
||||||
|
# Verify
|
||||||
|
self.assertTrue(project.read(uri))
|
||||||
|
self.assertFalse(project.isDirty())
|
||||||
|
# Remove from storage
|
||||||
|
storage = QgsApplication.projectStorageRegistry().projectStorageFromUri(uri)
|
||||||
|
self.assertTrue(storage.removeProject(uri))
|
||||||
|
self.assertTrue(project.isDirty())
|
||||||
|
# Save it back
|
||||||
|
self.assertTrue(project.write())
|
||||||
|
self.assertFalse(project.isDirty())
|
||||||
|
# Reload
|
||||||
|
self.assertTrue(project.read(uri))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user