QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgslayout.h"
23#include "qgslogger.h"
24
25#include <QGraphicsPathItem>
26
27class QgsLineSymbol;
28
34{
35 Q_OBJECT
36
37 public:
38
46
52
57 QgsLayoutItemPolyline( const QPolygonF &polyline, QgsLayout *layout );
58
65
66 int type() const override;
67 QIcon icon() const override;
68 QString displayName() const override;
69 QPainterPath shape() const override;
70 bool isValid() const override;
71
77
84
90 MarkerMode startMarker() const { return mStartMarker; }
91
97 void setStartMarker( MarkerMode mode );
98
104 MarkerMode endMarker() const { return mEndMarker; }
105
111 void setEndMarker( MarkerMode mode );
112
117 void setArrowHeadWidth( double width );
118
123 double arrowHeadWidth() const { return mArrowHeadWidth; }
124
130 void setStartSvgMarkerPath( const QString &path );
131
137 QString startSvgMarkerPath() const { return mStartMarkerFile; }
138
144 void setEndSvgMarkerPath( const QString &path );
145
151 QString endSvgMarkerPath() const { return mEndMarkerFile; }
152
158 QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
159
165 void setArrowHeadStrokeColor( const QColor &color );
166
172 QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
173
179 void setArrowHeadFillColor( const QColor &color );
180
186 void setArrowHeadStrokeWidth( double width );
187
193 double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
194
195 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
196
197 protected:
198
199 bool _addNode( int indexPoint, QPointF newPoint, double radius ) override;
200 bool _removeNode( int nodeIndex ) override;
201 void _draw( QgsLayoutItemRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;
202 void _readXmlStyle( const QDomElement &elmt, const QgsReadWriteContext &context ) override;
203 void _writeXmlStyle( QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context ) const override;
204 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
205 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
206
207 protected slots:
208
209 void updateBoundingRect() override;
210
211 private:
212
214 std::unique_ptr<QgsLineSymbol> mPolylineStyleSymbol;
215
217 MarkerMode mStartMarker = NoMarker;
219 MarkerMode mEndMarker = NoMarker;
220
222 double mArrowHeadWidth = 4.0;
223
225 double mStartArrowHeadHeight = 0.0;
226
228 double mEndArrowHeadHeight = 0.0;
229
231 QString mStartMarkerFile;
232
234 QString mEndMarkerFile;
235
237 double mArrowHeadStrokeWidth = 1.0;
238
239 QColor mArrowHeadStrokeColor = Qt::black;
240 QColor mArrowHeadFillColor = Qt::black;
241
243 void createDefaultPolylineStyleSymbol();
244
249 void refreshSymbol();
250
251 void drawStartMarker( QPainter *painter );
252 void drawEndMarker( QPainter *painter );
253
254 void drawArrow( QPainter *painter, QPointF center, double angle );
255
256 void updateMarkerSvgSizes();
257
267 static void drawArrowHead( QPainter *p, double x, double y, double angle, double arrowHeadWidth );
268 void drawSvgMarker( QPainter *p, QPointF point, double angle, const QString &markerPath, double height ) const;
269
270 double computeMarkerMargin() const;
271
274
275};
276
277#endif // QGSLAYOUTITEMPOLYLINE_H
278
Layout item for node based polyline shapes.
double arrowHeadStrokeWidth() const
Returns the pen width in millimeters for the stroke of the arrow head.
QString startSvgMarkerPath() const
Returns the path the an SVG marker drawn at the start of the line.
QString endSvgMarkerPath() const
Returns the path the an SVG marker drawn at the end of the line.
QgsLineSymbol * symbol()
Returns the line symbol used to draw the shape.
QColor arrowHeadFillColor() const
Returns the color used to fill the arrow head.
MarkerMode endMarker() const
Returns the end marker mode, which controls what marker is drawn at the end of the line.
MarkerMode
Vertex marker mode.
@ ArrowHead
Show arrow marker.
@ NoMarker
Don't show marker.
QPainterPath shape() const override
~QgsLayoutItemPolyline() override
static QgsLayoutItemPolyline * create(QgsLayout *layout)
Returns a new polyline item for the specified layout.
QColor arrowHeadStrokeColor() const
Returns the color used to draw the stroke around the the arrow head.
void setSymbol(QgsLineSymbol *symbol)
Sets the symbol used to draw the shape.
MarkerMode startMarker() const
Returns the start marker mode, which controls what marker is drawn at the start of the line.
double arrowHeadWidth() const
Returns the width of line arrow heads in mm.
QgsLayoutItemPolyline(QgsLayout *layout)
Constructor for QgsLayoutItemPolyline for the specified layout.
Contains settings and helpers relating to a render of a QgsLayoutItem.
friend class QgsLayout
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
virtual QIcon icon() const
Returns the item's icon.
int type() const override
Returns a unique graphics item type identifier.
virtual QString displayName() const
Gets item display name.
virtual void updateBoundingRect()
Called when the bounding rect of the item should recalculated.
virtual bool _removeNode(int nodeIndex)=0
Method called in removeNode.
virtual void _writeXmlStyle(QDomDocument &doc, QDomElement &elmt, const QgsReadWriteContext &context) const =0
Method called in writeXml.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
virtual void _readXmlStyle(const QDomElement &elmt, const QgsReadWriteContext &context)=0
Method called in readXml.
virtual bool isValid() const =0
Must be reimplemented in subclasses.
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.
const QgsLayout * layout() const
Returns the layout the object is attached to.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
A line symbol type, for rendering LineString and MultiLineString geometries.
A container for the context for various read/write operations on objects.
An interface for classes which can visit style entity (e.g.
#define SIP_FACTORY
Definition qgis_sip.h:84