2626#include < QSvgRenderer>
2727#include < limits>
2828#include < QGraphicsPathItem>
29+ #include < QVector2D>
2930
3031QgsLayoutItemPolyline::QgsLayoutItemPolyline ( QgsLayout *layout )
3132 : QgsLayoutNodesItem( layout )
@@ -164,7 +165,13 @@ void QgsLayoutItemPolyline::drawEndMarker( QPainter *painter )
164165 // calculate angle at end of line
165166 QLineF endLine ( mPolygon .at ( mPolygon .count () - 2 ), mPolygon .at ( mPolygon .count () - 1 ) );
166167 double angle = endLine.angle ();
167- drawArrow ( painter, endLine.p2 (), angle );
168+
169+ // move end point depending on arrow width
170+ QVector2D dir = QVector2D ( endLine.dx (), endLine.dy () ).normalized ();
171+ QPointF endPoint = endLine.p2 ();
172+ endPoint += ( dir * 0.5 * mArrowHeadWidth ).toPointF ();
173+
174+ drawArrow ( painter, endPoint, angle );
168175 break ;
169176 }
170177 case MarkerMode::SvgMarker:
@@ -189,6 +196,7 @@ void QgsLayoutItemPolyline::drawArrow( QPainter *painter, QPointF center, double
189196 QBrush b;
190197 b.setColor ( mArrowHeadFillColor );
191198 painter->setBrush ( b );
199+
192200 drawArrowHead ( painter, center.x (), center.y (), angle, mArrowHeadWidth );
193201}
194202
@@ -205,6 +213,7 @@ void QgsLayoutItemPolyline::drawArrowHead( QPainter *p, const double x, const do
205213
206214 double angleRad = angle / 180.0 * M_PI ;
207215 QPointF middlePoint ( x, y );
216+
208217 // rotate both arrow points
209218 QPointF p1 = QPointF ( -arrowHeadWidth / 2.0 , arrowHeadWidth );
210219 QPointF p2 = QPointF ( arrowHeadWidth / 2.0 , arrowHeadWidth );
@@ -433,6 +442,10 @@ void QgsLayoutItemPolyline::updateBoundingRect()
433442 QRectF br = rect ();
434443
435444 double margin = std::max ( mMaxSymbolBleed , computeMarkerMargin () );
445+ if ( mEndMarker == ArrowHead )
446+ {
447+ margin += 0.5 * mArrowHeadWidth ;
448+ }
436449 br.adjust ( -margin, -margin, margin, margin );
437450 mCurrentRectangle = br;
438451
0 commit comments