Skip to content

Commit 1cdff21

Browse files
jduggenyalldawson
authored andcommitted
[layouts] Use polyline shape instead of bounding box for selection, makes polylines selectable via single click
Fixes #20940
1 parent d61f410 commit 1cdff21

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

python/core/auto_generated/layout/qgslayoutitempolyline.sip.in

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The caller takes responsibility for deleting the returned object.
5353

5454
virtual QString displayName() const;
5555

56+
virtual QPainterPath shape() const;
57+
5658

5759
QgsLineSymbol *symbol();
5860
%Docstring

src/core/layout/qgslayoutitempolyline.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgssvgcache.h"
2626
#include <QSvgRenderer>
2727
#include <limits>
28+
#include <QGraphicsPathItem>
2829

2930
QgsLayoutItemPolyline::QgsLayoutItemPolyline( QgsLayout *layout )
3031
: QgsLayoutNodesItem( layout )
@@ -312,6 +313,19 @@ void QgsLayoutItemPolyline::setArrowHeadWidth( double width )
312313
update();
313314
}
314315

316+
QPainterPath QgsLayoutItemPolyline::shape() const
317+
{
318+
QPainterPath path;
319+
path.addPolygon( mPolygon );
320+
321+
QPainterPathStroker ps;
322+
323+
ps.setWidth( 2 * mMaxSymbolBleed );
324+
QPainterPath strokedOutline = ps.createStroke( path );
325+
326+
return strokedOutline;
327+
}
328+
315329
void QgsLayoutItemPolyline::setStartSvgMarkerPath( const QString &path )
316330
{
317331
QSvgRenderer r;

src/core/layout/qgslayoutitempolyline.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "qgis_core.h"
2121
#include "qgslayoutitemnodeitem.h"
2222
#include "qgssymbol.h"
23+
#include <QGraphicsPathItem>
24+
#include "qgslogger.h"
25+
#include "qgslayout.h"
2326

2427
/**
2528
* \ingroup core
@@ -61,6 +64,7 @@ class CORE_EXPORT QgsLayoutItemPolyline: public QgsLayoutNodesItem
6164
int type() const override;
6265
QIcon icon() const override;
6366
QString displayName() const override;
67+
QPainterPath shape() const override;
6468

6569
/**
6670
* Returns the line symbol used to draw the shape.

0 commit comments

Comments
 (0)