Skip to content
Permalink
Browse files

Ensure draw line only inside polygon works correctly with multipolygo…

…n rings (fix #9624)
  • Loading branch information
nyalldawson committed Mar 1, 2014
1 parent 1877b51 commit 66913320f07adb215f0d7b10df7d6509273fd91f
Showing with 48 additions and 15 deletions.
  1. +45 −15 src/core/symbology-ng/qgslinesymbollayerv2.cpp
  2. +3 −0 src/core/symbology-ng/qgslinesymbollayerv2.h
@@ -174,6 +174,51 @@ void QgsSimpleLineSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
Q_UNUSED( context );
}

void QgsSimpleLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
if ( !p )
{
return;
}

if ( mDrawInsidePolygon )
{
//only drawing the line on the interior of the polygon, so set clip path for painter
p->save();
QPainterPath clipPath;
clipPath.addPolygon( points );

if ( rings != NULL )
{
//add polygon rings
QList<QPolygonF>::const_iterator it = rings->constBegin();
for ( ; it != rings->constEnd(); ++it )
{
QPolygonF ring = *it;
clipPath.addPolygon( ring );
}
}

//use intersect mode, as a clip path may already exist (eg, for composer maps)
p->setClipPath( clipPath, Qt::IntersectClip );
}

renderPolyline( points, context );
if ( rings )
{
foreach ( const QPolygonF& ring, *rings )
renderPolyline( ring, context );
}

if ( mDrawInsidePolygon )
{
//restore painter to reset clip path
p->restore();
}

}

void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
@@ -198,15 +243,6 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
}
#endif

if ( mDrawInsidePolygon )
{
//only drawing the line on the interior of the polygon, so set clip path for painter
p->save();
QPainterPath clipPath;
clipPath.addPolygon( points );
p->setClipPath( clipPath, Qt::IntersectClip );
}

if ( offset == 0 )
{
p->drawPolyline( points );
@@ -216,12 +252,6 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
}

if ( mDrawInsidePolygon )
{
//restore painter to reset clip path
p->restore();
}
}

QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
@@ -52,6 +52,9 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2

void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );

//overriden so that clip path can be set when using draw inside polygon option
void renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const;

0 comments on commit 6691332

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