Skip to content

Commit

Permalink
Use expression contexts when rendering symbols in composer items
Browse files Browse the repository at this point in the history
(eg shape fills, arrow line styles, overview frames, grid lines)
  • Loading branch information
nyalldawson committed Sep 2, 2015
1 parent caa3c34 commit 03d4f63
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermapgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermapoverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
20 changes: 6 additions & 14 deletions src/core/composer/qgscomposershape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
17 changes: 4 additions & 13 deletions src/core/composer/qgspaperitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 03d4f63

Please sign in to comment.