QgsLayoutItemShape class

Layout item for basic filled shapes (e.g.

rectangles, ellipses).

Base classes

class QgsLayoutItem
Base class for graphical items within a QgsLayout.

Public types

enum Shape { Ellipse, Rectangle, Triangle }
Shape type.

Public static functions

static auto create(QgsLayout* layout) -> QgsLayoutItemShape*
Returns a new shape item for the specified layout.

Constructors, destructors, conversion operators

QgsLayoutItemShape(QgsLayout* layout) explicit
Constructor for QgsLayoutItemShape, with the specified parent layout.

Public functions

auto cornerRadius() const -> QgsLayoutMeasurement
Returns the corner radius for rounded rectangle corners.
auto displayName() const -> QString override
Gets item display name.
auto estimatedFrameBleed() const -> double override
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
auto icon() const -> QIcon override
Returns the item's icon.
void setCornerRadius(QgsLayoutMeasurement radius)
Sets the corner radius for rounded rectangle corners.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
void setSymbol(QgsFillSymbol* symbol)
Sets the fill symbol used to draw the shape.
auto shapeType() const -> QgsLayoutItemShape::Shape
Returns the type of shape (e.g.
auto symbol() -> QgsFillSymbol*
Returns the fill symbol used to draw the shape.

Protected functions

void draw(QgsLayoutItemRenderContext& context) override
Draws the item's contents using the specified item render context.
auto readPropertiesFromElement(const QDomElement& element, const QDomDocument& document, const QgsReadWriteContext& context) -> bool override
Sets item state from a DOM element.
auto writePropertiesToElement(QDomElement& element, QDomDocument& document, const QgsReadWriteContext& context) const -> bool override
Stores item state within an XML DOM element.

Enum documentation

enum QgsLayoutItemShape::Shape

Shape type.

Enumerators
Ellipse

Ellipse shape.

Rectangle

Rectangle shape.

Triangle

Triangle shape.

Function documentation

static QgsLayoutItemShape* QgsLayoutItemShape::create(QgsLayout* layout)

Returns a new shape item for the specified layout.

The caller takes responsibility for deleting the returned object.

QgsLayoutMeasurement QgsLayoutItemShape::cornerRadius() const

Returns the corner radius for rounded rectangle corners.

QString QgsLayoutItemShape::displayName() const override

Gets item display name.

This is the item's id if set, and if not, a user-friendly string identifying item type.

double QgsLayoutItemShape::estimatedFrameBleed() const override

Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.

For instance, if the item has a 2mm frame stroke, then 1mm of this frame is drawn outside the item's rect. In this case the return value will be 1.0.

Returned values are in layout units.

void QgsLayoutItemShape::setCornerRadius(QgsLayoutMeasurement radius)

Sets the corner radius for rounded rectangle corners.

void QgsLayoutItemShape::setShapeType(QgsLayoutItemShape::Shape type)

Sets the type of shape (e.g.

rectangle, ellipse, etc).

void QgsLayoutItemShape::setSymbol(QgsFillSymbol* symbol)

Sets the fill symbol used to draw the shape.

Ownership is not transferred and a clone of the symbol is made.

QgsLayoutItemShape::Shape QgsLayoutItemShape::shapeType() const

Returns the type of shape (e.g.

rectangle, ellipse, etc).

QgsFillSymbol* QgsLayoutItemShape::symbol()

Returns the fill symbol used to draw the shape.

void QgsLayoutItemShape::draw(QgsLayoutItemRenderContext& context) override protected

Draws the item's contents using the specified item render context.

Note that the context's painter has been scaled so that painter units are pixels. Use the QgsRenderContext methods to convert from millimeters or other units to the painter's units.

bool QgsLayoutItemShape::readPropertiesFromElement(const QDomElement& element, const QDomDocument& document, const QgsReadWriteContext& context) override protected

Sets item state from a DOM element.

Parameters
element is the DOM element for the item
document DOM document
context read write context

Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map's signals should be implemented in finalizeRestoreFromXml(), not readPropertiesFromElement().

bool QgsLayoutItemShape::writePropertiesToElement(QDomElement& element, QDomDocument& document, const QgsReadWriteContext& context) const override protected

Stores item state within an XML DOM element.

Parameters
element is the DOM element to store the item's properties in
document DOM document
context read write context