Skip to content
Permalink
Browse files

Move end arrowhead by half arrow width. Fix for bug #21171

  • Loading branch information
mhugent committed Feb 9, 2019
1 parent c327dec commit 5a3303c69cd8a33ef6e4a2421083cc880799a24b
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/core/layout/qgslayoutitempolyline.cpp
@@ -26,6 +26,7 @@
#include <QSvgRenderer>
#include <limits>
#include <QGraphicsPathItem>
#include <QVector2D>

QgsLayoutItemPolyline::QgsLayoutItemPolyline( QgsLayout *layout )
: QgsLayoutNodesItem( layout )
@@ -164,7 +165,13 @@ void QgsLayoutItemPolyline::drawEndMarker( QPainter *painter )
// calculate angle at end of line
QLineF endLine( mPolygon.at( mPolygon.count() - 2 ), mPolygon.at( mPolygon.count() - 1 ) );
double angle = endLine.angle();
drawArrow( painter, endLine.p2(), angle );

//move end point depending on arrow width
QVector2D dir = QVector2D( endLine.dx(), endLine.dy() ).normalized();
QPointF endPoint = endLine.p2();
endPoint += ( dir * 0.5 * mArrowHeadWidth ).toPointF();

drawArrow( painter, endPoint, angle );
break;
}
case MarkerMode::SvgMarker:
@@ -189,6 +196,7 @@ void QgsLayoutItemPolyline::drawArrow( QPainter *painter, QPointF center, double
QBrush b;
b.setColor( mArrowHeadFillColor );
painter->setBrush( b );

drawArrowHead( painter, center.x(), center.y(), angle, mArrowHeadWidth );
}

@@ -205,6 +213,7 @@ void QgsLayoutItemPolyline::drawArrowHead( QPainter *p, const double x, const do

double angleRad = angle / 180.0 * M_PI;
QPointF middlePoint( x, y );

//rotate both arrow points
QPointF p1 = QPointF( -arrowHeadWidth / 2.0, arrowHeadWidth );
QPointF p2 = QPointF( arrowHeadWidth / 2.0, arrowHeadWidth );
@@ -433,6 +442,10 @@ void QgsLayoutItemPolyline::updateBoundingRect()
QRectF br = rect();

double margin = std::max( mMaxSymbolBleed, computeMarkerMargin() );
if ( mEndMarker == ArrowHead )
{
margin += 0.5 * mArrowHeadWidth;
}
br.adjust( -margin, -margin, margin, margin );
mCurrentRectangle = br;

0 comments on commit 5a3303c

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