Skip to content

Commit

Permalink
[layouts] Fix polyline does not render purely horizontal/vertical lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 420821f commit 4e8483e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/layout/qgslayoutitemnodeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 50 additions & 0 deletions tests/src/python/test_qgslayoutpolyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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 4e8483e

Please sign in to comment.