Skip to content

Commit

Permalink
return empty CRS instead of 4326 if the XML is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and nyalldawson committed Jan 16, 2018
1 parent d426a8d commit 2c511d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion python/core/qgscoordinatereferencesystem.sip
Expand Up @@ -507,7 +507,7 @@ pieces of information about CRS.
bool readXml( const QDomNode &node );
%Docstring
Restores state from the given DOM node.
If it fails or if the node is empty, a default not empty CRS will be returned.
If it fails or if the node is empty, a default empty CRS will be returned.

:param node: The node from which state will be restored

Expand Down
7 changes: 2 additions & 5 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1397,9 +1397,6 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )

//make sure the map units have been set
setMapUnits();

//@TODO this srs needs to be validated!!!
d->mIsValid = true; //shamelessly hard coded for now
}
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
Expand All @@ -1417,8 +1414,8 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
}
else
{
// Return default CRS if none was found in the XML.
createFromId( GEOCRS_ID, InternalCrsId );
// Return empty CRS if none was found in the XML.
d = new QgsCoordinateReferenceSystemPrivate();
result = false;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscoordinatereferencesystem.h
Expand Up @@ -466,7 +466,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

/**
* Restores state from the given DOM node.
* If it fails or if the node is empty, a default not empty CRS will be returned.
* If it fails or if the node is empty, a default empty CRS will be returned.
* \param node The node from which state will be restored
* \returns bool True on success, False on failure
*/
Expand Down
45 changes: 32 additions & 13 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -62,8 +62,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void equality();
void noEquality();
void equalityInvalid();
void readXml();
void writeXml();
void readWriteXml();
void setCustomSrsValidation();
void customSrsValidation();
void postgisSrid();
Expand Down Expand Up @@ -600,18 +599,38 @@ void TestQgsCoordinateReferenceSystem::equalityInvalid()
QgsCoordinateReferenceSystem invalidCrs2;
QVERIFY( invalidCrs1 == invalidCrs2 );
}
void TestQgsCoordinateReferenceSystem::readXml()
void TestQgsCoordinateReferenceSystem::readWriteXml()
{
//QgsCoordinateReferenceSystem myCrs;
//myCrs.createFromSrid( GEOSRID );
//QgsCoordinateReferenceSystem myCrs2;
//QVERIFY( myCrs2.readXml( QDomNode & node ) );
}
void TestQgsCoordinateReferenceSystem::writeXml()
{
//QgsCoordinateReferenceSystem myCrs;
//bool writeXml( QDomNode & node, QDomDocument & doc ) const;
//QVERIFY( myCrs.isValid() );
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.isValid() );
QDomDocument document( "test" );
QDomElement node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
QVERIFY( myCrs.writeXml( node, document ) );
QgsCoordinateReferenceSystem myCrs2;
QVERIFY( myCrs2.readXml( node ) );
QVERIFY( myCrs == myCrs2 );

// Empty XML made from writeXml operation
QgsCoordinateReferenceSystem myCrs3;
QDomDocument document2( "test" );
QDomElement node2 = document2.createElement( QStringLiteral( "crs" ) );
document2.appendChild( node2 );
QVERIFY( ! myCrs3.isValid() );
QVERIFY( myCrs3.writeXml( node2, document2 ) );
QgsCoordinateReferenceSystem myCrs4;
QVERIFY( myCrs4.readXml( node2 ) );
QVERIFY( ! myCrs4.isValid() );
QVERIFY( myCrs3 == myCrs4 );

// Empty XML node
QDomDocument document3( "test" );
QDomElement node3 = document3.createElement( QStringLiteral( "crs" ) );
document3.appendChild( node3 );
QgsCoordinateReferenceSystem myCrs5;
QVERIFY( ! myCrs5.readXml( node3 ) );
QVERIFY( myCrs5 == QgsCoordinateReferenceSystem() );
}
void TestQgsCoordinateReferenceSystem::setCustomSrsValidation()
{
Expand Down

0 comments on commit 2c511d2

Please sign in to comment.