Skip to content

Commit 52dba5d

Browse files
committedOct 28, 2019
Add unit tests for multipolygon random marker fill
1 parent f373203 commit 52dba5d

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed
 

‎src/core/symbology/qgsfillsymbollayer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,10 +3988,13 @@ void QgsRandomMarkerFillSymbolLayer::renderPolygon( const QPolygonF &points, QLi
39883988

39893989
if ( mRenderingFeature )
39903990
{
3991+
// in the middle of rendering a possibly multi-part feature, so we collect all the parts and defer the actual rendering
3992+
// until after we've received the final part
39913993
mCurrentParts << part;
39923994
}
39933995
else
39943996
{
3997+
// not rendering a feature, so we can just render the polygon immediately
39953998
render( context.renderContext(), QVector< Part>() << part, context.feature() ? *context.feature() : QgsFeature(), context.selected() );
39963999
}
39974000
}
@@ -4036,8 +4039,7 @@ void QgsRandomMarkerFillSymbolLayer::render( QgsRenderContext &context, const QV
40364039
}
40374040
}
40384041

4039-
QgsGeometry geom = QgsGeometry::unaryUnion( geometryParts );
4040-
4042+
const QgsGeometry geom = geometryParts.count() != 1 ? QgsGeometry::unaryUnion( geometryParts ) : geometryParts.at( 0 );
40414043

40424044
if ( clipPoints )
40434045
{
@@ -4060,6 +4062,8 @@ void QgsRandomMarkerFillSymbolLayer::render( QgsRenderContext &context, const QV
40604062

40614063
QVector< QgsPointXY > randomPoints = geom.randomPointsInPolygon( count, seed );
40624064
#if 0
4065+
// in some cases rendering from top to bottom is nice (e.g. randomised tree markers), but in other cases it's not wanted..
4066+
// TODO consider exposing this as an option
40634067
std::sort( randomPoints.begin(), randomPoints.end(), []( const QgsPointXY & a, const QgsPointXY & b )->bool
40644068
{
40654069
return a.y() < b.y();

‎tests/src/python/test_qgsrandommarkersymbollayer.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,8 @@
3838
QgsReadWriteContext,
3939
QgsSymbolLayerUtils,
4040
QgsSimpleMarkerSymbolLayer,
41-
QgsLineSymbolLayer,
42-
QgsTemplatedLineSymbolLayerBase,
43-
QgsMarkerLineSymbolLayer,
41+
QgsSimpleFillSymbolLayer,
4442
QgsMarkerSymbol,
45-
QgsGeometryGeneratorSymbolLayer,
46-
QgsSymbol,
47-
QgsFontMarkerSymbolLayer,
48-
QgsFontUtils,
49-
QgsLineSymbol,
50-
QgsSymbolLayer,
51-
QgsProperty,
52-
QgsRectangle,
53-
QgsUnitTypes,
5443
QgsRandomMarkerFillSymbolLayer
5544
)
5645

@@ -142,6 +131,30 @@ def testCreate(self):
142131
random_fill = QgsRandomMarkerFillSymbolLayer.create({})
143132
self.assertNotEqual(random_fill.seed(), 0)
144133

134+
def testMultipart(self):
135+
"""
136+
Test rendering a multi-part random marker fill symbol
137+
"""
138+
s = QgsFillSymbol()
139+
s.deleteSymbolLayer(0)
140+
141+
simple_fill = QgsSimpleFillSymbolLayer(color=QColor(255,255,255))
142+
s.appendSymbolLayer(simple_fill.clone())
143+
144+
random_fill = QgsRandomMarkerFillSymbolLayer(12, seed=481523)
145+
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Triangle, 4)
146+
marker.setColor(QColor(255, 0, 0))
147+
marker.setStrokeStyle(Qt.NoPen)
148+
marker_symbol = QgsMarkerSymbol()
149+
marker_symbol.changeSymbolLayer(0, marker)
150+
random_fill.setSubSymbol(marker_symbol)
151+
152+
s.appendSymbolLayer(random_fill.clone())
153+
154+
g = QgsGeometry.fromWkt('MultiPolygon(((0 0, 5 0, 5 10, 0 10, 0 0),(1 1, 1 9, 4 9, 4 1, 1 1)), ((6 0, 10 0, 10 5, 6 5, 6 0)), ((8 6, 10 6, 10 10, 8 10, 8 6)))')
155+
rendered_image = self.renderGeometry(s, g)
156+
self.assertTrue(self.imageCheck('randommarkerfill_multipoly', 'randommarkerfill_multipoly', rendered_image))
157+
145158
def renderGeometry(self, symbol, geom, buffer=20):
146159
f = QgsFeature()
147160
f.setGeometry(geom)

0 commit comments

Comments
 (0)
Please sign in to comment.