@@ -302,47 +302,27 @@ void LineAnnotation::drawLineAnnotaion(QPainter *painter)
302302 applyLinePattern (painter);
303303 // draw start arrow
304304 if (mPoints .size () > 1 ) {
305- if (mArrow .at (0 ) == StringHandler::ArrowFilled) {
306- painter->save ();
307- painter->setBrush (QBrush (mLineColor , Qt::SolidPattern));
308- painter->drawPolygon (drawArrow (mPoints .at (0 ), mPoints .at (1 ), mArrowSize , mArrow .at (0 )));
309- painter->restore ();
310- } else {
311- painter->drawPolygon (drawArrow (mPoints .at (0 ), mPoints .at (1 ), mArrowSize , mArrow .at (0 )));
312- }
305+ drawArrow (painter, mPoints .at (0 ), mPoints .at (1 ), mArrowSize , mArrow .at (0 ));
313306 }
314307 painter->drawPath (getShape ());
315308 // draw end arrow
316309 if (mPoints .size () > 1 ) {
317- if (mArrow .at (1 ) == StringHandler::ArrowFilled) {
318- painter->save ();
319- painter->setBrush (QBrush (mLineColor , Qt::SolidPattern));
320- painter->drawPolygon (drawArrow (mPoints .at (mPoints .size () - 1 ), mPoints .at (mPoints .size () - 2 ), mArrowSize , mArrow .at (1 )));
321- painter->restore ();
322- } else {
323- painter->drawPolygon (drawArrow (mPoints .at (mPoints .size () - 1 ), mPoints .at (mPoints .size () - 2 ), mArrowSize , mArrow .at (1 )));
324- }
310+ drawArrow (painter, mPoints .at (mPoints .size () - 1 ), mPoints .at (mPoints .size () - 2 ), mArrowSize , mArrow .at (1 ));
325311 }
326312}
327313
328- QPolygonF LineAnnotation::drawArrow (QPointF startPos, QPointF endPos, qreal size, int arrowType) const
314+ void LineAnnotation::drawArrow (QPainter *painter, QPointF startPos, QPointF endPos, qreal size, int arrowType) const
329315{
330316 double xA = size / 2 ;
331317 double yA = size * sqrt (3 ) / 2 ;
332318 double xB = -xA;
333319 double yB = yA;
334- switch (arrowType) {
335- case StringHandler::ArrowFilled:
336- break ;
337- case StringHandler::ArrowHalf:
338- xB = 0 ;
339- break ;
340- case StringHandler::ArrowNone:
341- return QPolygonF ();
342- case StringHandler::ArrowOpen:
343- break ;
344- }
345320 double angle = 0 .0f ;
321+
322+ if (arrowType == StringHandler::ArrowHalf) {
323+ xB = 0 ;
324+ }
325+
346326 if (endPos.x () - startPos.x () == 0 ) {
347327 if (endPos.y () - startPos.y () >= 0 ) {
348328 angle = 0 ;
@@ -368,14 +348,36 @@ QPolygonF LineAnnotation::drawArrow(QPointF startPos, QPointF endPos, qreal size
368348 QTransform t1 (m11, m12, m13, m21, m22, m23, m31, m32, m33);
369349 QTransform t2 (xA, 1 , 1 , yA, 1 , 1 , 1 , 1 , 1 );
370350 QTransform t3 = t1 * t2;
371- QPolygonF polygon ;
372- polygon << startPos;
373- polygon << QPointF (t3.m11 (), t3.m21 ());
351+ QPolygonF arrowPolygon ;
352+ arrowPolygon << startPos;
353+ arrowPolygon << QPointF (t3.m11 (), t3.m21 ());
374354 t2.setMatrix (xB, 1 , 1 , yB, 1 , 1 , 1 , 1 , 1 );
375355 t3 = t1 * t2;
376- polygon << QPointF (t3.m11 (), t3.m21 ());
377- polygon << startPos;
378- return polygon;
356+ arrowPolygon << QPointF (t3.m11 (), t3.m21 ());
357+ arrowPolygon << startPos;
358+ // draw arrow
359+ switch (arrowType) {
360+ case StringHandler::ArrowFilled:
361+ painter->save ();
362+ painter->setBrush (QBrush (mLineColor , Qt::SolidPattern));
363+ painter->drawPolygon (arrowPolygon);
364+ painter->restore ();
365+ break ;
366+ case StringHandler::ArrowOpen:
367+ if (arrowPolygon.size () > 2 ) {
368+ painter->drawLine (arrowPolygon.at (0 ), arrowPolygon.at (1 ));
369+ painter->drawLine (arrowPolygon.at (0 ), arrowPolygon.at (2 ));
370+ }
371+ break ;
372+ case StringHandler::ArrowHalf:
373+ if (arrowPolygon.size () > 1 ) {
374+ painter->drawLine (arrowPolygon.at (0 ), arrowPolygon.at (1 ));
375+ }
376+ break ;
377+ case StringHandler::ArrowNone:
378+ default :
379+ break ;
380+ }
379381}
380382
381383/* !
0 commit comments