Skip to content

Commit 783636d

Browse files
committed
Port polygon and polyline items to layouts
1 parent b41fea9 commit 783636d

File tree

33 files changed

+1991
-0
lines changed

33 files changed

+1991
-0
lines changed

python/core/core_auto.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,10 @@
409409
%Include layout/qgslayoutitem.sip
410410
%Include layout/qgslayoutitemgroup.sip
411411
%Include layout/qgslayoutitemmap.sip
412+
%Include layout/qgslayoutitemnodeitem.sip
412413
%Include layout/qgslayoutitempage.sip
414+
%Include layout/qgslayoutitempolygon.sip
415+
%Include layout/qgslayoutitempolyline.sip
413416
%Include layout/qgslayoutitemregistry.sip
414417
%Include layout/qgslayoutitemshape.sip
415418
%Include layout/qgslayoutmodel.sip

python/core/layout/qgslayoutitem.sip

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
263263
.. seealso:: positionWithUnits()
264264
%End
265265

266+
267+
void attemptSetSceneRect( const QRectF &rect, bool includesFrame = false );
268+
%Docstring
269+
Attempts to update the item's position and size to match the passed ``rect`` in layout
270+
coordinates.
271+
272+
If ``includesFrame`` is true, then the position and size specified by ``rect`` represents the
273+
position and size at for the outside of the item's frame.
274+
275+
Note that the final position and size of the item may not match the specified target rect,
276+
as data defined item position and size may override the specified value.
277+
278+
.. seealso:: attemptResize()
279+
.. seealso:: attemptMove()
280+
.. seealso:: referencePoint()
281+
.. seealso:: positionWithUnits()
282+
%End
283+
266284
QgsLayoutPoint positionWithUnits() const;
267285
%Docstring
268286
Returns the item's current position, including units. The position returned
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutitemnodeitem.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutNodesItem: QgsLayoutItem
13+
{
14+
%Docstring
15+
An abstract layout item that provides generic methods for node based
16+
shapes such as polygon or polylines.
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgslayoutitemnodeitem.h"
22+
%End
23+
public:
24+
25+
bool addNode( QPointF point, bool checkArea = true, double radius = 10 );
26+
%Docstring
27+
Add a node in current shape.
28+
\param point is the location of the new node (in scene coordinates)
29+
\param checkArea is a flag to indicate if there's a space constraint.
30+
\param radius is the space contraint and is used only if checkArea is
31+
true. Typically, if this flag is true, the new node has to be nearer
32+
than radius to the shape to be added.
33+
:rtype: bool
34+
%End
35+
36+
void setDisplayNodes( bool display = true );
37+
%Docstring
38+
Set whether the item's nodes should be displayed.
39+
%End
40+
41+
bool moveNode( int index, QPointF node );
42+
%Docstring
43+
Moves a node to a new position.
44+
\param index the index of the node to move
45+
\param node is the new position in scene coordinate
46+
:rtype: bool
47+
%End
48+
49+
int nodeAtPosition( QPointF point, bool searchInRadius = true, double radius = 10 ) const;
50+
%Docstring
51+
Search for the nearest node in the shape within a maximal area. Returns the
52+
index of the nearest node or -1 if no node was found.
53+
\param point is the location to search for nodes from (in scene coordinates)
54+
\param searchInRadius is a flag to indicate if the area of research is
55+
limited in space.
56+
\param radius is only used if searchInRadius is true
57+
:rtype: int
58+
%End
59+
60+
bool nodePosition( int index, QPointF &position ) const;
61+
%Docstring
62+
Gets the position of a node in scene coordinates.
63+
\param index of the node
64+
\param position the position of the node
65+
:return: true if the index is valid and the position is set, false otherwise
66+
:rtype: bool
67+
%End
68+
69+
bool removeNode( int index );
70+
%Docstring
71+
Remove a node with specified ``index`` from the shape.
72+
:rtype: bool
73+
%End
74+
75+
int nodesSize() const;
76+
%Docstring
77+
Returns the number of nodes in the shape.
78+
:rtype: int
79+
%End
80+
81+
bool setSelectedNode( int index );
82+
%Docstring
83+
Selects a node by ``index``.
84+
:rtype: bool
85+
%End
86+
87+
int selectedNode() const;
88+
%Docstring
89+
Returns the currently selected node, or -1 if no node is selected.
90+
:rtype: int
91+
%End
92+
93+
void deselectNode();
94+
%Docstring
95+
Deselects any selected nodes.
96+
%End
97+
98+
QPolygonF nodes() const;
99+
%Docstring
100+
Returns the nodes the shape consists of.
101+
:rtype: QPolygonF
102+
%End
103+
104+
protected:
105+
106+
QgsLayoutNodesItem( QgsLayout *layout );
107+
%Docstring
108+
Constructor
109+
\param tagName tag used in XML file
110+
\param layout parent layout
111+
%End
112+
113+
QgsLayoutNodesItem( const QPolygonF &polygon, QgsLayout *layout );
114+
%Docstring
115+
Constructor
116+
\param tagName tag used in XML file
117+
\param polygon nodes of the shape
118+
\param layout parent layout
119+
%End
120+
121+
virtual void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );
122+
123+
virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
124+
125+
virtual bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context );
126+
127+
128+
129+
virtual bool _addNode( const int nodeIndex, QPointF newNode, const double radius ) = 0;
130+
%Docstring
131+
Method called in addNode.
132+
:rtype: bool
133+
%End
134+
135+
virtual bool _removeNode( const int nodeIndex ) = 0;
136+
%Docstring
137+
Method called in removeNode.
138+
:rtype: bool
139+
%End
140+
141+
virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 ) = 0;
142+
%Docstring
143+
Method called in paint.
144+
%End
145+
146+
virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) = 0;
147+
%Docstring
148+
Method called in readXml.
149+
%End
150+
151+
virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const = 0;
152+
%Docstring
153+
Method called in writeXml.
154+
%End
155+
156+
void rescaleToFitBoundingBox();
157+
%Docstring
158+
Rescale the current shape according to the item's bounding box. Useful when
159+
the shape is resized thanks to the rubber band.
160+
%End
161+
162+
double computeDistance( QPointF pt1, QPointF pt2 ) const;
163+
%Docstring
164+
Compute an euclidian distance between 2 nodes.
165+
:rtype: float
166+
%End
167+
168+
void updateSceneRect();
169+
%Docstring
170+
Update the current scene rectangle for this item.
171+
%End
172+
173+
};
174+
175+
/************************************************************************
176+
* This file has been generated automatically from *
177+
* *
178+
* src/core/layout/qgslayoutitemnodeitem.h *
179+
* *
180+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
181+
************************************************************************/
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutitempolygon.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsLayoutItemPolygon: QgsLayoutNodesItem
14+
{
15+
%Docstring
16+
Layout item for node based polygon shapes.
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgslayoutitempolygon.h"
22+
%End
23+
public:
24+
25+
QgsLayoutItemPolygon( QgsLayout *layout );
26+
%Docstring
27+
Constructor for QgsLayoutItemPolygon for the specified ``layout``.
28+
%End
29+
30+
QgsLayoutItemPolygon( const QPolygonF &polygon, QgsLayout *layout );
31+
%Docstring
32+
Constructor for QgsLayoutItemPolygon for the specified ``polygon``
33+
and ``layout``.
34+
%End
35+
36+
static QgsLayoutItemPolygon *create( QgsLayout *layout ) /Factory/;
37+
%Docstring
38+
Returns a new polygon item for the specified ``layout``.
39+
40+
The caller takes responsibility for deleting the returned object.
41+
:rtype: QgsLayoutItemPolygon
42+
%End
43+
44+
virtual int type() const;
45+
46+
virtual QString stringType() const;
47+
48+
virtual QString displayName() const;
49+
50+
51+
QgsFillSymbol *symbol();
52+
%Docstring
53+
Returns the fill symbol used to draw the shape.
54+
.. seealso:: setSymbol()
55+
:rtype: QgsFillSymbol
56+
%End
57+
58+
void setSymbol( QgsFillSymbol *symbol );
59+
%Docstring
60+
Sets the ``symbol`` used to draw the shape.
61+
Ownership of ``symbol`` is not transferred.
62+
.. seealso:: symbol()
63+
%End
64+
65+
protected:
66+
virtual bool _addNode( const int indexPoint, QPointF newPoint, const double radius );
67+
68+
virtual bool _removeNode( const int nodeIndex );
69+
70+
virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );
71+
72+
virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context );
73+
74+
virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const;
75+
76+
77+
};
78+
79+
/************************************************************************
80+
* This file has been generated automatically from *
81+
* *
82+
* src/core/layout/qgslayoutitempolygon.h *
83+
* *
84+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
85+
************************************************************************/
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutitempolyline.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutItemPolyline: QgsLayoutNodesItem
13+
{
14+
%Docstring
15+
Layout item for node based polyline shapes.
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgslayoutitempolyline.h"
21+
%End
22+
public:
23+
24+
QgsLayoutItemPolyline( QgsLayout *layout );
25+
%Docstring
26+
Constructor for QgsLayoutItemPolyline for the specified ``layout``.
27+
%End
28+
29+
QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
30+
%Docstring
31+
Constructor for QgsLayoutItemPolyline for the specified ``polyline``
32+
and ``layout``.
33+
%End
34+
35+
static QgsLayoutItemPolyline *create( QgsLayout *layout ) /Factory/;
36+
%Docstring
37+
Returns a new polyline item for the specified ``layout``.
38+
39+
The caller takes responsibility for deleting the returned object.
40+
:rtype: QgsLayoutItemPolyline
41+
%End
42+
43+
virtual int type() const;
44+
45+
virtual QString stringType() const;
46+
47+
virtual QString displayName() const;
48+
49+
50+
QgsLineSymbol *symbol();
51+
%Docstring
52+
Returns the line symbol used to draw the shape.
53+
.. seealso:: setSymbol()
54+
:rtype: QgsLineSymbol
55+
%End
56+
57+
void setSymbol( QgsLineSymbol *symbol );
58+
%Docstring
59+
Sets the ``symbol`` used to draw the shape.
60+
Ownership of ``symbol`` is not transferred.
61+
.. seealso:: symbol()
62+
%End
63+
64+
protected:
65+
66+
virtual bool _addNode( const int indexPoint, QPointF newPoint, const double radius );
67+
68+
virtual bool _removeNode( const int nodeIndex );
69+
70+
virtual void _draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );
71+
72+
virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context );
73+
74+
virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const;
75+
76+
77+
};
78+
79+
80+
/************************************************************************
81+
* This file has been generated automatically from *
82+
* *
83+
* src/core/layout/qgslayoutitempolyline.h *
84+
* *
85+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
86+
************************************************************************/

python/core/layout/qgslayoutitemregistry.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class QgsLayoutItemRegistry : QObject
104104
LayoutPage,
105105
LayoutMap,
106106
LayoutShape,
107+
LayoutPolygon,
108+
LayoutPolyline,
107109

108110
// item
109111
PluginItem,

0 commit comments

Comments
 (0)