Skip to content

Commit

Permalink
Restore projects with OTF off to "no projection" (fix #16338)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 798f0f7 commit 1aee424
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/core/qgsproject.cpp
Expand Up @@ -419,22 +419,16 @@ QFileInfo QgsProject::fileInfo() const

QgsCoordinateReferenceSystem QgsProject::crs() const
{
QgsCoordinateReferenceSystem projectCrs;
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
if ( currentCRS != -1 )
{
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}
return projectCrs;
return mCrs;
}

void QgsProject::setCrs( const QgsCoordinateReferenceSystem &crs )
{
mCrs = crs;
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSProj4String" ), crs.toProj4() );
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), static_cast< int >( crs.srsid() ) );
writeEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCrs" ), crs.authid() );
setDirty( true );

emit crsChanged();
}

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

//crs
QgsCoordinateReferenceSystem projectCrs;
if ( QgsProject::instance()->readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectionsEnabled" ), 0 ) )
{
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
if ( currentCRS != -1 )
{
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}
}
mCrs = projectCrs;
emit crsChanged();

QDomNodeList nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );
if ( nl.count() )
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsproject.h
Expand Up @@ -1009,6 +1009,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
QString mTitle; // project title
bool mAutoTransaction; // transaction grouped editing
bool mEvaluateDefaultValues; // evaluate default values immediately
QgsCoordinateReferenceSystem mCrs;
bool mDirty; // project has been modified since it has been read or saved
};

Expand Down
23 changes: 23 additions & 0 deletions src/core/qgsprojectfiletransform.cpp
Expand Up @@ -617,6 +617,29 @@ void QgsProjectFileTransform::transform2200to2300()

void QgsProjectFileTransform::transform2990()
{
QDomNodeList srsNodes = mDom.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
if ( srsNodes.count() > 0 )
{
QDomElement srsElem = srsNodes.at( 0 ).toElement();
QDomNodeList projNodes = srsElem.elementsByTagName( "ProjectionsEnabled" );
if ( projNodes.count() == 0 )
{
QDomElement projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projElem.setAttribute( "type", "int" );
projElem.setNodeValue( "0" );
srsElem.appendChild( projElem );
}
}
else
{
QDomElement srsElem = mDom.createElement( QStringLiteral( "SpatialRefSys" ) );
mDom.appendChild( srsElem );
QDomElement projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projElem.setAttribute( "type", "int" );
projElem.setNodeValue( "0" );
srsElem.appendChild( projElem );
}

QDomNodeList mapLayers = mDom.elementsByTagName( QStringLiteral( "maplayer" ) );

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

0 comments on commit 1aee424

Please sign in to comment.