Skip to content
Permalink
Browse files

Silence annoying 'appendChild() on a null node does nothing' warning

(cherry-picked from 0449874)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent c5e7998 commit 4395b8ed772c8f98c31394787ca1b5da0e4e2211
Showing with 100 additions and 96 deletions.
  1. +100 −96 src/core/qgsprojectfiletransform.cpp
@@ -625,115 +625,119 @@ void QgsProjectFileTransform::transform2990()
{
// transform OTF off to "no projection" for project
QDomElement propsElem = mDom.firstChildElement( QStringLiteral( "qgis" ) ).toElement().firstChildElement( QStringLiteral( "properties" ) );
QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
QDomElement srsElem;
QDomElement projElem;
if ( srsNodes.count() > 0 )
if ( !propsElem.isNull() )
{
srsElem = srsNodes.at( 0 ).toElement();
QDomNodeList projNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectionsEnabled" ) );
if ( projNodes.count() == 0 )
QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
QDomElement srsElem;
QDomElement projElem;
if ( srsNodes.count() > 0 )
{
srsElem = srsNodes.at( 0 ).toElement();
QDomNodeList projNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectionsEnabled" ) );
if ( projNodes.count() == 0 )
{
projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projText = mDom.createTextNode( QStringLiteral( "0" ) );
projElem.appendChild( projText );
srsElem.appendChild( projElem );
}
}
else
{
srsElem = mDom.createElement( QStringLiteral( "SpatialRefSys" ) );
projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projText = mDom.createTextNode( QStringLiteral( "0" ) );
projElem.appendChild( projText );
srsElem.appendChild( projElem );
propsElem.appendChild( srsElem );
}
}
else
{
srsElem = mDom.createElement( QStringLiteral( "SpatialRefSys" ) );
projElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projText = mDom.createTextNode( QStringLiteral( "0" ) );
projElem.appendChild( projText );
srsElem.appendChild( projElem );
propsElem.appendChild( srsElem );
}
// transform map canvas CRS to project CRS - this is because project CRS was inconsistently used
// prior to 3.0. In >= 3.0 main canvas CRS is forced to match project CRS, so we need to make
// sure we can read the project CRS correctly
QDomNodeList canvasNodes = mDom.elementsByTagName( QStringLiteral( "mapcanvas" ) );
if ( canvasNodes.count() > 0 )
{
QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral( "spatialrefsys" ) );
if ( canvasSrsNodes.count() > 0 )
{
QDomElement canvasSrsElem = canvasSrsNodes.at( 0 ).toElement();
QString proj;
QString authid;
QString srsid;

QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName( QStringLiteral( "proj4" ) );
if ( proj4Nodes.count() > 0 )
{
QDomElement proj4Node = proj4Nodes.at( 0 ).toElement();
proj = proj4Node.text();
}
QDomNodeList authidNodes = canvasSrsElem.elementsByTagName( QStringLiteral( "authid" ) );
if ( authidNodes.count() > 0 )
{
QDomElement authidNode = authidNodes.at( 0 ).toElement();
authid = authidNode.text();
}
QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName( QStringLiteral( "srsid" ) );
if ( srsidNodes.count() > 0 )
// transform map canvas CRS to project CRS - this is because project CRS was inconsistently used
// prior to 3.0. In >= 3.0 main canvas CRS is forced to match project CRS, so we need to make
// sure we can read the project CRS correctly
QDomNodeList canvasNodes = mDom.elementsByTagName( QStringLiteral( "mapcanvas" ) );
if ( canvasNodes.count() > 0 )
{
QDomElement canvasElem = canvasNodes.at( 0 ).toElement();
QDomNodeList canvasSrsNodes = canvasElem.elementsByTagName( QStringLiteral( "spatialrefsys" ) );
if ( canvasSrsNodes.count() > 0 )
{
QDomElement srsidNode = srsidNodes.at( 0 ).toElement();
srsid = srsidNode.text();
}
QDomElement canvasSrsElem = canvasSrsNodes.at( 0 ).toElement();
QString proj;
QString authid;
QString srsid;

// clear existing project CRS nodes
QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCRSProj4String" ) );
for ( int i = oldProjectProj4Nodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectProj4Nodes.at( i ) );
}
QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCrs" ) );
for ( int i = oldProjectCrsNodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectCrsNodes.at( i ) );
}
QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCRSID" ) );
for ( int i = oldProjectCrsIdNodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectCrsIdNodes.at( i ) );
}
QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectionsEnabled" ) );
for ( int i = projectionsEnabledNodes.count(); i >= 0; --i )
{
srsElem.removeChild( projectionsEnabledNodes.at( i ) );
}
QDomNodeList proj4Nodes = canvasSrsElem.elementsByTagName( QStringLiteral( "proj4" ) );
if ( proj4Nodes.count() > 0 )
{
QDomElement proj4Node = proj4Nodes.at( 0 ).toElement();
proj = proj4Node.text();
}
QDomNodeList authidNodes = canvasSrsElem.elementsByTagName( QStringLiteral( "authid" ) );
if ( authidNodes.count() > 0 )
{
QDomElement authidNode = authidNodes.at( 0 ).toElement();
authid = authidNode.text();
}
QDomNodeList srsidNodes = canvasSrsElem.elementsByTagName( QStringLiteral( "srsid" ) );
if ( srsidNodes.count() > 0 )
{
QDomElement srsidNode = srsidNodes.at( 0 ).toElement();
srsid = srsidNode.text();
}

QDomElement proj4Elem = mDom.createElement( QStringLiteral( "ProjectCRSProj4String" ) );
proj4Elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "QString" ) );
QDomText proj4Text = mDom.createTextNode( proj );
proj4Elem.appendChild( proj4Text );
QDomElement projectCrsElem = mDom.createElement( QStringLiteral( "ProjectCrs" ) );
projectCrsElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "QString" ) );
QDomText projectCrsText = mDom.createTextNode( authid );
projectCrsElem.appendChild( projectCrsText );
QDomElement projectCrsIdElem = mDom.createElement( QStringLiteral( "ProjectCRSID" ) );
projectCrsIdElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText srsidText = mDom.createTextNode( srsid );
projectCrsIdElem.appendChild( srsidText );
QDomElement projectionsEnabledElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projectionsEnabledElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projectionsEnabledText = mDom.createTextNode( QStringLiteral( "1" ) );
projectionsEnabledElem.appendChild( projectionsEnabledText );
srsElem.appendChild( proj4Elem );
srsElem.appendChild( projectCrsElem );
srsElem.appendChild( projectCrsIdElem );
srsElem.appendChild( projectionsEnabledElem );

QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
for ( int i = srsNodes.count(); i >= 0; --i )
{
propsElem.removeChild( srsNodes.at( i ) );
// clear existing project CRS nodes
QDomNodeList oldProjectProj4Nodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCRSProj4String" ) );
for ( int i = oldProjectProj4Nodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectProj4Nodes.at( i ) );
}
QDomNodeList oldProjectCrsNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCrs" ) );
for ( int i = oldProjectCrsNodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectCrsNodes.at( i ) );
}
QDomNodeList oldProjectCrsIdNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectCRSID" ) );
for ( int i = oldProjectCrsIdNodes.count(); i >= 0; --i )
{
srsElem.removeChild( oldProjectCrsIdNodes.at( i ) );
}
QDomNodeList projectionsEnabledNodes = srsElem.elementsByTagName( QStringLiteral( "ProjectionsEnabled" ) );
for ( int i = projectionsEnabledNodes.count(); i >= 0; --i )
{
srsElem.removeChild( projectionsEnabledNodes.at( i ) );
}

QDomElement proj4Elem = mDom.createElement( QStringLiteral( "ProjectCRSProj4String" ) );
proj4Elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "QString" ) );
QDomText proj4Text = mDom.createTextNode( proj );
proj4Elem.appendChild( proj4Text );
QDomElement projectCrsElem = mDom.createElement( QStringLiteral( "ProjectCrs" ) );
projectCrsElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "QString" ) );
QDomText projectCrsText = mDom.createTextNode( authid );
projectCrsElem.appendChild( projectCrsText );
QDomElement projectCrsIdElem = mDom.createElement( QStringLiteral( "ProjectCRSID" ) );
projectCrsIdElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText srsidText = mDom.createTextNode( srsid );
projectCrsIdElem.appendChild( srsidText );
QDomElement projectionsEnabledElem = mDom.createElement( QStringLiteral( "ProjectionsEnabled" ) );
projectionsEnabledElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
QDomText projectionsEnabledText = mDom.createTextNode( QStringLiteral( "1" ) );
projectionsEnabledElem.appendChild( projectionsEnabledText );
srsElem.appendChild( proj4Elem );
srsElem.appendChild( projectCrsElem );
srsElem.appendChild( projectCrsIdElem );
srsElem.appendChild( projectionsEnabledElem );

QDomNodeList srsNodes = propsElem.elementsByTagName( QStringLiteral( "SpatialRefSys" ) );
for ( int i = srsNodes.count(); i >= 0; --i )
{
propsElem.removeChild( srsNodes.at( i ) );
}
propsElem.appendChild( srsElem );
}
propsElem.appendChild( srsElem );
}
}

0 comments on commit 4395b8e

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