Skip to content
Permalink
Browse files

Fix #38473, forgetting CRS in a new project (#40648)

Fix #3847

(cherry picked from commit 7f2b71c)
  • Loading branch information
suricactus authored and nyalldawson committed Dec 21, 2020
1 parent e2af50b commit 887fadb5940ebf2459d86da8971d4b3c3f7e4556
Showing with 33 additions and 2 deletions.
  1. +1 −0 src/core/qgsproject.cpp
  2. +32 −2 tests/src/core/testqgsproject.cpp
@@ -830,6 +830,7 @@ void QgsProject::clear()
mDirty = false;
mTrustLayerMetadata = false;
mCustomVariables.clear();
mCrs = QgsCoordinateReferenceSystem();
mMetadata = QgsProjectMetadata();
if ( !mSettings.value( QStringLiteral( "projects/anonymize_new_projects" ), false, QgsSettings::Core ).toBool() )
{
@@ -50,6 +50,7 @@ class TestQgsProject : public QObject
void testEmbeddedLayerGroupFromQgz();
void projectSaveUser();
void testCrsExpressions();
void testCrsValidAfterReadingProjectFile();
};

void TestQgsProject::init()
@@ -618,9 +619,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 );
}

void TestQgsProject::testCrsExpressions()

0 comments on commit 887fadb

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