QGIS API Documentation  2.99.0-Master (9fdd060)
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 "qgis.h"
23 #include "qgscomposeritem.h"
24 #include <QBrush>
25 #include <QPen>
26 
27 class QgsLineSymbol;
28 
33 class CORE_EXPORT QgsComposerArrow: public QgsComposerItem
34 {
35  Q_OBJECT
36 
37  public:
38 
40  {
43  SVGMarker
44  };
45 
51 
58  QgsComposerArrow( QPointF startPoint, QPointF stopPoint, QgsComposition *c SIP_TRANSFERTHIS );
59 
61 
63  virtual int type() const override { return ComposerArrow; }
64 
66  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
67 
71  void setSceneRect( const QRectF &rectangle ) override;
72 
78  void setArrowHeadWidth( double width );
79 
85  double arrowHeadWidth() const { return mArrowHeadWidth; }
86 
93  void setStartMarker( const QString &svgPath );
94 
101  QString startMarker() const { return mStartMarkerFile; }
102 
109  void setEndMarker( const QString &svgPath );
110 
117  QString endMarker() const { return mEndMarkerFile; }
118 
126  QColor arrowHeadStrokeColor() const { return mArrowHeadStrokeColor; }
127 
135  void setArrowHeadStrokeColor( const QColor &color );
136 
144  QColor arrowHeadFillColor() const { return mArrowHeadFillColor; }
145 
153  void setArrowHeadFillColor( const QColor &color );
154 
162  void setArrowHeadStrokeWidth( const double width );
163 
171  double arrowHeadStrokeWidth() const { return mArrowHeadStrokeWidth; }
172 
179  void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
180 
187  QgsLineSymbol *lineSymbol() { return mLineSymbol; }
188 
194  MarkerMode markerMode() const { return mMarkerMode; }
195 
201  void setMarkerMode( MarkerMode mode );
202 
208  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
209 
215  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
216 
217  private:
218 
219  enum MarkerType
220  {
221  StartMarker,
222  EndMarker
223  };
224 
225  QPointF mStartPoint;
226  QPointF mStopPoint;
227 
232  int mStartXIdx;
233  int mStartYIdx;
234 
235  QPen mPen;
236  QBrush mBrush;
237 
239  double mArrowHeadWidth;
241  double mStartArrowHeadHeight;
242  double mStopArrowHeadHeight;
243 
245  QString mStartMarkerFile;
247  QString mEndMarkerFile;
249  MarkerMode mMarkerMode;
250 
251  double mArrowHeadStrokeWidth;
252  QColor mArrowHeadStrokeColor;
253  QColor mArrowHeadFillColor;
254 
259  int mBoundsBehavior;
260 
261  QgsLineSymbol *mLineSymbol = nullptr;
262 
267  void adaptItemSceneRect();
269  double computeMarkerMargin() const;
271  void drawHardcodedMarker( QPainter *p, MarkerType type );
273  void drawSVGMarker( QPainter *p, MarkerType type, const QString &markerPath );
275  void init();
276 
281  void createDefaultLineSymbol();
282 
287  void drawLine( QPainter *painter );
288 };
289 
290 #endif // QGSCOMPOSERARROW_H
291 
292 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
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.