@@ -198,6 +198,8 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, const QS
198
198
{
199
199
const QgsMapSettings &ms = mComposition ->mapSettings ();
200
200
201
+ QScopedPointer< QgsExpressionContext > expressionContext ( createExpressionContext () );
202
+
201
203
QgsMapSettings jobMapSettings;
202
204
jobMapSettings.setExtent ( extent );
203
205
jobMapSettings.setOutputSize ( size.toSize () );
@@ -208,7 +210,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, const QS
208
210
jobMapSettings.setRotation ( mEvaluatedMapRotation );
209
211
210
212
// set layers to render
211
- QStringList theLayerSet = layersToRender ();
213
+ QStringList theLayerSet = layersToRender ( expressionContext. data () );
212
214
if ( -1 != mCurrentExportLayer )
213
215
{
214
216
// exporting with separate layers (eg, to svg layers), so we only want to render a single map layer
@@ -219,7 +221,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, const QS
219
221
: QStringList (); // exporting decorations such as map frame/grid/overview, so no map layers required
220
222
}
221
223
jobMapSettings.setLayers ( theLayerSet );
222
- jobMapSettings.setLayerStyleOverrides ( layerStyleOverridesToRender () );
224
+ jobMapSettings.setLayerStyleOverrides ( layerStyleOverridesToRender ( *expressionContext ) );
223
225
jobMapSettings.setDestinationCrs ( ms.destinationCrs () );
224
226
jobMapSettings.setCrsTransformEnabled ( ms.hasCrsTransformEnabled () );
225
227
jobMapSettings.setFlags ( ms.flags () );
@@ -523,12 +525,20 @@ const QgsMapRenderer *QgsComposerMap::mapRenderer() const
523
525
Q_NOWARN_DEPRECATED_POP
524
526
}
525
527
526
- QStringList QgsComposerMap::layersToRender () const
528
+ QStringList QgsComposerMap::layersToRender ( const QgsExpressionContext* context ) const
527
529
{
530
+ const QgsExpressionContext* evalContext = context;
531
+ QScopedPointer< QgsExpressionContext > scopedContext;
532
+ if ( !evalContext )
533
+ {
534
+ scopedContext.reset ( createExpressionContext () );
535
+ evalContext = scopedContext.data ();
536
+ }
537
+
528
538
QStringList renderLayerSet;
529
539
530
540
QVariant exprVal;
531
- if ( dataDefinedEvaluate ( QgsComposerObject::MapStylePreset, exprVal ) )
541
+ if ( dataDefinedEvaluate ( QgsComposerObject::MapStylePreset, exprVal, *evalContext ) )
532
542
{
533
543
QString presetName = exprVal.toString ();
534
544
@@ -549,7 +559,7 @@ QStringList QgsComposerMap::layersToRender() const
549
559
}
550
560
}
551
561
552
- if ( dataDefinedEvaluate ( QgsComposerObject::MapLayers, exprVal ) )
562
+ if ( dataDefinedEvaluate ( QgsComposerObject::MapLayers, exprVal, *evalContext ) )
553
563
{
554
564
renderLayerSet.clear ();
555
565
@@ -583,10 +593,10 @@ QStringList QgsComposerMap::layersToRender() const
583
593
return renderLayerSet;
584
594
}
585
595
586
- QMap<QString, QString> QgsComposerMap::layerStyleOverridesToRender () const
596
+ QMap<QString, QString> QgsComposerMap::layerStyleOverridesToRender ( const QgsExpressionContext& context ) const
587
597
{
588
598
QVariant exprVal;
589
- if ( dataDefinedEvaluate ( QgsComposerObject::MapStylePreset, exprVal ) )
599
+ if ( dataDefinedEvaluate ( QgsComposerObject::MapStylePreset, exprVal, context ) )
590
600
{
591
601
QString presetName = exprVal.toString ();
592
602
@@ -2175,7 +2185,7 @@ void QgsComposerMap::refreshDataDefinedProperty( const QgsComposerObject::DataDe
2175
2185
property == QgsComposerObject::AllProperties )
2176
2186
{
2177
2187
QgsRectangle beforeExtent = *currentMapExtent ();
2178
- refreshMapExtents ();
2188
+ refreshMapExtents ( evalContext );
2179
2189
emit itemChanged ();
2180
2190
if ( *currentMapExtent () != beforeExtent )
2181
2191
{
0 commit comments