@@ -48,6 +48,7 @@ class TestQgsProject : public QObject
48
48
void testReadFlags ();
49
49
void testSetGetCrs ();
50
50
void testEmbeddedLayerGroupFromQgz ();
51
+ void testCrsValidAfterReadingProjectFile ();
51
52
};
52
53
53
54
void TestQgsProject::init ()
@@ -568,9 +569,38 @@ void TestQgsProject::testSetGetCrs()
568
569
#else
569
570
QCOMPARE ( p.ellipsoid (), QStringLiteral ( " bessel" ) );
570
571
#endif
572
+ }
571
573
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 );
574
604
}
575
605
576
606
0 commit comments