QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 QgsFillSymbolV2;
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( QgsFillSymbolV2* symbol );
78  QgsFillSymbolV2* shapeStyleSymbol() { return mShapeStyleSymbol; }
79 
82  void setUseSymbolV2( bool useSymbolV2 );
83 
86  QRectF boundingRect() const override;
87 
91  void setSceneRect( const QRectF& rectangle ) override;
92 
93  //Overridden to return shape type
94  virtual QString displayName() const override;
95 
96  protected:
97  /* reimplement drawFrame, since it's not a rect, but a custom shape */
98  virtual void drawFrame( QPainter* p ) override;
99  /* reimplement drawBackground, since it's not a rect, but a custom shape */
100  virtual void drawBackground( QPainter* p ) override;
103  virtual double estimatedFrameBleed() const override;
104 
105  public slots:
109  void refreshSymbol();
110 
111  private:
113  Shape mShape;
114 
115  double mCornerRadius;
116 
117  bool mUseSymbolV2;
118 
119  QgsFillSymbolV2* mShapeStyleSymbol;
120  double mMaxSymbolBleed;
122  QRectF mCurrentRectangle;
123 
124  /* draws the custom shape */
125  void drawShape( QPainter* p );
126 
127  /* draws the custom shape using symbol v2*/
128  void drawShapeUsingSymbol( QPainter* p );
129 
130  /* creates the default shape symbol */
131  void createDefaultShapeStyleSymbol();
132 
134  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
135 
137  void updateBoundingRect();
138 };
139 
140 #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 writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
virtual QRectF boundingRect() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QgsComposerShape::Shape shapeType() const
QgsFillSymbolV2 * shapeStyleSymbol()
Returns the QgsFillSymbolV2 used to draw the shape.
Graphics scene for map printing.
A composer items that draws common shapes (ellipse, triangle, rectangle)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
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...