QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslayoutitemshape.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemshape.h
3  ---------------------
4  begin : July 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSLAYOUTITEMSHAPE_H
18 #define QGSLAYOUTITEMSHAPE_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitem.h"
22 #include "qgslayoutitemregistry.h"
23 #include "qgssymbol.h"
24 #include "qgslayoutmeasurement.h"
25 
32 class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
33 {
34  Q_OBJECT
35 
36  public:
37 
39  enum Shape
40  {
43  Triangle
44  };
45 
46 
50  explicit QgsLayoutItemShape( QgsLayout *layout );
51 
57  static QgsLayoutItemShape *create( QgsLayout *layout ) SIP_FACTORY;
58 
59 
60  int type() const override;
61  QIcon icon() const override;
62 
63  //Overridden to return shape type
64  QString displayName() const override;
65 
70  QgsLayoutItemShape::Shape shapeType() const { return mShape; }
71 
76  void setShapeType( QgsLayoutItemShape::Shape type );
77 
83  void setSymbol( QgsFillSymbol *symbol );
84 
89  QgsFillSymbol *symbol() { return mShapeStyleSymbol.get(); }
90 
95  void setCornerRadius( QgsLayoutMeasurement radius ) { mCornerRadius = radius; }
96 
101  QgsLayoutMeasurement cornerRadius() const { return mCornerRadius; }
102 
103  // Depending on the symbol style, the bounding rectangle can be larger than the shape
104  QRectF boundingRect() const override;
105 
106  // Reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology
107  // rather than the item's pen
108  double estimatedFrameBleed() const override;
109 
110  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
111 
112  protected:
113 
114  void draw( QgsLayoutItemRenderContext &context ) override;
115 
116  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
117  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
118 
119  private slots:
120 
125  void refreshSymbol();
126 
128  void updateBoundingRect();
129 
130  private:
131 
132  Shape mShape = Rectangle;
133 
134  std::unique_ptr< QgsFillSymbol > mShapeStyleSymbol;
135 
136  double mMaxSymbolBleed = 0.0;
138  QRectF mCurrentRectangle;
139 
140  QgsLayoutMeasurement mCornerRadius;
141 };
142 
143 
144 #endif //QGSLAYOUTITEMSHAPE_H
QgsLayoutItemShape
Layout item for basic filled shapes (e.g. rectangles, ellipses).
Definition: qgslayoutitemshape.h:32
QgsLayoutItem::writePropertiesToElement
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
Definition: qgslayoutitem.cpp:1318
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:331
QgsLayoutItemRenderContext
Definition: qgslayoutitem.h:44
QgsLayoutItemShape::setCornerRadius
void setCornerRadius(QgsLayoutMeasurement radius)
Sets the corner radius for rounded rectangle corners.
Definition: qgslayoutitemshape.h:95
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsLayoutItem::readPropertiesFromElement
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
Definition: qgslayoutitem.cpp:1323
QgsLayoutItemShape::Ellipse
@ Ellipse
Ellipse shape.
Definition: qgslayoutitemshape.h:41
QgsLayoutItem::draw
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
QgsLayoutItem::estimatedFrameBleed
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
Definition: qgslayoutitem.cpp:937
qgslayoutitem.h
QgsLayoutItem::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitem.cpp:1166
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:112
qgslayoutmeasurement.h
QgsLayoutItemShape::Rectangle
@ Rectangle
Rectangle shape.
Definition: qgslayoutitemshape.h:42
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsFillSymbol
Definition: qgssymbol.h:1212
QgsLayoutItemShape::symbol
QgsFillSymbol * symbol()
Returns the fill symbol used to draw the shape.
Definition: qgslayoutitemshape.h:89
QgsLayoutItemShape::shapeType
QgsLayoutItemShape::Shape shapeType() const
Returns the type of shape (e.g.
Definition: qgslayoutitemshape.h:70
QgsLayoutItemShape::Shape
Shape
Shape type.
Definition: qgslayoutitemshape.h:39
QgsLayoutItemShape::cornerRadius
QgsLayoutMeasurement cornerRadius() const
Returns the corner radius for rounded rectangle corners.
Definition: qgslayoutitemshape.h:101
qgslayoutitemregistry.h
qgssymbol.h
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:33