Skip to content
Permalink
Browse files

Optimise rendering by skipping variable set when not required

  • Loading branch information
nyalldawson committed Mar 31, 2021
1 parent 2acd832 commit 24b6ae680f9401e613d914dabb286f1418dbecfe
Showing with 33 additions and 12 deletions.
  1. +22 −8 src/core/symbology/qgslinesymbollayer.cpp
  2. +11 −4 src/core/symbology/qgssymbollayer.cpp
@@ -279,8 +279,13 @@ void QgsSimpleLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, con
return;
}

QgsExpressionContextScope *scope = new QgsExpressionContextScope();
QgsExpressionContextScopePopper scopePopper( context.renderContext().expressionContext(), scope );
QgsExpressionContextScope *scope = nullptr;
std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
if ( hasDataDefinedProperties() )
{
scope = new QgsExpressionContextScope();
scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.renderContext().expressionContext(), scope );
}

if ( mDrawInsidePolygon )
p->save();
@@ -310,7 +315,8 @@ void QgsSimpleLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, con
p->setClipPath( clipPath, Qt::IntersectClip );
}

scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );

renderPolyline( points, context );
}
@@ -331,7 +337,8 @@ void QgsSimpleLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, con
int ringIndex = 1;
for ( const QPolygonF &ring : std::as_const( *rings ) )
{
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, ringIndex, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, ringIndex, true ) );

renderPolyline( ring, context );
ringIndex++;
@@ -1321,15 +1328,21 @@ void QgsTemplatedLineSymbolLayerBase::renderPolygonStroke( const QPolygonF &poin
context.renderContext().setGeometry( curvePolygon->exteriorRing() );
}

QgsExpressionContextScope *scope = new QgsExpressionContextScope();
QgsExpressionContextScopePopper scopePopper( context.renderContext().expressionContext(), scope );
QgsExpressionContextScope *scope = nullptr;
std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
if ( hasDataDefinedProperties() )
{
scope = new QgsExpressionContextScope();
scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.renderContext().expressionContext(), scope );
}

switch ( mRingFilter )
{
case AllRings:
case ExteriorRingOnly:
{
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );

renderPolyline( points, context );
break;
@@ -1352,7 +1365,8 @@ void QgsTemplatedLineSymbolLayerBase::renderPolygonStroke( const QPolygonF &poin
{
context.renderContext().setGeometry( curvePolygon->interiorRing( i ) );
}
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, i + 1, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, i + 1, true ) );

renderPolyline( rings->at( i ), context );
}
@@ -694,15 +694,21 @@ void QgsLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &context, QSize

void QgsLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, const QVector<QPolygonF> *rings, QgsSymbolRenderContext &context )
{
QgsExpressionContextScope *scope = new QgsExpressionContextScope();
QgsExpressionContextScopePopper scopePopper( context.renderContext().expressionContext(), scope );
QgsExpressionContextScope *scope = nullptr;
std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
if ( hasDataDefinedProperties() )
{
scope = new QgsExpressionContextScope();
scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.renderContext().expressionContext(), scope );
}

switch ( mRingFilter )
{
case AllRings:
case ExteriorRingOnly:
{
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, 0, true ) );
renderPolyline( points, context );
break;
}
@@ -720,7 +726,8 @@ void QgsLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, const QVe
int ringIndex = 1;
for ( const QPolygonF &ring : std::as_const( *rings ) )
{
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, ringIndex, true ) );
if ( scope )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_RING_NUM, ringIndex, true ) );

renderPolyline( ring, context );
ringIndex++;

0 comments on commit 24b6ae6

Please sign in to comment.