32 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"white" ) );
33 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
34 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
35 properties.insert( QStringLiteral(
"color_border" ), QStringLiteral(
"black" ) );
36 properties.insert( QStringLiteral(
"width_border" ), QStringLiteral(
"0.3" ) );
37 properties.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
75 if ( !
id().isEmpty() )
83 return tr(
"<Ellipse>" );
85 return tr(
"<Rectangle>" );
87 return tr(
"<Triangle>" );
90 return tr(
"<Shape>" );
102 if (
mLayout &&
id().isEmpty() )
105 mLayout->itemsModel()->updateItemDisplayName(
this );
109 void QgsLayoutItemShape::refreshSymbol()
117 updateBoundingRect();
123 void QgsLayoutItemShape::updateBoundingRect()
125 QRectF rectangle = rect();
126 rectangle.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
127 if ( rectangle != mCurrentRectangle )
129 prepareGeometryChange();
130 mCurrentRectangle = rectangle;
139 mShapeStyleSymbol.reset( symbol->
clone() );
145 return mCurrentRectangle;
150 return mMaxSymbolBleed;
156 painter->setPen( Qt::NoPen );
157 painter->setBrush( Qt::NoBrush );
161 QPolygonF shapePolygon;
165 QTransform t = QTransform::fromScale( 100, 100 );
167 QTransform ti = t.inverted();
174 QPainterPath ellipsePath;
175 ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
176 QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
177 shapePolygon = ti.map( ellipsePoly );
183 if ( mCornerRadius.
length() > 0 )
185 QPainterPath roundedRectPath;
186 double radius =
mLayout->convertToLayoutUnits( mCornerRadius ) * scale;
187 roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ), radius, radius );
188 QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
189 shapePolygon = ti.map( roundedPoly );
193 shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
199 shapePolygon << QPointF( 0, rect().height() * scale );
200 shapePolygon << QPointF( rect().width() * scale, rect().height() * scale );
201 shapePolygon << QPointF( rect().width() / 2.0 * scale, 0 );
202 shapePolygon << QPointF( 0, rect().height() * scale );
207 QList<QPolygonF> rings;
216 element.setAttribute( QStringLiteral(
"shapeType" ), mShape );
217 element.setAttribute( QStringLiteral(
"cornerRadiusMeasure" ), mCornerRadius.
encodeMeasurement() );
220 element.appendChild( shapeStyleElem );
227 mShape =
static_cast< Shape >( element.attribute( QStringLiteral(
"shapeType" ), QStringLiteral(
"0" ) ).toInt() );
228 if ( element.hasAttribute( QStringLiteral(
"cornerRadiusMeasure" ) ) )
231 mCornerRadius =
QgsLayoutMeasurement( element.attribute( QStringLiteral(
"cornerRadius" ), QStringLiteral(
"0" ) ).toDouble() );
233 QDomElement shapeStyleSymbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
234 if ( !shapeStyleSymbolElem.isNull() )
236 mShapeStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( shapeStyleSymbolElem, context ) );
QIcon icon() const override
Returns the item's icon.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
The class is used as a container of context for various read/write operations on other objects...
Base class for graphical items within a QgsLayout.
double estimatedFrameBleed() const override
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
QgsLayoutItemShape(QgsLayout *layout)
Constructor for QgsLayoutItemShape, with the specified parent layout.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QMap< QString, QString > QgsStringMap
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
QString displayName() const override
Gets item display name.
void frameChanged()
Emitted if the item's frame style changes.
void sizePositionChanged()
Emitted when the item's size or position changes.
static QgsLayoutItemShape * create(QgsLayout *layout)
Returns a new shape item for the specified layout.
const QgsLayout * layout() const
Returns the layout the object is attached to.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
QgsFillSymbol * clone() const override
Gets a deep copy of this symbol.
double dpi() const
Returns the dpi for outputting the layout.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Layout item for basic filled shapes (e.g.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
QPointer< QgsLayout > mLayout
int type() const override
QRectF boundingRect() const override
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
QString id() const
Returns the item's ID name.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Contains settings and helpers relating to a render of a QgsLayoutItem.
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
double length() const
Returns the length of the measurement.
void setSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to draw the shape.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFillSymbol * symbol()
Returns the fill symbol used to draw the shape.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
void stopRender(QgsRenderContext &context)
Ends the rendering process.