Skip to content

Commit

Permalink
Fix crash, missing points in some corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 5, 2019
1 parent 426382c commit 4582cb8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/symbology/qgslinesymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
46 changes: 46 additions & 0 deletions tests/src/python/test_qgsmarkerlinesymbollayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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.