QGIS API Documentation  2.99.0-Master (37c43df)
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 "qgscomposeritem.h"
22 #include <QBrush>
23 #include <QPen>
24 
25 class QgsFillSymbol;
26 
29 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
30 {
31  Q_OBJECT
32  public:
33 
34  enum Shape
35  {
38  Triangle
39  };
40 
41  QgsComposerShape( QgsComposition* composition );
42  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
44 
46  virtual int type() const override { return ComposerShape; }
47 
49  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
50 
55  bool writeXml( QDomElement& elem, QDomDocument & doc ) const override;
56 
61  bool readXml( const QDomElement& itemElem, const QDomDocument& doc ) override;
62 
63  //setters and getters
64  QgsComposerShape::Shape shapeType() const { return mShape; }
65  void setShapeType( QgsComposerShape::Shape s );
66 
68  void setCornerRadius( double radius );
70  double cornerRadius() const { return mCornerRadius; }
71 
75  void setShapeStyleSymbol( QgsFillSymbol* symbol );
76 
79  QgsFillSymbol* shapeStyleSymbol() { return mShapeStyleSymbol; }
80 
83  void setUseSymbol( bool useSymbol );
84 
87  QRectF boundingRect() const override;
88 
92  void setSceneRect( const QRectF& rectangle ) override;
93 
94  //Overridden to return shape type
95  virtual QString displayName() const override;
96 
97  protected:
98  /* reimplement drawFrame, since it's not a rect, but a custom shape */
99  virtual void drawFrame( QPainter* p ) override;
100  /* reimplement drawBackground, since it's not a rect, but a custom shape */
101  virtual void drawBackground( QPainter* p ) override;
102 
105  virtual double estimatedFrameBleed() const override;
106 
107  public slots:
108 
112  void refreshSymbol();
113 
114  private:
116  Shape mShape;
117 
118  double mCornerRadius;
119 
120  bool mUseSymbol;
121 
122  QgsFillSymbol* mShapeStyleSymbol;
123  double mMaxSymbolBleed;
125  QRectF mCurrentRectangle;
126 
127  /* draws the custom shape */
128  void drawShape( QPainter* p );
129 
130  /* draws the custom shape using symbol v2*/
131  void drawShapeUsingSymbol( QPainter* p );
132 
133  /* creates the default shape symbol */
134  void createDefaultShapeStyleSymbol();
135 
137  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
138 
140  void updateBoundingRect();
141 };
142 
143 #endif // QGSCOMPOSERSHAPEITEM_H
virtual QString displayName() const
Get item display name.
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.