mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[layouts] Fix polyline does not render purely horizontal/vertical lines
This commit is contained in:
parent
420821fd68
commit
4e8483ecfb
@ -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 @@ class TestQgsLayoutPolyline(unittest.TestCase):
|
||||
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.
After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
Loading…
x
Reference in New Issue
Block a user