@@ -68,13 +68,9 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition )
68
68
// default to no background
69
69
setBackgroundEnabled ( false );
70
70
71
- if ( mComposition && mComposition ->atlasMode () == QgsComposition::PreviewAtlas )
72
- {
73
- // a label added while atlas preview is enabled needs to have the expression context set,
74
- // otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
75
- QgsFeature atlasFeature = mComposition ->atlasComposition ().feature ();
76
- setExpressionContext ( &atlasFeature, mComposition ->atlasComposition ().coverageLayer () );
77
- }
71
+ // a label added while atlas preview is enabled needs to have the expression context set,
72
+ // otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
73
+ refreshExpressionContext ();
78
74
79
75
if ( mComposition )
80
76
{
@@ -236,7 +232,7 @@ void QgsComposerLabel::setHtmlState( int state )
236
232
237
233
void QgsComposerLabel::setExpressionContext ( QgsFeature *feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions )
238
234
{
239
- mExpressionFeature = feature ? *feature : QgsFeature ( );
235
+ mExpressionFeature . reset ( feature ? new QgsFeature ( *feature ) : 0 );
240
236
mExpressionLayer = layer;
241
237
mSubstitutions = substitutions;
242
238
@@ -260,21 +256,42 @@ void QgsComposerLabel::setExpressionContext( QgsFeature *feature, QgsVectorLayer
260
256
update ();
261
257
}
262
258
259
+ void QgsComposerLabel::setSubstitutions ( QMap<QString, QVariant> substitutions )
260
+ {
261
+ mSubstitutions = substitutions;
262
+ }
263
+
263
264
void QgsComposerLabel::refreshExpressionContext ()
264
265
{
265
- QgsVectorLayer * vl = 0 ;
266
- QgsFeature feature;
266
+ mExpressionLayer = 0 ;
267
+ mExpressionFeature .reset ();
268
+
269
+ if ( !mComposition )
270
+ return ;
267
271
268
272
if ( mComposition ->atlasComposition ().enabled () )
269
273
{
270
- vl = mComposition ->atlasComposition ().coverageLayer ();
274
+ mExpressionLayer = mComposition ->atlasComposition ().coverageLayer ();
275
+ if ( mComposition ->atlasMode () != QgsComposition::AtlasOff )
276
+ {
277
+ mExpressionFeature .reset ( new QgsFeature ( mComposition ->atlasComposition ().feature () ) );
278
+ }
279
+ }
280
+
281
+ // setup distance area conversion
282
+ if ( mExpressionLayer )
283
+ {
284
+ mDistanceArea ->setSourceCrs ( mExpressionLayer ->crs ().srsid () );
271
285
}
272
- if ( mComposition -> atlasMode () != QgsComposition::AtlasOff )
286
+ else
273
287
{
274
- feature = mComposition ->atlasComposition ().feature ();
288
+ // set to composition's mapsettings' crs
289
+ mDistanceArea ->setSourceCrs ( mComposition ->mapSettings ().destinationCrs ().srsid () );
275
290
}
291
+ mDistanceArea ->setEllipsoidalMode ( mComposition ->mapSettings ().hasCrsTransformEnabled () );
292
+ mDistanceArea ->setEllipsoid ( QgsProject::instance ()->readEntry ( " Measure" , " /Ellipsoid" , GEO_NONE ) );
276
293
277
- setExpressionContext ( &feature, vl );
294
+ update ( );
278
295
}
279
296
280
297
QString QgsComposerLabel::displayText () const
@@ -283,7 +300,7 @@ QString QgsComposerLabel::displayText() const
283
300
replaceDateText ( displayText );
284
301
QMap<QString, QVariant> subs = mSubstitutions ;
285
302
subs[ " $page" ] = QVariant (( int )mComposition ->itemPageNumber ( this ) + 1 );
286
- return QgsExpression::replaceExpressionText ( displayText, & mExpressionFeature , mExpressionLayer , &subs, mDistanceArea );
303
+ return QgsExpression::replaceExpressionText ( displayText, mExpressionFeature . data () , mExpressionLayer , &subs, mDistanceArea );
287
304
}
288
305
289
306
void QgsComposerLabel::replaceDateText ( QString& text ) const
0 commit comments