Skip to content
Permalink
Browse files
Merge pull request #42853 from qgis/backport-42846-to-release-3_18
[Backport release-3_18] [symbology] Make use of the marker symbol line angle for all polyline templated line rendering
  • Loading branch information
nirvn committed Apr 21, 2021
2 parents a1325e6 + e580489 commit e3e45fb8dd42c366b9751b28b55f8a806d985474
@@ -1643,7 +1643,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi

QgsRenderContext &rc = context.renderContext();

double origAngle = symbolAngle();
int i = -1, maxCount = 0;
bool isRing = false;

@@ -1698,7 +1697,7 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
if ( rotateSymbols() )
{
double angle = context.renderContext().geometry()->vertexAngle( vId );
setSymbolAngle( angle * 180 / M_PI );
setSymbolLineAngle( angle * 180 / M_PI );
}
renderSymbol( mapPoint, context.feature(), rc, -1, context.selected() );
}
@@ -1746,8 +1745,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
double distance;
distance = placement == QgsTemplatedLineSymbolLayerBase::FirstVertex ? offsetAlongLine : -offsetAlongLine;
renderOffsetVertexAlongLine( points, i, distance, context );
// restore original rotation
setSymbolAngle( origAngle );

return;
}
@@ -1776,7 +1773,7 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
{
double angle = std::atan2( currentPoint.y() - prevPoint.y(),
currentPoint.x() - prevPoint.x() );
setSymbolAngle( origAngle + angle * 180 / M_PI );
setSymbolLineAngle( angle * 180 / M_PI );
}
prevPoint = currentPoint;
}
@@ -1787,15 +1784,12 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
if ( rotateSymbols() )
{
double angle = markerAngle( points, isRing, i );
setSymbolAngle( origAngle + angle * 180 / M_PI );
setSymbolLineAngle( angle * 180 / M_PI );
}
}

renderSymbol( symbolPoint, context.feature(), rc, -1, context.selected() );
}

// restore original rotation
setSymbolAngle( origAngle );
}

double QgsTemplatedLineSymbolLayerBase::markerAngle( const QPolygonF &points, bool isRing, int vertex )
@@ -1879,7 +1873,6 @@ void QgsTemplatedLineSymbolLayerBase::renderOffsetVertexAlongLine( const QPolygo
return;

QgsRenderContext &rc = context.renderContext();
double origAngle = symbolAngle();
if ( qgsDoubleNear( distance, 0.0 ) )
{
// rotate marker (if desired)
@@ -1889,7 +1882,7 @@ void QgsTemplatedLineSymbolLayerBase::renderOffsetVertexAlongLine( const QPolygo
if ( points.first() == points.last() )
isRing = true;
double angle = markerAngle( points, isRing, vertex );
setSymbolAngle( origAngle + angle * 180 / M_PI );
setSymbolLineAngle( angle * 180 / M_PI );
}
renderSymbol( points[vertex], context.feature(), rc, -1, context.selected() );
return;
@@ -1918,7 +1911,7 @@ void QgsTemplatedLineSymbolLayerBase::renderOffsetVertexAlongLine( const QPolygo
// rotate marker (if desired)
if ( rotateSymbols() )
{
setSymbolAngle( origAngle + ( l.angle() * 180 / M_PI ) );
setSymbolLineAngle( l.angle() * 180 / M_PI );
}
renderSymbol( markerPoint, context.feature(), rc, -1, context.selected() );
return;
@@ -496,7 +496,7 @@ def testCenterSegment(self):
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_segmentcenter', 'markerline_segmentcenter', rendered_image)

def testMarkerAngleDD(self):
def testMarkerDataDefinedAngleLine(self):
"""Test issue https://github.com/qgis/QGIS/issues/38716"""

s = QgsLineSymbol()
@@ -548,6 +548,48 @@ def testMarkerAngleDD(self):
rendered_image = self.renderGeometry(s, g)
assert self.imageCheck('markerline_center_angle_dd', 'markerline_center_angle_dd', rendered_image)

def testDataDefinedAnglePolygon(self):
# test rendering curve polygon with markers at vertices and curve points
s = QgsFillSymbol()

marker_line = QgsMarkerLineSymbolLayer(True)
marker_line.setPlacement(QgsMarkerLineSymbolLayer.SegmentCenter)
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Triangle, 4)
marker.setColor(QColor(255, 0, 0))
marker.setStrokeStyle(Qt.NoPen)
marker.setAngle(90)
marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, marker)
marker_line.setSubSymbol(marker_symbol)

s.appendSymbolLayer(marker_line.clone())

g = QgsGeometry.fromWkt('Polygon (LineString (0 5, 5 0, 10 5, 5 10, 0 5))')
self.assertFalse(g.isNull())

# rendering test with non data-defined angle
rendered_image = self.renderGeometry(s, g)
self.assertTrue(self.imageCheck('markerline_datadefinedanglepolygon', 'markerline_datadefinedanglepolygon', rendered_image))

s = QgsFillSymbol()

marker_line = QgsMarkerLineSymbolLayer(True)
marker_line.setPlacement(QgsMarkerLineSymbolLayer.SegmentCenter)
marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Triangle, 4)
marker.setColor(QColor(255, 0, 0))
marker.setStrokeStyle(Qt.NoPen)
marker.setAngle(38)
marker_symbol = QgsMarkerSymbol()
marker_symbol.changeSymbolLayer(0, marker)
marker_symbol.setDataDefinedAngle(QgsProperty.fromExpression('90'))
marker_line.setSubSymbol(marker_symbol)

s.appendSymbolLayer(marker_line.clone())

# rendering test with data-defined angle
rendered_image = self.renderGeometry(s, g)
self.assertTrue(self.imageCheck('markerline_datadefinedanglepolygon', 'markerline_datadefinedanglepolygon', rendered_image))

def testOpacityWithDataDefinedColor(self):
line_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
line_layer = QgsVectorLayer(line_shp, 'Lines', 'ogr')
Binary file not shown.
Binary file not shown.

0 comments on commit e3e45fb

Please sign in to comment.