QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgslayoutmeasurement.h"
24 
31 class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
32 {
33  Q_OBJECT
34 
35  public:
36 
38  enum Shape
39  {
42  Triangle
43  };
44 
45 
49  explicit QgsLayoutItemShape( QgsLayout *layout );
50 
51  ~QgsLayoutItemShape() override;
52 
58  static QgsLayoutItemShape *create( QgsLayout *layout ) SIP_FACTORY;
59 
60 
61  int type() const override;
62  QIcon icon() const override;
63 
64  //Overridden to return shape type
65  QString displayName() const override;
66  QgsLayoutItem::Flags itemFlags() const override;
67 
72  QgsLayoutItemShape::Shape shapeType() const { return mShape; }
73 
78  void setShapeType( QgsLayoutItemShape::Shape type );
79 
85  void setSymbol( QgsFillSymbol *symbol );
86 
91  QgsFillSymbol *symbol() { return mShapeStyleSymbol.get(); }
92 
97  void setCornerRadius( QgsLayoutMeasurement radius );
98 
103  QgsLayoutMeasurement cornerRadius() const { return mCornerRadius; }
104 
105  QgsGeometry clipPath() const override;
106 
107  // Depending on the symbol style, the bounding rectangle can be larger than the shape
108  QRectF boundingRect() const override;
109 
110  // Reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology
111  // rather than the item's pen
112  double estimatedFrameBleed() const override;
113 
114  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
115 
116  protected:
117 
118  void draw( QgsLayoutItemRenderContext &context ) override;
119 
120  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
121  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
122 
123  private slots:
124 
132  void refreshSymbol( bool redraw );
133 
135  void updateBoundingRect();
136 
137  private:
138 
139  Shape mShape = Rectangle;
140 
141  std::unique_ptr< QgsFillSymbol > mShapeStyleSymbol;
142 
143  double mMaxSymbolBleed = 0.0;
145  QRectF mCurrentRectangle;
146 
147  QgsLayoutMeasurement mCornerRadius;
148 
149  QPolygonF calculatePolygon( double scale ) const;
150 };
151 
152 
153 #endif //QGSLAYOUTITEMSHAPE_H
QgsLayoutItemShape
Layout item for basic filled shapes (e.g. rectangles, ellipses).
Definition: qgslayoutitemshape.h:31
QgsLayoutItem::writePropertiesToElement
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
Definition: qgslayoutitem.cpp:1326
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:336
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
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:1331
QgsLayoutItemShape::Ellipse
@ Ellipse
Ellipse shape.
Definition: qgslayoutitemshape.h:40
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::clipPath
virtual QgsGeometry clipPath() const
Returns the clipping path generated by this item, in layout coordinates.
Definition: qgslayoutitem.cpp:1172
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:41
QgsLayoutItem::itemFlags
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
Definition: qgslayoutitem.cpp:129
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsLayoutItemShape::symbol
QgsFillSymbol * symbol()
Returns the fill symbol used to draw the shape.
Definition: qgslayoutitemshape.h:91
QgsLayoutItemShape::shapeType
QgsLayoutItemShape::Shape shapeType() const
Returns the type of shape (e.g.
Definition: qgslayoutitemshape.h:72
QgsLayoutItemShape::Shape
Shape
Shape type.
Definition: qgslayoutitemshape.h:38
QgsLayoutItemShape::cornerRadius
QgsLayoutMeasurement cornerRadius() const
Returns the corner radius for rounded rectangle corners.
Definition: qgslayoutitemshape.h:103
qgslayoutitemregistry.h
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:33