Skip to content

Commit 1aee424

Browse files
committedMar 14, 2017
Restore projects with OTF off to "no projection" (fix #16338)
1 parent 798f0f7 commit 1aee424

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed
 

‎src/core/qgsproject.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,22 +419,16 @@ QFileInfo QgsProject::fileInfo() const
419419

420420
QgsCoordinateReferenceSystem QgsProject::crs() const
421421
{
422-
QgsCoordinateReferenceSystem projectCrs;
423-
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
424-
if ( currentCRS != -1 )
425-
{
426-
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
427-
}
428-
return projectCrs;
422+
return mCrs;
429423
}
430424

431425
void QgsProject::setCrs( const QgsCoordinateReferenceSystem &crs )
432426
{
427+
mCrs = crs;
433428
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSProj4String" ), crs.toProj4() );
434429
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), static_cast< int >( crs.srsid() ) );
435430
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCrs" ), crs.authid() );
436431
setDirty( true );
437-
438432
emit crsChanged();
439433
}
440434

@@ -816,6 +810,19 @@ bool QgsProject::read()
816810
// now get project title
817811
_getTitle( *doc, mTitle );
818812

813+
//crs
814+
QgsCoordinateReferenceSystem projectCrs;
815+
if ( QgsProject::instance()->readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) )
816+
{
817+
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
818+
if ( currentCRS != -1 )
819+
{
820+
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
821+
}
822+
}
823+
mCrs = projectCrs;
824+
emit crsChanged();
825+
819826
QDomNodeList nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );
820827
if ( nl.count() )
821828
{

‎src/core/qgsproject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
10091009
QString mTitle; // project title
10101010
bool mAutoTransaction; // transaction grouped editing
10111011
bool mEvaluateDefaultValues; // evaluate default values immediately
1012+
QgsCoordinateReferenceSystem mCrs;
10121013
bool mDirty; // project has been modified since it has been read or saved
10131014
};
10141015

‎src/core/qgsprojectfiletransform.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,29 @@ void QgsProjectFileTransform::transform2200to2300()
617617

618618
void QgsProjectFileTransform::transform2990()
619619
{
620+
QDomNodeList srsNodes = mDom.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
621+
if ( srsNodes.count() > 0 )
622+
{
623+
QDomElement srsElem = srsNodes.at( 0 ).toElement();
624+
QDomNodeList projNodes = srsElem.elementsByTagName( "ProjectionsEnabled" );
625+
if ( projNodes.count() == 0 )
626+
{
627+
QDomElement projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
628+
projElem.setAttribute( "type", "int" );
629+
projElem.setNodeValue( "0" );
630+
srsElem.appendChild( projElem );
631+
}
632+
}
633+
else
634+
{
635+
QDomElement srsElem = mDom.createElement( QStringLiteral( "SpatialRefSys" ) );
636+
mDom.appendChild( srsElem );
637+
QDomElement projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
638+
projElem.setAttribute( "type", "int" );
639+
projElem.setNodeValue( "0" );
640+
srsElem.appendChild( projElem );
641+
}
642+
620643
QDomNodeList mapLayers = mDom.elementsByTagName( QStringLiteral( "maplayer" ) );
621644

622645
for ( int mapLayerIndex = 0; mapLayerIndex < mapLayers.count(); ++mapLayerIndex )

0 commit comments

Comments
 (0)
Please sign in to comment.