Skip to content

Commit 2c511d2

Browse files
Gustrynyalldawson
authored andcommittedJan 16, 2018
return empty CRS instead of 4326 if the XML is empty
1 parent d426a8d commit 2c511d2

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed
 

‎python/core/qgscoordinatereferencesystem.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pieces of information about CRS.
507507
bool readXml( const QDomNode &node );
508508
%Docstring
509509
Restores state from the given DOM node.
510-
If it fails or if the node is empty, a default not empty CRS will be returned.
510+
If it fails or if the node is empty, a default empty CRS will be returned.
511511

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

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,6 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
13971397

13981398
//make sure the map units have been set
13991399
setMapUnits();
1400-
1401-
//@TODO this srs needs to be validated!!!
1402-
d->mIsValid = true; //shamelessly hard coded for now
14031400
}
14041401
//TODO: createFromProj4 used to save to the user database any new CRS
14051402
// this behavior was changed in order to separate creation and saving.
@@ -1417,8 +1414,8 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
14171414
}
14181415
else
14191416
{
1420-
// Return default CRS if none was found in the XML.
1421-
createFromId( GEOCRS_ID, InternalCrsId );
1417+
// Return empty CRS if none was found in the XML.
1418+
d = new QgsCoordinateReferenceSystemPrivate();
14221419
result = false;
14231420
}
14241421
return result;

‎src/core/qgscoordinatereferencesystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
466466

467467
/**
468468
* Restores state from the given DOM node.
469-
* If it fails or if the node is empty, a default not empty CRS will be returned.
469+
* If it fails or if the node is empty, a default empty CRS will be returned.
470470
* \param node The node from which state will be restored
471471
* \returns bool True on success, False on failure
472472
*/

‎tests/src/core/testqgscoordinatereferencesystem.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
6262
void equality();
6363
void noEquality();
6464
void equalityInvalid();
65-
void readXml();
66-
void writeXml();
65+
void readWriteXml();
6766
void setCustomSrsValidation();
6867
void customSrsValidation();
6968
void postgisSrid();
@@ -600,18 +599,38 @@ void TestQgsCoordinateReferenceSystem::equalityInvalid()
600599
QgsCoordinateReferenceSystem invalidCrs2;
601600
QVERIFY( invalidCrs1 == invalidCrs2 );
602601
}
603-
void TestQgsCoordinateReferenceSystem::readXml()
602+
void TestQgsCoordinateReferenceSystem::readWriteXml()
604603
{
605-
//QgsCoordinateReferenceSystem myCrs;
606-
//myCrs.createFromSrid( GEOSRID );
607-
//QgsCoordinateReferenceSystem myCrs2;
608-
//QVERIFY( myCrs2.readXml( QDomNode & node ) );
609-
}
610-
void TestQgsCoordinateReferenceSystem::writeXml()
611-
{
612-
//QgsCoordinateReferenceSystem myCrs;
613-
//bool writeXml( QDomNode & node, QDomDocument & doc ) const;
614-
//QVERIFY( myCrs.isValid() );
604+
QgsCoordinateReferenceSystem myCrs;
605+
myCrs.createFromSrid( GEOSRID );
606+
QVERIFY( myCrs.isValid() );
607+
QDomDocument document( "test" );
608+
QDomElement node = document.createElement( QStringLiteral( "crs" ) );
609+
document.appendChild( node );
610+
QVERIFY( myCrs.writeXml( node, document ) );
611+
QgsCoordinateReferenceSystem myCrs2;
612+
QVERIFY( myCrs2.readXml( node ) );
613+
QVERIFY( myCrs == myCrs2 );
614+
615+
// Empty XML made from writeXml operation
616+
QgsCoordinateReferenceSystem myCrs3;
617+
QDomDocument document2( "test" );
618+
QDomElement node2 = document2.createElement( QStringLiteral( "crs" ) );
619+
document2.appendChild( node2 );
620+
QVERIFY( ! myCrs3.isValid() );
621+
QVERIFY( myCrs3.writeXml( node2, document2 ) );
622+
QgsCoordinateReferenceSystem myCrs4;
623+
QVERIFY( myCrs4.readXml( node2 ) );
624+
QVERIFY( ! myCrs4.isValid() );
625+
QVERIFY( myCrs3 == myCrs4 );
626+
627+
// Empty XML node
628+
QDomDocument document3( "test" );
629+
QDomElement node3 = document3.createElement( QStringLiteral( "crs" ) );
630+
document3.appendChild( node3 );
631+
QgsCoordinateReferenceSystem myCrs5;
632+
QVERIFY( ! myCrs5.readXml( node3 ) );
633+
QVERIFY( myCrs5 == QgsCoordinateReferenceSystem() );
615634
}
616635
void TestQgsCoordinateReferenceSystem::setCustomSrsValidation()
617636
{

0 commit comments

Comments
 (0)
Please sign in to comment.