Skip to content

Commit 6691332

Browse files
committedMar 1, 2014
Ensure draw line only inside polygon works correctly with multipolygon rings (fix #9624)
1 parent 1877b51 commit 6691332

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed
 

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,51 @@ void QgsSimpleLineSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
174174
Q_UNUSED( context );
175175
}
176176

177+
void QgsSimpleLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
178+
{
179+
QPainter* p = context.renderContext().painter();
180+
if ( !p )
181+
{
182+
return;
183+
}
184+
185+
if ( mDrawInsidePolygon )
186+
{
187+
//only drawing the line on the interior of the polygon, so set clip path for painter
188+
p->save();
189+
QPainterPath clipPath;
190+
clipPath.addPolygon( points );
191+
192+
if ( rings != NULL )
193+
{
194+
//add polygon rings
195+
QList<QPolygonF>::const_iterator it = rings->constBegin();
196+
for ( ; it != rings->constEnd(); ++it )
197+
{
198+
QPolygonF ring = *it;
199+
clipPath.addPolygon( ring );
200+
}
201+
}
202+
203+
//use intersect mode, as a clip path may already exist (eg, for composer maps)
204+
p->setClipPath( clipPath, Qt::IntersectClip );
205+
}
206+
207+
renderPolyline( points, context );
208+
if ( rings )
209+
{
210+
foreach ( const QPolygonF& ring, *rings )
211+
renderPolyline( ring, context );
212+
}
213+
214+
if ( mDrawInsidePolygon )
215+
{
216+
//restore painter to reset clip path
217+
p->restore();
218+
}
219+
220+
}
221+
177222
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
178223
{
179224
QPainter* p = context.renderContext().painter();
@@ -198,15 +243,6 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
198243
}
199244
#endif
200245

201-
if ( mDrawInsidePolygon )
202-
{
203-
//only drawing the line on the interior of the polygon, so set clip path for painter
204-
p->save();
205-
QPainterPath clipPath;
206-
clipPath.addPolygon( points );
207-
p->setClipPath( clipPath, Qt::IntersectClip );
208-
}
209-
210246
if ( offset == 0 )
211247
{
212248
p->drawPolyline( points );
@@ -216,12 +252,6 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
216252
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
217253
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
218254
}
219-
220-
if ( mDrawInsidePolygon )
221-
{
222-
//restore painter to reset clip path
223-
p->restore();
224-
}
225255
}
226256

227257
QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const

‎src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
5252

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

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

5760
QgsSymbolLayerV2* clone() const;

0 commit comments

Comments
 (0)
Please sign in to comment.