Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[layouts] Use polyline shape instead of bounding box for selection, m…
…akes polylines selectable via single click

Fixes #20940

(cherry picked from commit 1cdff21)
  • Loading branch information
jdugge authored and nyalldawson committed Jan 29, 2019
1 parent a9466cd commit 33660ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Expand Up @@ -53,6 +53,8 @@ The caller takes responsibility for deleting the returned object.

virtual QString displayName() const;

virtual QPainterPath shape() const;


QgsLineSymbol *symbol();
%Docstring
Expand Down
14 changes: 14 additions & 0 deletions src/core/layout/qgslayoutitempolyline.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgssvgcache.h"
#include <QSvgRenderer>
#include <limits>
#include <QGraphicsPathItem>

QgsLayoutItemPolyline::QgsLayoutItemPolyline( QgsLayout *layout )
: QgsLayoutNodesItem( layout )
Expand Down Expand Up @@ -312,6 +313,19 @@ void QgsLayoutItemPolyline::setArrowHeadWidth( double width )
update();
}

QPainterPath QgsLayoutItemPolyline::shape() const
{
QPainterPath path;
path.addPolygon( mPolygon );

QPainterPathStroker ps;

ps.setWidth( 2 * mMaxSymbolBleed );
QPainterPath strokedOutline = ps.createStroke( path );

return strokedOutline;
}

void QgsLayoutItemPolyline::setStartSvgMarkerPath( const QString &path )
{
QSvgRenderer r;
Expand Down
4 changes: 4 additions & 0 deletions src/core/layout/qgslayoutitempolyline.h
Expand Up @@ -20,6 +20,9 @@
#include "qgis_core.h"
#include "qgslayoutitemnodeitem.h"
#include "qgssymbol.h"
#include <QGraphicsPathItem>
#include "qgslogger.h"
#include "qgslayout.h"

/**
* \ingroup core
Expand Down Expand Up @@ -61,6 +64,7 @@ class CORE_EXPORT QgsLayoutItemPolyline: public QgsLayoutNodesItem
int type() const override;
QIcon icon() const override;
QString displayName() const override;
QPainterPath shape() const override;

/**
* Returns the line symbol used to draw the shape.
Expand Down

0 comments on commit 33660ce

Please sign in to comment.