Skip to content
Permalink
Browse files
Fix only first part of multipart geometry rendered when generator
is used as a subsymbol of generator layers

Fixes #46635
  • Loading branch information
nyalldawson authored and github-actions committed Dec 27, 2021
1 parent 23d6559 commit a04d2b02247bcbfcfc80abd1e52ffcbc58db932b
@@ -106,8 +106,11 @@ void QgsGeometryGeneratorSymbolLayer::stopRender( QgsSymbolRenderContext &contex
mSymbol->stopRender( context.renderContext() );
}

void QgsGeometryGeneratorSymbolLayer::startFeatureRender( const QgsFeature &, QgsRenderContext & )
void QgsGeometryGeneratorSymbolLayer::startFeatureRender( const QgsFeature &, QgsRenderContext &context )
{
if ( context.flags() & Qgis::RenderContextFlag::RenderingSubSymbol )
return;

mRenderingFeature = true;
mHasRenderedFeature = false;
}
@@ -45,7 +45,9 @@
QgsRenderChecker,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsArrowSymbolLayer
QgsArrowSymbolLayer,
QgsFeature,
QgsGeometry
)

from qgis.testing import start_app, unittest
@@ -269,6 +271,45 @@ def test_multi_poly_opacity(self):
self.report += renderchecker.report()
self.assertTrue(res)

def test_generator_with_multipart_result_with_generator_subsymbol(self):
"""
Test that generator subsymbol of generator renders all parts of multipart geometry results
"""
lines = QgsVectorLayer('MultiLineString?crs=epsg:4326', 'Lines', 'memory')
self.assertTrue(lines.isValid())
f = QgsFeature()
f.setGeometry(QgsGeometry.fromWkt('MultiLineString((1 1, 2 1, 2 2),(3 1, 3 2, 4 2))'))
lines.dataProvider().addFeature(f)

sym = QgsLineSymbol.createSimple({'color': '#fffdbf6f', 'outline_width': 1})

parent_generator = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'segments_to_lines($geometry)'})
parent_generator.setSymbolType(QgsSymbol.Line)

child_generator = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'collect_geometries(offset_curve($geometry, -2), offset_curve($geometry,2))'})
child_generator.setUnits(QgsUnitTypes.RenderMillimeters)
child_generator.setSymbolType(QgsSymbol.Line)
child_generator.setSubSymbol(sym)

child_symbol = QgsLineSymbol()
child_symbol.changeSymbolLayer(0, child_generator)
parent_generator.setSubSymbol(child_symbol)

geom_symbol = QgsLineSymbol()
geom_symbol.changeSymbolLayer(0, parent_generator)
lines.renderer().setSymbol(geom_symbol)

mapsettings = QgsMapSettings(self.mapsettings)
mapsettings.setExtent(lines.extent())
mapsettings.setLayers([lines])

renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(mapsettings)
renderchecker.setControlName('expected_geometrygenerator_multipart_subsymbol')
res = renderchecker.runTest('geometrygenerator_multipart_subsymbol')
self.report += renderchecker.report()
self.assertTrue(res)

def test_no_feature(self):
"""
Test rendering as a pure symbol, no feature associated
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a04d2b0

Please sign in to comment.