QGIS API Documentation  2.99.0-Master (ae4d26a)
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 
32 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
33 {
34  Q_OBJECT
35  public:
36 
37  enum Shape
38  {
41  Triangle
42  };
43 
45  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition *composition SIP_TRANSFERTHIS );
47 
49  virtual int type() const override { return ComposerShape; }
50 
52  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
53 
59  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
60 
66  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
67 
68  //setters and getters
69  QgsComposerShape::Shape shapeType() const { return mShape; }
70  void setShapeType( QgsComposerShape::Shape s );
71 
73  void setCornerRadius( double radius );
75  double cornerRadius() const { return mCornerRadius; }
76 
81  void setShapeStyleSymbol( QgsFillSymbol *symbol );
82 
86  QgsFillSymbol *shapeStyleSymbol() { return mShapeStyleSymbol; }
87 
91  void setUseSymbol( bool useSymbol );
92 
96  QRectF boundingRect() const override;
97 
102  void setSceneRect( const QRectF &rectangle ) override;
103 
104  //Overridden to return shape type
105  virtual QString displayName() const override;
106 
107  protected:
108  /* reimplement drawFrame, since it's not a rect, but a custom shape */
109  virtual void drawFrame( QPainter *p ) override;
110  /* reimplement drawBackground, since it's not a rect, but a custom shape */
111  virtual void drawBackground( QPainter *p ) override;
112 
116  virtual double estimatedFrameBleed() const override;
117 
118  public slots:
119 
124  void refreshSymbol();
125 
126  private:
128  Shape mShape;
129 
130  double mCornerRadius;
131 
132  bool mUseSymbol;
133 
134  QgsFillSymbol *mShapeStyleSymbol = nullptr;
135  double mMaxSymbolBleed;
137  QRectF mCurrentRectangle;
138 
139  /* draws the custom shape */
140  void drawShape( QPainter *p );
141 
142  /* draws the custom shape using symbol v2*/
143  void drawShapeUsingSymbol( QPainter *p );
144 
145  /* creates the default shape symbol */
146  void createDefaultShapeStyleSymbol();
147 
149  QPointF pointOnLineWithDistance( const QPointF &startPoint, const QPointF &directionPoint, double distance ) const;
150 
152  void updateBoundingRect();
153 };
154 
155 #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.