QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscomposernodesitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposernodesitem.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 QGSCOMPOSERNODESITEM_H
18 #define QGSCOMPOSERNODESITEM_H
19 
20 #include "qgscomposeritem.h"
21 #include <QBrush>
22 #include <QPen>
23 
29 class CORE_EXPORT QgsComposerNodesItem: public QgsComposerItem
30 {
31  Q_OBJECT
32 
33  public:
34 
40 
46  QgsComposerNodesItem( QString mTagName, QPolygonF polygon, QgsComposition* c );
47 
50 
58  bool addNode( const QPointF &pt, const bool checkArea = true, const double radius = 10 );
59 
63  void setDisplayNodes( const bool display = true ) { mDrawNodes = display; }
64 
69  bool moveNode( const int index, const QPointF &node );
70 
72  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
73 
81  int nodeAtPosition( QPointF node, const bool searchInRadius = true, const double radius = 10 );
82 
88  bool nodePosition( const int index, QPointF &position );
89 
94  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
95 
99  bool removeNode( const int index );
100 
102  int nodesSize() { return mPolygon.size(); }
103 
107  bool setSelectedNode( const int index );
108 
112  int selectedNode() { return mSelectedNode; }
113 
116  void unselectNode() { mSelectedNode = -1; }
117 
122  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
123 
124  protected:
125 
128 
130  virtual bool _addNode( const int nodeIndex, const QPointF &newNode, const double radius ) = 0;
131 
133  virtual bool _removeNode( const int nodeIndex ) = 0;
134 
136  virtual void _draw( QPainter *painter ) = 0;
137 
139  virtual void _readXMLStyle( const QDomElement &elmt ) = 0;
140 
142  virtual void _writeXMLStyle( QDomDocument &doc, QDomElement &elmt ) const = 0;
143 
146  void rescaleToFitBoundingBox();
147 
149  double computeDistance( const QPointF &pt1, const QPointF &pt2 ) const;
150 
152  void updateSceneRect();
153 
154  private:
156  QString mTagName;
157 
159  int mSelectedNode;
160 
163  bool mDrawNodes;
164 
166  void drawNodes( QPainter *painter ) const;
167  void drawSelectedNode( QPainter *painter ) const;
168 };
169 
170 #endif // QGSCOMPOSERNODESITEM_H
int selectedNode()
Returns the currently selected node.
An abstract composer item that provides generic methods for nodes based shapes such as polygon or pol...
static unsigned index
QPolygonF mPolygon
Storage meaning for shape&#39;s nodes.
A item that forms part of a map composition.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Graphics scene for map printing.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
int nodesSize()
Returns the number of nodes in the shape.
void setDisplayNodes(const bool display=true)
Set a tag to indicate if we want to draw or not the shape&#39;s nodes.
void unselectNode()
Unselect a node.