QGIS API Documentation  2.99.0-Master (3450a9f)
qgscomposerarrow.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerarrow.h
3  ----------------------
4  begin : November 2009
5  copyright : (C) 2009 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOMPOSERARROW_H
19 #define QGSCOMPOSERARROW_H
20 
21 #include "qgis_core.h"
22 #include "qgscomposeritem.h"
23 #include <QBrush>
24 #include <QPen>
25 
26 class QgsLineSymbol;
27 
31 class CORE_EXPORT QgsComposerArrow: public QgsComposerItem
32 {
33  Q_OBJECT
34 
35  public:
36 
38  {
41  SVGMarker
42  };
43 
48 
54  QgsComposerArrow( QPointF startPoint, QPointF stopPoint, QgsComposition *c );
55 
57 
59  virtual int type() const override { return ComposerArrow; }
60 
62  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
63 
66  void setSceneRect( const QRectF &rectangle ) override;
67 
72  void setArrowHeadWidth( double width );
73 
78  double arrowHeadWidth() const { return mArrowHeadWidth; }
79 
85  void setStartMarker( const QString &svgPath );
86 
92  QString startMarker() const { return mStartMarkerFile; }
93 
99  void setEndMarker( const QString &svgPath );
100 
106  QString endMarker() const { return mEndMarkerFile; }
107 
114  QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
115 
122  void setArrowHeadStrokeColor( const QColor &color );
123 
130  QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
131 
138  void setArrowHeadFillColor( const QColor &color );
139 
146  void setArrowHeadStrokeWidth( const double width );
147 
154  double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
155 
161  void setLineSymbol( QgsLineSymbol *symbol );
162 
168  QgsLineSymbol *lineSymbol() { return mLineSymbol; }
169 
174  MarkerMode markerMode() const { return mMarkerMode; }
175 
180  void setMarkerMode( MarkerMode mode );
181 
186  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
187 
192  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
193 
194  private:
195 
196  enum MarkerType
197  {
198  StartMarker,
199  EndMarker
200  };
201 
202  QPointF mStartPoint;
203  QPointF mStopPoint;
204 
208  int mStartXIdx;
209  int mStartYIdx;
210 
211  QPen mPen;
212  QBrush mBrush;
213 
215  double mArrowHeadWidth;
217  double mStartArrowHeadHeight;
218  double mStopArrowHeadHeight;
219 
221  QString mStartMarkerFile;
223  QString mEndMarkerFile;
225  MarkerMode mMarkerMode;
226 
227  double mArrowHeadStrokeWidth;
228  QColor mArrowHeadStrokeColor;
229  QColor mArrowHeadFillColor;
230 
234  int mBoundsBehavior;
235 
236  QgsLineSymbol *mLineSymbol = nullptr;
237 
241  void adaptItemSceneRect();
243  double computeMarkerMargin() const;
245  void drawHardcodedMarker( QPainter *p, MarkerType type );
247  void drawSVGMarker( QPainter *p, MarkerType type, const QString &markerPath );
249  void init();
250 
254  void createDefaultLineSymbol();
255 
259  void drawLine( QPainter *painter );
260 };
261 
262 #endif // QGSCOMPOSERARROW_H
263 
264 
QColor arrowHeadFillColor() const
Returns the color used to fill the arrow head.
An item that draws an arrow between two points.
virtual int type() const override
Return composer item type.
QColor arrowHeadStrokeColor() const
Returns the color used to draw stroke around the the arrow head.
A item that forms part of a map composition.
double arrowHeadWidth() const
Returns the width of the arrow head in mm.
QgsLineSymbol * lineSymbol()
Returns the line symbol used for drawing the line portion of the arrow.
QString startMarker() const
Returns the marker drawn at the start of the line.
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Graphics scene for map printing.
MarkerMode markerMode() const
Returns marker mode, which controls how the arrow endpoints are drawn.
double arrowHeadStrokeWidth() const
Returns the pen width for the stroke of the arrow head.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
QString endMarker() const
Returns the marker drawn at the end of the line.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.