Skip to content
Permalink
Browse files

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

Fix #3847
  • Loading branch information
suricactus committed Dec 21, 2020
1 parent da59316 commit 7f2b71c097716f8fd55bb5ebed1c55fd9bdd5d6f
Showing with 33 additions and 2 deletions.
  1. +1 −0 src/core/qgsproject.cpp
  2. +32 −2 tests/src/core/testqgsproject.cpp
@@ -828,6 +828,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 7f2b71c

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