QGIS API Documentation  2.99.0-Master (0a63d1f)
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 "qgscomposeritem.h"
23 #include <QBrush>
24 #include <QPen>
25 
26 class QgsFillSymbol;
27 
30 class CORE_EXPORT QgsComposerShape: public QgsComposerItem
31 {
32  Q_OBJECT
33  public:
34 
35  enum Shape
36  {
39  Triangle
40  };
41 
42  QgsComposerShape( QgsComposition* composition );
43  QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition );
45 
47  virtual int type() const override { return ComposerShape; }
48 
50  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
51 
56  bool writeXml( QDomElement& elem, QDomDocument & doc ) const override;
57 
62  bool readXml( const QDomElement& itemElem, const QDomDocument& doc ) override;
63 
64  //setters and getters
65  QgsComposerShape::Shape shapeType() const { return mShape; }
66  void setShapeType( QgsComposerShape::Shape s );
67 
69  void setCornerRadius( double radius );
71  double cornerRadius() const { return mCornerRadius; }
72 
76  void setShapeStyleSymbol( QgsFillSymbol* symbol );
77 
80  QgsFillSymbol* shapeStyleSymbol() { return mShapeStyleSymbol; }
81 
84  void setUseSymbol( bool useSymbol );
85 
88  QRectF boundingRect() const override;
89 
93  void setSceneRect( const QRectF& rectangle ) override;
94 
95  //Overridden to return shape type
96  virtual QString displayName() const override;
97 
98  protected:
99  /* reimplement drawFrame, since it's not a rect, but a custom shape */
100  virtual void drawFrame( QPainter* p ) override;
101  /* reimplement drawBackground, since it's not a rect, but a custom shape */
102  virtual void drawBackground( QPainter* p ) override;
103 
106  virtual double estimatedFrameBleed() const override;
107 
108  public slots:
109 
113  void refreshSymbol();
114 
115  private:
117  Shape mShape;
118 
119  double mCornerRadius;
120 
121  bool mUseSymbol;
122 
123  QgsFillSymbol* mShapeStyleSymbol;
124  double mMaxSymbolBleed;
126  QRectF mCurrentRectangle;
127 
128  /* draws the custom shape */
129  void drawShape( QPainter* p );
130 
131  /* draws the custom shape using symbol v2*/
132  void drawShapeUsingSymbol( QPainter* p );
133 
134  /* creates the default shape symbol */
135  void createDefaultShapeStyleSymbol();
136 
138  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
139 
141  void updateBoundingRect();
142 };
143 
144 #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.