Skip to content

Commit

Permalink
Silence annoying 'appendChild() on a null node does nothing' warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 1, 2018
1 parent 9d9955e commit 0449874
Showing 1 changed file with 100 additions and 96 deletions.
196 changes: 100 additions & 96 deletions src/core/qgsprojectfiletransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down

0 comments on commit 0449874

Please sign in to comment.