@@ -124,9 +124,6 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
124124
125125void QgsComposerMap::init ()
126126{
127- if ( mComposition && mComposition ->project () )
128- mCrs = mComposition ->project ()->crs ();
129-
130127 mGridStack = new QgsComposerMapGridStack ( this );
131128 mOverviewStack = new QgsComposerMapOverviewStack ( this );
132129 connectUpdateSlot ();
@@ -204,14 +201,15 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, QSizeF
204201QgsMapSettings QgsComposerMap::mapSettings ( const QgsRectangle& extent, QSizeF size, int dpi ) const
205202{
206203 QgsExpressionContext expressionContext = createExpressionContext ();
204+ QgsCoordinateReferenceSystem renderCrs = crs ();
207205
208206 QgsMapSettings jobMapSettings;
209- jobMapSettings.setDestinationCrs ( mCrs );
207+ jobMapSettings.setDestinationCrs ( renderCrs );
210208 jobMapSettings.setCrsTransformEnabled ( true );
211209 jobMapSettings.setExtent ( extent );
212210 jobMapSettings.setOutputSize ( size.toSize () );
213211 jobMapSettings.setOutputDpi ( dpi );
214- jobMapSettings.setMapUnits ( mCrs .mapUnits () );
212+ jobMapSettings.setMapUnits ( renderCrs .mapUnits () );
215213 jobMapSettings.setBackgroundColor ( Qt::transparent );
216214 jobMapSettings.setRotation ( mEvaluatedMapRotation );
217215
@@ -253,7 +251,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF s
253251 jobMapSettings.setFlag ( QgsMapSettings::DrawSelection, false );
254252 jobMapSettings.setFlag ( QgsMapSettings::UseAdvancedEffects, mComposition ->useAdvancedEffects () ); // respect the composition's useAdvancedEffects flag
255253
256- jobMapSettings.datumTransformStore ().setDestinationCrs ( mCrs );
254+ jobMapSettings.datumTransformStore ().setDestinationCrs ( renderCrs );
257255
258256 return jobMapSettings;
259257}
@@ -873,7 +871,11 @@ QgsRectangle* QgsComposerMap::currentMapExtent()
873871
874872QgsCoordinateReferenceSystem QgsComposerMap::crs () const
875873{
876- return mCrs ;
874+ if ( mCrs .isValid () )
875+ return mCrs ;
876+ else if ( mComposition && mComposition ->project () )
877+ return mComposition ->project ()->crs ();
878+ return QgsCoordinateReferenceSystem ();
877879}
878880
879881void QgsComposerMap::setCrs ( const QgsCoordinateReferenceSystem& crs )
@@ -1271,9 +1273,12 @@ bool QgsComposerMap::writeXml( QDomElement& elem, QDomDocument & doc ) const
12711273 extentElem.setAttribute ( QStringLiteral ( " ymax" ), qgsDoubleToString ( mExtent .yMaximum () ) );
12721274 composerMapElem.appendChild ( extentElem );
12731275
1274- QDomElement crsElem = doc.createElement ( QStringLiteral ( " crs" ) );
1275- mCrs .writeXml ( crsElem, doc );
1276- composerMapElem.appendChild ( crsElem );
1276+ if ( mCrs .isValid () )
1277+ {
1278+ QDomElement crsElem = doc.createElement ( QStringLiteral ( " crs" ) );
1279+ mCrs .writeXml ( crsElem, doc );
1280+ composerMapElem.appendChild ( crsElem );
1281+ }
12771282
12781283 // follow map theme
12791284 composerMapElem.setAttribute ( QStringLiteral ( " followPreset" ), mFollowVisibilityPreset ? " true" : " false" );
@@ -1382,6 +1387,10 @@ bool QgsComposerMap::readXml( const QDomElement& itemElem, const QDomDocument& d
13821387 QDomElement crsElem = crsNodeList.at ( 0 ).toElement ();
13831388 mCrs .readXml ( crsElem );
13841389 }
1390+ else
1391+ {
1392+ mCrs = QgsCoordinateReferenceSystem ();
1393+ }
13851394
13861395 // map rotation
13871396 if ( !qgsDoubleNear ( itemElem.attribute ( QStringLiteral ( " mapRotation" ), QStringLiteral ( " 0" ) ).toDouble (), 0.0 ) )
0 commit comments