QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgslayoutitemnodeitem.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutitemnodeitem.h
3 begin : March 2016
4 copyright : (C) 2016 Paul Blottiere, Oslandia
5 email : paul dot blottiere at oslandia dot com
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSLAYOUTITEMNODEITEM_H
18#define QGSLAYOUTITEMNODEITEM_H
19
20#include "qgis_core.h"
21#include "qgslayoutitem.h"
22
28class CORE_EXPORT QgsLayoutNodesItem : public QgsLayoutItem
29{
30 Q_OBJECT
31
32 public:
37 void setNodes( const QPolygonF &nodes );
38
43 QPolygonF nodes() const { return mPolygon; }
44
53 bool addNode( QPointF point, bool checkArea = true, double radius = 10 );
54
58 void setDisplayNodes( bool display = true ) { mDrawNodes = display; }
59
65 bool moveNode( int index, QPointF node );
66
75 int nodeAtPosition( QPointF point, bool searchInRadius = true, double radius = 10 ) const;
76
83 bool nodePosition( int index, QPointF &position ) const;
84
88 bool removeNode( int index );
89
91 int nodesSize() const { return mPolygon.size(); }
92
96 bool setSelectedNode( int index );
97
101 int selectedNode() const { return mSelectedNode; }
102
106 void deselectNode() { mSelectedNode = -1; }
107
108 // Depending on the symbol style, the bounding rectangle can be larger than the shape
109 QRectF boundingRect() const override;
110
111 // Reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology
112 // rather than the item's pen
113 double estimatedFrameBleed() const override;
114
122 virtual bool isValid() const = 0;
123
124 protected:
129
133 QgsLayoutNodesItem( const QPolygonF &polygon, QgsLayout *layout );
134
135 void draw( QgsLayoutItemRenderContext &context ) override;
136 QgsLayoutItem::Flags itemFlags() const override;
137 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
138 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
139
141 QPolygonF mPolygon;
142
144 double mMaxSymbolBleed = 0.0;
145
147 virtual bool _addNode( int nodeIndex, QPointF newNode, double radius ) = 0;
148
150 virtual bool _removeNode( int nodeIndex ) = 0;
151
153 virtual void _draw( QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) = 0;
154
156 virtual void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) = 0;
157
159 virtual void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const = 0;
160
166
168 double computeDistance( QPointF pt1, QPointF pt2 ) const;
169
171 void updateSceneRect();
172
175
176 protected slots:
177
182 virtual void updateBoundingRect();
183
184 private:
185 void init();
186
188 int mSelectedNode = -1;
189
194 bool mDrawNodes = false;
195
197 void drawNodes( QgsLayoutItemRenderContext &context ) const;
198 void drawSelectedNode( QgsLayoutItemRenderContext &context ) const;
199};
200
201#endif // QGSLAYOUTITEMNODEITEM_H
Contains settings and helpers relating to a render of a QgsLayoutItem.
friend class QgsLayout
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
QFlags< Flag > Flags
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
virtual void updateBoundingRect()
Called when the bounding rect of the item should recalculated.
virtual bool _removeNode(int nodeIndex)=0
Method called in removeNode.
QPolygonF nodes() const
Returns the nodes the shape consists of.
double mMaxSymbolBleed
Max symbol bleed.
virtual void _writeXmlStyle(QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context) const =0
Method called in writeXml.
QRectF mCurrentRectangle
Current bounding rectangle of shape.
void updateSceneRect()
Update the current scene rectangle for this item.
virtual void _readXmlStyle(const QDomElement &elmt, const QgsReadWriteContext &context)=0
Method called in readXml.
int nodesSize() const
Returns the number of nodes in the shape.
double computeDistance(QPointF pt1, QPointF pt2) const
Compute an euclidean distance between 2 nodes.
void setDisplayNodes(bool display=true)
Set whether the item's nodes should be displayed.
virtual bool isValid() const =0
Must be reimplemented in subclasses.
int selectedNode() const
Returns the currently selected node, or -1 if no node is selected.
virtual void _draw(QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle=nullptr)=0
Method called in paint.
QgsLayoutNodesItem(QgsLayout *layout)
Constructor for QgsLayoutNodesItem, attached to the specified layout.
virtual bool _addNode(int nodeIndex, QPointF newNode, double radius)=0
Method called in addNode.
void rescaleToFitBoundingBox()
Rescale the current shape according to the item's bounding box.
void setNodes(const QPolygonF &nodes)
Sets the nodes the shape consists of.
void deselectNode()
Deselects any selected nodes.
QPolygonF mPolygon
Shape's nodes.
const QgsLayout * layout() const
Returns the layout the object is attached to.
A container for the context for various read/write operations on objects.