Skip to content
Permalink
Browse files
Fix crash, missing points in some corner cases
  • Loading branch information
nyalldawson committed Apr 5, 2019
1 parent 426382c commit 4582cb8d0909ec2e0428730607580bb535885485
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
@@ -1119,7 +1119,13 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p
// (or trace past the final point)
collectOffsetPoints( points, symbolPoints, painterUnitInterval, lengthLeft );

if ( symbolPoints.constFirst() == symbolPoints.constLast() )
if ( symbolPoints.empty() )
{
// no symbols to draw, shortcut out early
return;
}

if ( symbolPoints.count() > 1 && symbolPoints.constFirst() == symbolPoints.constLast() )
{
// avoid duplicate points at start and end of closed rings
symbolPoints.pop_back();
@@ -275,6 +275,52 @@ def testRingNoDupe(self):
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_ring_no_dupes', 'markerline_ring_no_dupes', rendered_image)

def testSinglePoint(self):
s = QgsLineSymbol()
s.deleteSymbolLayer(0)

marker_line = QgsMarkerLineSymbolLayer(True)
marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval)
marker_line.setInterval(1000)
marker_line.setIntervalUnit(QgsUnitTypes.RenderMapUnits)
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 4)
marker.setColor(QColor(255, 0, 0, 100))
marker.setStrokeStyle(Qt.NoPen)
marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, marker)
marker_line.setSubSymbol(marker_symbol)
line_symbol = QgsLineSymbol()
line_symbol.changeSymbolLayer(0, marker_line)

s.appendSymbolLayer(marker_line.clone())

g = QgsGeometry.fromWkt('LineString(0 0, 0 10, 10 10)')
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_single', 'markerline_single', rendered_image)

def testNoPoint(self):
s = QgsLineSymbol()
s.deleteSymbolLayer(0)

marker_line = QgsMarkerLineSymbolLayer(True)
marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval)
marker_line.setOffsetAlongLine(1000)
marker_line.setIntervalUnit(QgsUnitTypes.RenderMapUnits)
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 4)
marker.setColor(QColor(255, 0, 0, 100))
marker.setStrokeStyle(Qt.NoPen)
marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, marker)
marker_line.setSubSymbol(marker_symbol)
line_symbol = QgsLineSymbol()
line_symbol.changeSymbolLayer(0, marker_line)

s.appendSymbolLayer(marker_line.clone())

g = QgsGeometry.fromWkt('LineString(0 0, 0 10, 10 10)')
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_none', 'markerline_none', rendered_image)

def renderGeometry(self, symbol, geom, buffer=20):
f = QgsFeature()
f.setGeometry(geom)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 4582cb8

Please sign in to comment.