QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 #include <QGraphicsPathItem>
24 #include "qgslogger.h"
25 #include "qgslayout.h"
26 
32 class CORE_EXPORT QgsLayoutItemPolyline: public QgsLayoutNodesItem
33 {
34  Q_OBJECT
35 
36  public:
37 
40  {
44  };
45 
50 
55  QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
56 
62  static QgsLayoutItemPolyline *create( QgsLayout *layout ) SIP_FACTORY;
63 
64  int type() const override;
65  QIcon icon() const override;
66  QString displayName() const override;
67  QPainterPath shape() const override;
68 
73  QgsLineSymbol *symbol() { return mPolylineStyleSymbol.get(); }
74 
80  void setSymbol( QgsLineSymbol *symbol );
81 
87  MarkerMode startMarker() const { return mStartMarker; }
88 
94  void setStartMarker( MarkerMode mode );
95 
101  MarkerMode endMarker() const { return mEndMarker; }
102 
108  void setEndMarker( MarkerMode mode );
109 
114  void setArrowHeadWidth( double width );
115 
120  double arrowHeadWidth() const { return mArrowHeadWidth; }
121 
127  void setStartSvgMarkerPath( const QString &path );
128 
134  QString startSvgMarkerPath() const { return mStartMarkerFile; }
135 
141  void setEndSvgMarkerPath( const QString &path );
142 
148  QString endSvgMarkerPath() const { return mEndMarkerFile; }
149 
155  QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
156 
162  void setArrowHeadStrokeColor( const QColor &color );
163 
169  QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
170 
176  void setArrowHeadFillColor( const QColor &color );
177 
183  void setArrowHeadStrokeWidth( double width );
184 
190  double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
191 
192  protected:
193 
194  bool _addNode( int indexPoint, QPointF newPoint, double radius ) override;
195  bool _removeNode( int nodeIndex ) override;
196  void _draw( QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;
197  void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) override;
198  void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const override;
199  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
200  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
201 
202  protected slots:
203 
204  void updateBoundingRect() override;
205 
206  private:
207 
209  std::unique_ptr<QgsLineSymbol> mPolylineStyleSymbol;
210 
212  MarkerMode mStartMarker = NoMarker;
214  MarkerMode mEndMarker = NoMarker;
215 
217  double mArrowHeadWidth = 4.0;
218 
220  double mStartArrowHeadHeight = 0.0;
221 
223  double mEndArrowHeadHeight = 0.0;
224 
226  QString mStartMarkerFile;
227 
229  QString mEndMarkerFile;
230 
232  double mArrowHeadStrokeWidth = 1.0;
233 
234  QColor mArrowHeadStrokeColor = Qt::black;
235  QColor mArrowHeadFillColor = Qt::black;
236 
238  void createDefaultPolylineStyleSymbol();
239 
244  void refreshSymbol();
245 
246  void drawStartMarker( QPainter *painter );
247  void drawEndMarker( QPainter *painter );
248 
249  void drawArrow( QPainter *painter, QPointF center, double angle );
250 
251  void updateMarkerSvgSizes();
252 
262  static void drawArrowHead( QPainter *p, double x, double y, double angle, double arrowHeadWidth );
263  void drawSvgMarker( QPainter *p, QPointF point, double angle, const QString &markerPath, double height ) const;
264 
265  double computeMarkerMargin() const;
266 
267  friend class TestQgsLayoutPolyline;
269 
270 };
271 
272 #endif // QGSLAYOUTITEMPOLYLINE_H
273 
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 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 bool _removeNode(int nodeIndex)=0
Method called in removeNode.
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
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:966
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.
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:44
virtual QString displayName() const
Gets 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.
virtual bool _addNode(int nodeIndex, QPointF newNode, double radius)=0
Method called in addNode.