Skip to content

Commit 51d7044

Browse files
authoredDec 22, 2020
[Backport release-3_10] Fix #38473, forgetting CRS in a new project (#40707)
* Fix #38473, forgetting CRS in a new project
1 parent 9d7b550 commit 51d7044

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
 

‎src/core/qgsproject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ void QgsProject::clear()
730730
mDirty = false;
731731
mTrustLayerMetadata = false;
732732
mCustomVariables.clear();
733+
mCrs = QgsCoordinateReferenceSystem();
733734
mMetadata = QgsProjectMetadata();
734735
if ( !settings.value( QStringLiteral( "projects/anonymize_new_projects" ), false, QgsSettings::Core ).toBool() )
735736
{

‎tests/src/core/testqgsproject.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TestQgsProject : public QObject
4848
void testReadFlags();
4949
void testSetGetCrs();
5050
void testEmbeddedLayerGroupFromQgz();
51+
void testCrsValidAfterReadingProjectFile();
5152
};
5253

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

572-
crsChangedSpy.clear();
573-
ellipsoidChangedSpy.clear();
574+
void TestQgsProject::testCrsValidAfterReadingProjectFile()
575+
{
576+
QgsProject p;
577+
QSignalSpy crsChangedSpy( &p, &QgsProject::crsChanged );
578+
579+
// - new project
580+
// - set CRS tp 4326, the crs changes
581+
// - save the project
582+
// - clear()
583+
// - load the project, the CRS should be 4326
584+
QTemporaryDir dir;
585+
QVERIFY( dir.isValid() );
586+
// on mac the returned path was not canonical and the resolver failed to convert paths properly
587+
QString dirPath = QFileInfo( dir.path() ).canonicalFilePath();
588+
QString projectFilename = dirPath + "/project.qgs";
589+
590+
p.setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
591+
592+
QCOMPARE( crsChangedSpy.count(), 1 );
593+
QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
594+
595+
QVERIFY( p.write( projectFilename ) );
596+
p.clear();
597+
598+
QCOMPARE( p.crs(), QgsCoordinateReferenceSystem() );
599+
QCOMPARE( crsChangedSpy.count(), 1 );
600+
601+
QVERIFY( p.read( projectFilename ) );
602+
QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
603+
QCOMPARE( crsChangedSpy.count(), 2 );
574604
}
575605

576606

0 commit comments

Comments
 (0)
Please sign in to comment.