Skip to content
Permalink
Browse files

Fix crash when writing CRS to XML using QgsXmlUtils

Fixes a crash when saving a processing model using a CRS input
  • Loading branch information
nyalldawson committed Sep 18, 2018
1 parent 9503ffa commit 9ac33124ecd4449f9e6220ef74f608ef63a7c9f6
Showing with 35 additions and 2 deletions.
  1. +1 −0 src/core/qgsapplication.cpp
  2. +13 −0 src/core/qgsxmlutils.cpp
  3. +21 −2 tests/src/python/test_qgsxmlutils.py
@@ -199,6 +199,7 @@ void QgsApplication::init( QString profileFolder )
qRegisterMetaType<QgsReferencedPointXY>( "QgsReferencedPointXY" );
qRegisterMetaType<QgsLayoutRenderContext::Flags>( "QgsLayoutRenderContext::Flags" );
qRegisterMetaType<QgsStyle::StyleEntity>( "QgsStyle::StyleEntity" );
qRegisterMetaType<QgsCoordinateReferenceSystem>( "QgsCoordinateReferenceSystem" );

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
// QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );
@@ -168,6 +168,13 @@ QDomElement QgsXmlUtils::writeVariant( const QVariant &value, QDomDocument &doc
element.appendChild( propertyElem );
break;
}
else if ( value.canConvert< QgsCoordinateReferenceSystem >() )
{
element.setAttribute( QStringLiteral( "type" ), QStringLiteral( "QgsCoordinateReferenceSystem" ) );
const QgsCoordinateReferenceSystem crs = value.value< QgsCoordinateReferenceSystem >();
crs.writeXml( element, doc );
break;
}
FALLTHROUGH
}

@@ -250,6 +257,12 @@ QVariant QgsXmlUtils::readVariant( const QDomElement &element )

return QVariant();
}
else if ( type == QLatin1String( "QgsCoordinateReferenceSystem" ) )
{
QgsCoordinateReferenceSystem crs;
crs.readXml( element );
return crs;
}
else
{
return QVariant();
@@ -15,13 +15,13 @@
import qgis # NOQA switch sip api

from qgis.core import (QgsXmlUtils,
QgsProperty)
QgsProperty,
QgsCoordinateReferenceSystem)

from qgis.PyQt.QtXml import QDomDocument

from qgis.testing import start_app, unittest


start_app()


@@ -141,6 +141,25 @@ def test_property(self):

self.assertEqual(prop, prop2)

def test_crs(self):
"""
Test that QgsCoordinateReferenceSystem values are correctly loaded and written
"""
doc = QDomDocument("properties")

crs = QgsCoordinateReferenceSystem('epsg:3111')
elem = QgsXmlUtils.writeVariant(crs, doc)

crs2 = QgsXmlUtils.readVariant(elem)
self.assertTrue(crs2.isValid())
self.assertEqual(crs2.authid(), 'EPSG:3111')

crs = QgsCoordinateReferenceSystem()
elem = QgsXmlUtils.writeVariant(crs, doc)

crs2 = QgsXmlUtils.readVariant(elem)
self.assertFalse(crs2.isValid())


if __name__ == '__main__':
unittest.main()

0 comments on commit 9ac3312

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