Skip to content
Permalink
Browse files

[layouts] Fix polyline does not render purely horizontal/vertical lines

  • Loading branch information
nyalldawson committed Oct 17, 2017
1 parent 420821f commit 4e8483ecfbf464a0a75ffb66d88802995eda178e
@@ -295,8 +295,10 @@ void QgsLayoutNodesItem::rescaleToFitBoundingBox()
const QRectF boundingRect = mPolygon.boundingRect();

// compute x/y ratio
const float ratioX = rect().width() / boundingRect.width();
const float ratioY = rect().height() / boundingRect.height();
const float ratioX = !qgsDoubleNear( boundingRect.width(), 0.0 )
? rect().width() / boundingRect.width() : 0;
const float ratioY = !qgsDoubleNear( boundingRect.height(), 0.0 )
? rect().height() / boundingRect.height() : 0;

// scaling
QTransform trans;
@@ -306,6 +306,56 @@ def testBounds(self):
self.assertEqual(bounds.top(), -3.0)
self.assertEqual(bounds.bottom(), 93.0)

def testHorizontalLine(self):
pr = QgsProject()
l = QgsLayout(pr)
l.initializeDefaults()

p = QPolygonF()
p.append(QPointF(50.0, 100.0))
p.append(QPointF(100.0, 100.0))
shape = QgsLayoutItemPolyline(p, l)
l.addLayoutItem(shape)

props = {}
props["color"] = "0,0,0,255"
props["width"] = "10.0"
props["capstyle"] = "square"

style = QgsLineSymbol.createSimple(props)
shape.setSymbol(style)

checker = QgsLayoutChecker(
'composerpolyline_hozline', l)
checker.setControlPathPrefix("composer_polyline")
myTestResult, myMessage = checker.testLayout()
assert myTestResult, myMessage

def testVerticalLine(self):
pr = QgsProject()
l = QgsLayout(pr)
l.initializeDefaults()

p = QPolygonF()
p.append(QPointF(100.0, 50.0))
p.append(QPointF(100.0, 100.0))
shape = QgsLayoutItemPolyline(p, l)
l.addLayoutItem(shape)

props = {}
props["color"] = "0,0,0,255"
props["width"] = "10.0"
props["capstyle"] = "square"

style = QgsLineSymbol.createSimple(props)
shape.setSymbol(style)

checker = QgsLayoutChecker(
'composerpolyline_vertline', l)
checker.setControlPathPrefix("composer_polyline")
myTestResult, myMessage = checker.testLayout()
assert myTestResult, myMessage


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.

0 comments on commit 4e8483e

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