QGIS API Documentation  2.99.0-Master (7d4f81d)
qgscomposershape.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposershape.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 QGSCOMPOSERSHAPE_H
19 #define QGSCOMPOSERSHAPE_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgscomposeritem.h"
24 #include <QBrush>
25 #include <QPen>
26 
27 class QgsFillSymbol;
28 
31 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
32 {
33  Q_OBJECT
34  public:
35 
36  enum Shape
37  {
40  Triangle
41  };
42 
44  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition *composition SIP_TRANSFERTHIS );
46 
48  virtual int type() const override { return ComposerShape; }
49 
51  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
52 
57  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
58 
63  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
64 
65  //setters and getters
66  QgsComposerShape::Shape shapeType() const { return mShape; }
67  void setShapeType( QgsComposerShape::Shape s );
68 
70  void setCornerRadius( double radius );
72  double cornerRadius() const { return mCornerRadius; }
73 
77  void setShapeStyleSymbol( QgsFillSymbol *symbol );
78 
81  QgsFillSymbol *shapeStyleSymbol() { return mShapeStyleSymbol; }
82 
85  void setUseSymbol( bool useSymbol );
86 
89  QRectF boundingRect() const override;
90 
94  void setSceneRect( const QRectF &rectangle ) override;
95 
96  //Overridden to return shape type
97  virtual QString displayName() const override;
98 
99  protected:
100  /* reimplement drawFrame, since it's not a rect, but a custom shape */
101  virtual void drawFrame( QPainter *p ) override;
102  /* reimplement drawBackground, since it's not a rect, but a custom shape */
103  virtual void drawBackground( QPainter *p ) override;
104 
107  virtual double estimatedFrameBleed() const override;
108 
109  public slots:
110 
114  void refreshSymbol();
115 
116  private:
118  Shape mShape;
119 
120  double mCornerRadius;
121 
122  bool mUseSymbol;
123 
124  QgsFillSymbol *mShapeStyleSymbol = nullptr;
125  double mMaxSymbolBleed;
127  QRectF mCurrentRectangle;
128 
129  /* draws the custom shape */
130  void drawShape( QPainter *p );
131 
132  /* draws the custom shape using symbol v2*/
133  void drawShapeUsingSymbol( QPainter *p );
134 
135  /* creates the default shape symbol */
136  void createDefaultShapeStyleSymbol();
137 
139  QPointF pointOnLineWithDistance( const QPointF &startPoint, const QPointF &directionPoint, double distance ) const;
140 
142  void updateBoundingRect();
143 };
144 
145 #endif // QGSCOMPOSERSHAPEITEM_H
virtual QString displayName() const
Get item display name.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A item that forms part of a map composition.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item&#39;s frame bleeds outside the item&#39;s actual rectangle.
double cornerRadius() const
Returns the radius for rounded rectangle corners.
virtual void drawFrame(QPainter *p)
Draw black frame around item.
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
QgsComposerShape::Shape shapeType() const
Graphics scene for map printing.
A composer items that draws common shapes (ellipse, triangle, rectangle)
QgsFillSymbol * shapeStyleSymbol()
Returns the QgsFillSymbol used to draw the shape.
virtual int type() const override
Return correct graphics item type.
virtual void drawBackground(QPainter *p)
Draw background.
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...
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.