Skip to content
Permalink
Browse files

[Backport release-3_10] Fix #38473, forgetting CRS in a new project (#…

…40707)

* Fix #38473, forgetting CRS in a new project
  • Loading branch information
qgis-bot committed Dec 22, 2020
1 parent 9d7b550 commit 51d70440502cbf23f331de14a84df162c764cadc
Showing with 33 additions and 2 deletions.
  1. +1 −0 src/core/qgsproject.cpp
  2. +32 −2 tests/src/core/testqgsproject.cpp
@@ -730,6 +730,7 @@ void QgsProject::clear()
mDirty = false;
mTrustLayerMetadata = false;
mCustomVariables.clear();
mCrs = QgsCoordinateReferenceSystem();
mMetadata = QgsProjectMetadata();
if ( !settings.value( QStringLiteral( "projects/anonymize_new_projects" ), false, QgsSettings::Core ).toBool() )
{
@@ -48,6 +48,7 @@ class TestQgsProject : public QObject
void testReadFlags();
void testSetGetCrs();
void testEmbeddedLayerGroupFromQgz();
void testCrsValidAfterReadingProjectFile();
};

void TestQgsProject::init()
@@ -568,9 +569,38 @@ void TestQgsProject::testSetGetCrs()
#else
QCOMPARE( p.ellipsoid(), QStringLiteral( "bessel" ) );
#endif
}

crsChangedSpy.clear();
ellipsoidChangedSpy.clear();
void TestQgsProject::testCrsValidAfterReadingProjectFile()
{
QgsProject p;
QSignalSpy crsChangedSpy( &p, &QgsProject::crsChanged );

// - new project
// - set CRS tp 4326, the crs changes
// - save the project
// - clear()
// - load the project, the CRS should be 4326
QTemporaryDir dir;
QVERIFY( dir.isValid() );
// on mac the returned path was not canonical and the resolver failed to convert paths properly
QString dirPath = QFileInfo( dir.path() ).canonicalFilePath();
QString projectFilename = dirPath + "/project.qgs";

p.setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );

QCOMPARE( crsChangedSpy.count(), 1 );
QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );

QVERIFY( p.write( projectFilename ) );
p.clear();

QCOMPARE( p.crs(), QgsCoordinateReferenceSystem() );
QCOMPARE( crsChangedSpy.count(), 1 );

QVERIFY( p.read( projectFilename ) );
QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
QCOMPARE( crsChangedSpy.count(), 2 );
}


0 comments on commit 51d7044

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