Skip to content
Permalink
Browse files

Use expression contexts when rendering symbols in composer items

(eg shape fills, arrow line styles, overview frames, grid lines)
  • Loading branch information
nyalldawson committed Sep 2, 2015
1 parent caa3c34 commit 03d4f637c7a0267ed14abbf35b038c613a1d12e2
@@ -186,6 +186,9 @@ void QgsComposerArrow::drawLine( QPainter *painter )
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setForceVectorOutput( true );
context.setPainter( painter );
QgsExpressionContext* expressionContext = createExpressionContext();
context.setExpressionContext( *expressionContext );
delete expressionContext;

//line scaled to dots
QPolygonF line;
@@ -656,6 +656,9 @@ void QgsComposerMapGrid::draw( QPainter* p )
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setForceVectorOutput( true );
context.setPainter( p );
QgsExpressionContext* expressionContext = createExpressionContext();
context.setExpressionContext( *expressionContext );
delete expressionContext;

QList< QPair< double, QLineF > > verticalLines;
QList< QPair< double, QLineF > > horizontalLines;
@@ -97,6 +97,9 @@ void QgsComposerMapOverview::draw( QPainter *painter )
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setForceVectorOutput( true );
context.setPainter( painter );
QgsExpressionContext* expressionContext = createExpressionContext();
context.setExpressionContext( *expressionContext );
delete expressionContext;

painter->save();
painter->setCompositionMode( mBlendMode );
@@ -182,6 +182,10 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setPainter( p );
context.setForceVectorOutput( true );
QgsExpressionContext* expressionContext = createExpressionContext();
context.setExpressionContext( *expressionContext );
delete expressionContext;

p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots

//generate polygon to draw
@@ -232,21 +236,9 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
}

mShapeStyleSymbol->startRender( context );

//need to render using atlas feature properties?
if ( mComposition->atlasComposition().enabled() && mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//using an atlas, so render using current atlas feature
//since there may be data defined symbols using atlas feature properties
QgsFeature atlasFeature = mComposition->atlasComposition().feature();
mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, &atlasFeature, context );
}
else
{
mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, 0, context );
}

mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, 0, context );
mShapeStyleSymbol->stopRender( context );

p->restore();
}

@@ -164,6 +164,9 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setPainter( painter );
context.setForceVectorOutput( true );
QgsExpressionContext* expressionContext = createExpressionContext();
context.setExpressionContext( *expressionContext );
delete expressionContext;

painter->save();

@@ -194,19 +197,7 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) );
QList<QPolygonF> rings; //empty list

//need to render using atlas feature properties?
if ( mComposition->atlasComposition().enabled() && mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//using an atlas, so render using current atlas feature
//since there may be data defined symbols using atlas feature properties
QgsFeature atlasFeature = mComposition->atlasComposition().feature();
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, &atlasFeature, context );
}
else
{
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );
}

mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );
mComposition->pageStyleSymbol()->stopRender( context );
painter->restore();
}

0 comments on commit 03d4f63

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