Skip to content
Permalink
Browse files

[composer] Write a dummy Grid element when saving composer maps, fixe…

…s crash when loading project in older QGIS versions (fix #10905)
  • Loading branch information
nyalldawson committed Jul 19, 2014
1 parent 66031f6 commit 5a6f68bed4e786d2d80e0aca9024728e1f4bdbfc
Showing with 17 additions and 11 deletions.
  1. +17 −11 src/core/composer/qgscomposermap.cpp
@@ -1178,6 +1178,10 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
//overview map frame
composerMapElem.setAttribute( "overviewFrameMap", mOverviewFrameMapId );

//write a dummy "Grid" element to prevent crashes on pre 2.5 versions (refs #10905)
QDomElement gridElem = doc.createElement( "Grid" );
composerMapElem.appendChild( gridElem );

QList< QgsComposerMapGrid* >::const_iterator gridIt = mGrids.constBegin();
for ( ; gridIt != mGrids.constEnd(); ++gridIt )
{
@@ -1317,9 +1321,21 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mNumCachedLayers = 0;
mCacheUpdated = false;

//grids
QDomNodeList mapGridNodeList = itemElem.elementsByTagName( "ComposerMapGrid" );
for ( int i = 0; i < mapGridNodeList.size(); ++i )
{
QDomElement mapGridElem = mapGridNodeList.at( i ).toElement();
QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( mapGridElem.attribute( "name" ), this );
mapGrid->readXML( mapGridElem, doc );
mGrids.append( mapGrid );
}

//load grid / grid annotation in old xml format
//only do this if we don't have the newer ComposerMapGrid element, otherwise this will
//be the dummy element created by QGIS >= 2.5 (refs #10905)
QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
if ( gridNodeList.size() > 0 )
if ( mapGridNodeList.size() == 0 && gridNodeList.size() > 0 )
{
QDomElement gridElem = gridNodeList.at( 0 ).toElement();
QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( gridCount() + 1 ), this );
@@ -1380,16 +1396,6 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mGrids.append( mapGrid );
}

//grids
QDomNodeList mapGridNodeList = itemElem.elementsByTagName( "ComposerMapGrid" );
for ( int i = 0; i < mapGridNodeList.size(); ++i )
{
QDomElement mapGridElem = mapGridNodeList.at( i ).toElement();
QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( mapGridElem.attribute( "name" ), this );
mapGrid->readXML( mapGridElem, doc );
mGrids.append( mapGrid );
}

//atlas
QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
if ( atlasNodeList.size() > 0 )

0 comments on commit 5a6f68b

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