Skip to content
Permalink
Browse files
[layouts] Fix polyline does not render purely horizontal/vertical lines
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 420821f commit 4e8483ecfbf464a0a75ffb66d88802995eda178e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
@@ -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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.