Skip to content
Permalink
Browse files

Restore projects with OTF off to "no projection" (fix #16338)

  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 798f0f7 commit 1aee4246e0836ace38896a1cc1ac7f6f6bf00fd0
Showing with 39 additions and 8 deletions.
  1. +15 −8 src/core/qgsproject.cpp
  2. +1 −0 src/core/qgsproject.h
  3. +23 −0 src/core/qgsprojectfiletransform.cpp
@@ -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();
}

@@ -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() )
{
@@ -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
};

@@ -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 )

0 comments on commit 1aee424

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