Skip to content
Permalink
Browse files

Merge pull request #9129 from mhugent/itempolyline_end_arrow

Move end arrowhead by half arrow width
  • Loading branch information
mhugent committed Feb 8, 2019
2 parents b7138b1 + 14e5176 commit 4eaae77a5d1036910356a8e6e6cd72020495176c
@@ -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;

@@ -146,6 +146,17 @@ def testSelectedNode(self):
myTestResult, myMessage = checker.testLayout()
assert myTestResult, myMessage

def testEndArrow(self):
self.polyline.setEndMarker(QgsLayoutItemPolyline.ArrowHead)
self.polyline.setArrowHeadWidth(30.0)

checker = QgsLayoutChecker('composerpolyline_endArrow', self.layout)
checker.setControlPathPrefix("composer_polyline")
myTestResult, myMessage = checker.testLayout()
assert myTestResult, myMessage

self.polyline.setEndMarker(QgsLayoutItemPolyline.NoMarker)

def testRemoveNode(self):
"""Test removeNode method"""

Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4eaae77

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