Skip to content
Permalink
Browse files

return empty CRS instead of 4326 if the XML is empty

  • Loading branch information
Gustry authored and nyalldawson committed Jan 14, 2018
1 parent d426a8d commit 2c511d25dce248e1f26dd8461072b282d4c1b68e
@@ -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

@@ -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.
@@ -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;
@@ -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
*/
@@ -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();
@@ -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()
{

0 comments on commit 2c511d2

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