QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 <QGraphicsPathItem>
23 #include "qgslogger.h"
24 #include "qgslayout.h"
25 
26 class QgsLineSymbol;
27 
33 class CORE_EXPORT QgsLayoutItemPolyline: public QgsLayoutNodesItem
34 {
35  Q_OBJECT
36 
37  public:
38 
41  {
45  };
46 
51  ~QgsLayoutItemPolyline() override;
52 
57  QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
58 
64  static QgsLayoutItemPolyline *create( QgsLayout *layout ) SIP_FACTORY;
65 
66  int type() const override;
67  QIcon icon() const override;
68  QString displayName() const override;
69  QPainterPath shape() const override;
70 
75  QgsLineSymbol *symbol();
76 
82  void setSymbol( QgsLineSymbol *symbol );
83 
89  MarkerMode startMarker() const { return mStartMarker; }
90 
96  void setStartMarker( MarkerMode mode );
97 
103  MarkerMode endMarker() const { return mEndMarker; }
104 
110  void setEndMarker( MarkerMode mode );
111 
116  void setArrowHeadWidth( double width );
117 
122  double arrowHeadWidth() const { return mArrowHeadWidth; }
123 
129  void setStartSvgMarkerPath( const QString &path );
130 
136  QString startSvgMarkerPath() const { return mStartMarkerFile; }
137 
143  void setEndSvgMarkerPath( const QString &path );
144 
150  QString endSvgMarkerPath() const { return mEndMarkerFile; }
151 
157  QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
158 
164  void setArrowHeadStrokeColor( const QColor &color );
165 
171  QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
172 
178  void setArrowHeadFillColor( const QColor &color );
179 
185  void setArrowHeadStrokeWidth( double width );
186 
192  double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
193 
194  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
195 
196  protected:
197 
198  bool _addNode( int indexPoint, QPointF newPoint, double radius ) override;
199  bool _removeNode( int nodeIndex ) override;
200  void _draw( QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;
201  void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) override;
202  void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const override;
203  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
204  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
205 
206  protected slots:
207 
208  void updateBoundingRect() override;
209 
210  private:
211 
213  std::unique_ptr<QgsLineSymbol> mPolylineStyleSymbol;
214 
216  MarkerMode mStartMarker = NoMarker;
218  MarkerMode mEndMarker = NoMarker;
219 
221  double mArrowHeadWidth = 4.0;
222 
224  double mStartArrowHeadHeight = 0.0;
225 
227  double mEndArrowHeadHeight = 0.0;
228 
230  QString mStartMarkerFile;
231 
233  QString mEndMarkerFile;
234 
236  double mArrowHeadStrokeWidth = 1.0;
237 
238  QColor mArrowHeadStrokeColor = Qt::black;
239  QColor mArrowHeadFillColor = Qt::black;
240 
242  void createDefaultPolylineStyleSymbol();
243 
248  void refreshSymbol();
249 
250  void drawStartMarker( QPainter *painter );
251  void drawEndMarker( QPainter *painter );
252 
253  void drawArrow( QPainter *painter, QPointF center, double angle );
254 
255  void updateMarkerSvgSizes();
256 
266  static void drawArrowHead( QPainter *p, double x, double y, double angle, double arrowHeadWidth );
267  void drawSvgMarker( QPainter *p, QPointF point, double angle, const QString &markerPath, double height ) const;
268 
269  double computeMarkerMargin() const;
270 
271  friend class TestQgsLayoutPolyline;
273 
274 };
275 
276 #endif // QGSLAYOUTITEMPOLYLINE_H
277 
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayoutNodesItem::readPropertiesFromElement
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
Definition: qgslayoutitemnodeitem.cpp:276
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:336
QgsLayoutItemPolyline
Layout item for node based polyline shapes.
Definition: qgslayoutitempolyline.h:33
QgsLayoutItemPolyline::startSvgMarkerPath
QString startSvgMarkerPath() const
Returns the path the an SVG marker drawn at the start of the line.
Definition: qgslayoutitempolyline.h:136
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
QgsLayoutItemPolyline::startMarker
MarkerMode startMarker() const
Returns the start marker mode, which controls what marker is drawn at the start of the line.
Definition: qgslayoutitempolyline.h:89
QgsLayoutNodesItem::_removeNode
virtual bool _removeNode(int nodeIndex)=0
Method called in removeNode.
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsLayoutItemPolyline::arrowHeadStrokeColor
QColor arrowHeadStrokeColor() const
Returns the color used to draw the stroke around the the arrow head.
Definition: qgslayoutitempolyline.h:157
qgslayoutitemnodeitem.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
QgsLayoutItemPolyline::SvgMarker
@ SvgMarker
Show SVG marker.
Definition: qgslayoutitempolyline.h:44
QgsLayoutItemPolyline::MarkerMode
MarkerMode
Vertex marker mode.
Definition: qgslayoutitempolyline.h:40
QgsLayoutNodesItem::_draw
virtual void _draw(QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle=nullptr)=0
Method called in paint.
QgsLayoutItemPolyline::arrowHeadWidth
double arrowHeadWidth() const
Returns the width of line arrow heads in mm.
Definition: qgslayoutitempolyline.h:122
QgsLayoutItemPolyline::endMarker
MarkerMode endMarker() const
Returns the end marker mode, which controls what marker is drawn at the end of the line.
Definition: qgslayoutitempolyline.h:103
QgsCompositionConverter
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Definition: qgscompositionconverter.h:56
QgsLayoutItem::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitem.cpp:1166
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsLayoutItemPolyline::arrowHeadStrokeWidth
double arrowHeadStrokeWidth() const
Returns the pen width in millimeters for the stroke of the arrow head.
Definition: qgslayoutitempolyline.h:192
QgsLayoutNodesItem::writePropertiesToElement
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Definition: qgslayoutitemnodeitem.cpp:356
QgsLayoutItemPolyline::endSvgMarkerPath
QString endSvgMarkerPath() const
Returns the path the an SVG marker drawn at the end of the line.
Definition: qgslayoutitempolyline.h:150
qgslayout.h
QgsLayoutItemPolyline::ArrowHead
@ ArrowHead
Show arrow marker.
Definition: qgslayoutitempolyline.h:43
QgsLayoutNodesItem::_readXmlStyle
virtual void _readXmlStyle(const QDomElement &elmt, const QgsReadWriteContext &context)=0
Method called in readXml.
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutNodesItem
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
Definition: qgslayoutitemnodeitem.h:29
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsLayoutItemPolyline::NoMarker
@ NoMarker
Don't show marker.
Definition: qgslayoutitempolyline.h:42
QgsLayoutNodesItem::updateBoundingRect
virtual void updateBoundingRect()
Called when the bounding rect of the item should recalculated.
Definition: qgslayoutitemnodeitem.cpp:345
qgslogger.h
QgsLayoutNodesItem::_writeXmlStyle
virtual void _writeXmlStyle(QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context) const =0
Method called in writeXml.
QgsLayoutItemPolyline::arrowHeadFillColor
QColor arrowHeadFillColor() const
Returns the color used to fill the arrow head.
Definition: qgslayoutitempolyline.h:171
MathUtils::angle
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
QgsLayoutNodesItem::_addNode
virtual bool _addNode(int nodeIndex, QPointF newNode, double radius)=0
Method called in addNode.