Skip to content
Permalink
Browse files

Fix custom stroke patterns incorrectly scale when data defined

stroke width is set

Fixes #39201
  • Loading branch information
nyalldawson committed Oct 8, 2020
1 parent 1cd5a33 commit 03fdc0cd7992a7883183704cd68506f32afe9ca3
@@ -594,6 +594,18 @@ void QgsSimpleLineSymbolLayer::applyDataDefinedSymbology( QgsSymbolRenderContext
pen.setDashPattern( dashVector );
}
}
else if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeWidth ) && mUseCustomDashPattern )
{
//re-scale pattern vector after data defined pen width was applied

QVector<qreal> scaledVector;
for ( double v : mCustomDashVector )
{
//the dash is specified in terms of pen widths, therefore the division
scaledVector << context.renderContext().convertToPainterUnits( v, mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv;
}
mPen.setDashPattern( scaledVector );
}

// dash pattern offset
double patternOffset = mDashPatternOffset;
@@ -41,7 +41,9 @@
QgsLineSymbolLayer,
QgsLineSymbol,
QgsUnitTypes,
QgsMapUnitScale
QgsMapUnitScale,
QgsSymbolLayer,
QgsProperty
)

from qgis.testing import unittest, start_app
@@ -60,6 +62,20 @@ def tearDown(self):
with open(report_file_path, 'a') as report_file:
report_file.write(self.report)

def testDashPatternWithDataDefinedWidth(self):
# rendering test
s = QgsLineSymbol.createSimple({'outline_color': '#ff0000', 'outline_width': '2'})

s[0].setUseCustomDashPattern(True)
s[0].setPenCapStyle(Qt.FlatCap)
s[0].setCustomDashVector([3, 4, 5, 6])

s[0].dataDefinedProperties().setProperty(QgsSymbolLayer.PropertyStrokeWidth, QgsProperty.fromExpression('3'))

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

def testDashPatternOffset(self):

s = QgsLineSymbol.createSimple({'outline_color': '#ff0000', 'outline_width': '0.6'})
Binary file not shown.

0 comments on commit 03fdc0c

Please sign in to comment.
You can’t perform that action at this time.