QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
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"
24
30class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
31{
32 Q_OBJECT
33
34 public:
42
43
47 explicit QgsLayoutItemShape( QgsLayout *layout );
48
50
57
58
59 int type() const override;
60 QIcon icon() const override;
61
62 //Overridden to return shape type
63 QString displayName() const override;
64 QgsLayoutItem::Flags itemFlags() 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 );
96
101 QgsLayoutMeasurement cornerRadius() const { return mCornerRadius; }
102
103 QgsGeometry clipPath() const override;
104
105 // Depending on the symbol style, the bounding rectangle can be larger than the shape
106 QRectF boundingRect() const override;
107
108 // Reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology
109 // rather than the item's pen
110 double estimatedFrameBleed() const override;
111
112 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
113
114 protected:
115 void draw( QgsLayoutItemRenderContext &context ) override;
116
117 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
118 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
119
120 private slots:
121
129 void refreshSymbol( bool redraw );
130
132 void updateBoundingRect();
133
134 private:
135 Shape mShape = Rectangle;
136
137 std::unique_ptr< QgsFillSymbol > mShapeStyleSymbol;
138
139 double mMaxSymbolBleed = 0.0;
141 QRectF mCurrentRectangle;
142
143 QgsLayoutMeasurement mCornerRadius;
144
145 QPolygonF calculatePolygon( double scale ) const;
146};
147
148
149#endif //QGSLAYOUTITEMSHAPE_H
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A geometry is the spatial representation of a feature.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Layout item for basic filled shapes (e.g.
static QgsLayoutItemShape * create(QgsLayout *layout)
Returns a new shape item for the specified layout.
QgsFillSymbol * symbol()
Returns the fill symbol used to draw the shape.
~QgsLayoutItemShape() override
QgsLayoutItemShape(QgsLayout *layout)
Constructor for QgsLayoutItemShape, with the specified parent layout.
QgsLayoutMeasurement cornerRadius() const
Returns the corner radius for rounded rectangle corners.
@ Ellipse
Ellipse shape.
@ Rectangle
Rectangle shape.
@ Triangle
Triangle shape.
QgsLayoutItemShape::Shape shapeType() const
Returns the type of shape (e.g.
friend class QgsLayout
virtual QgsGeometry clipPath() const
Returns the clipping path generated by this item, in layout coordinates.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
virtual QIcon icon() const
Returns the item's icon.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
int type() const override
Returns a unique graphics item type identifier.
virtual QString displayName() const
Gets item display name.
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
QFlags< Flag > Flags
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
const QgsLayout * layout() const
Returns the layout the object is attached to.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
A container for the context for various read/write operations on objects.
An interface for classes which can visit style entity (e.g.
#define SIP_FACTORY
Definition qgis_sip.h:83