QGIS API Documentation  3.0.2-Girona (307d082)
qgslayoutitempolyline.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitempolyline.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 QGSLAYOUTITEMPOLYLINE_H
18 #define QGSLAYOUTITEMPOLYLINE_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitemnodeitem.h"
22 #include "qgssymbol.h"
23 
29 class CORE_EXPORT QgsLayoutItemPolyline: public QgsLayoutNodesItem
30 {
31  Q_OBJECT
32 
33  public:
34 
37  {
41  };
42 
47 
52  QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
53 
59  static QgsLayoutItemPolyline *create( QgsLayout *layout ) SIP_FACTORY;
60 
61  int type() const override;
62  QIcon icon() const override;
63  QString displayName() const override;
64 
69  QgsLineSymbol *symbol() { return mPolylineStyleSymbol.get(); }
70 
76  void setSymbol( QgsLineSymbol *symbol );
77 
83  MarkerMode startMarker() const { return mStartMarker; }
84 
90  void setStartMarker( MarkerMode mode );
91 
97  MarkerMode endMarker() const { return mEndMarker; }
98 
104  void setEndMarker( MarkerMode mode );
105 
110  void setArrowHeadWidth( double width );
111 
116  double arrowHeadWidth() const { return mArrowHeadWidth; }
117 
123  void setStartSvgMarkerPath( const QString &path );
124 
130  QString startSvgMarkerPath() const { return mStartMarkerFile; }
131 
137  void setEndSvgMarkerPath( const QString &path );
138 
144  QString endSvgMarkerPath() const { return mEndMarkerFile; }
145 
151  QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
152 
158  void setArrowHeadStrokeColor( const QColor &color );
159 
165  QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
166 
172  void setArrowHeadFillColor( const QColor &color );
173 
179  void setArrowHeadStrokeWidth( double width );
180 
186  double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
187 
188  protected:
189 
190  bool _addNode( const int indexPoint, QPointF newPoint, const double radius ) override;
191  bool _removeNode( const int nodeIndex ) override;
192  void _draw( QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;
193  void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) override;
194  void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const override;
195  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
196  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
197 
198  protected slots:
199 
200  void updateBoundingRect() override;
201 
202  private:
203 
205  std::unique_ptr<QgsLineSymbol> mPolylineStyleSymbol;
206 
208  MarkerMode mStartMarker = NoMarker;
210  MarkerMode mEndMarker = NoMarker;
211 
213  double mArrowHeadWidth = 4.0;
214 
216  double mStartArrowHeadHeight = 0.0;
217 
219  double mEndArrowHeadHeight = 0.0;
220 
222  QString mStartMarkerFile;
223 
225  QString mEndMarkerFile;
226 
228  double mArrowHeadStrokeWidth = 1.0;
229 
230  QColor mArrowHeadStrokeColor = Qt::black;
231  QColor mArrowHeadFillColor = Qt::black;
232 
234  void createDefaultPolylineStyleSymbol();
235 
240  void refreshSymbol();
241 
242  void drawStartMarker( QPainter *painter );
243  void drawEndMarker( QPainter *painter );
244 
245  void drawArrow( QPainter *painter, QPointF center, double angle );
246 
247  void updateMarkerSvgSizes();
248 
258  static void drawArrowHead( QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth );
259  void drawSvgMarker( QPainter *p, QPointF point, double angle, const QString &markerPath, double height ) const;
260 
261  double computeMarkerMargin() const;
262 
263  friend class TestQgsLayoutPolyline;
265 
266 };
267 
268 #endif // QGSLAYOUTITEMPOLYLINE_H
269 
double arrowHeadWidth() const
Returns the width of line arrow heads in mm.
virtual void _writeXmlStyle(QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context) const =0
Method called in writeXml.
The class is used as a container of context for various read/write operations on other objects...
virtual QIcon icon() const
Returns the item&#39;s icon.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
QString startSvgMarkerPath() const
Returns the path the an SVG marker drawn at the start of the line.
int type() const override
Returns a unique graphics item type identifier.
virtual bool _removeNode(const int nodeIndex)=0
Method called in removeNode.
virtual void _draw(QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle=nullptr)=0
Method called in paint.
MarkerMode
Vertex marker mode.
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
virtual void updateBoundingRect()
Called when the bounding rect of the item should recalculated.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QColor arrowHeadFillColor() const
Returns the color used to fill the arrow head.
QgsLineSymbol * symbol()
Returns the line symbol used to draw the shape.
Layout item for node based polyline shapes.
virtual bool _addNode(const int nodeIndex, QPointF newNode, const double radius)=0
Method called in addNode.
double arrowHeadStrokeWidth() const
Returns the pen width in millimeters for the stroke of the arrow head.
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
MarkerMode startMarker() const
Returns the start marker mode, which controls what marker is drawn at the start of the line...
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:43
virtual QString displayName() const
Get item display name.
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
QString endSvgMarkerPath() const
Returns the path the an SVG marker drawn at the end of the line.
MarkerMode endMarker() const
Returns the end marker mode, which controls what marker is drawn at the end of the line...
QColor arrowHeadStrokeColor() const
Returns the color used to draw the stroke around the the arrow head.
virtual void _readXmlStyle(const QDomElement &elmt, const QgsReadWriteContext &context)=0
Method called in readXml.