Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move end arrowhead by half arrow width. Fix for bug #21171
  • Loading branch information
mhugent committed Feb 9, 2019
1 parent c327dec commit 5a3303c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/layout/qgslayoutitempolyline.cpp
Expand Up @@ -26,6 +26,7 @@
#include <QSvgRenderer>
#include <limits>
#include <QGraphicsPathItem>
#include <QVector2D>

QgsLayoutItemPolyline::QgsLayoutItemPolyline( QgsLayout *layout )
: QgsLayoutNodesItem( layout )
Expand Down Expand Up @@ -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:
Expand All @@ -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 );
}

Expand All @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5a3303c

Please sign in to comment.