32 QVariantMap properties;
33 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"white" ) );
34 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
35 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
36 properties.insert( QStringLiteral(
"color_border" ), QStringLiteral(
"black" ) );
37 properties.insert( QStringLiteral(
"width_border" ), QStringLiteral(
"0.3" ) );
38 properties.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
77 if ( !
id().isEmpty() )
85 return tr(
"<Ellipse>" );
87 return tr(
"<Rectangle>" );
89 return tr(
"<Triangle>" );
92 return tr(
"<Shape>" );
104 if (
type == mShape )
111 if (
mLayout &&
id().isEmpty() )
114 mLayout->itemsModel()->updateItemDisplayName(
this );
120 void QgsLayoutItemShape::refreshSymbol()
122 if (
auto *lLayout =
layout() )
128 updateBoundingRect();
134 void QgsLayoutItemShape::updateBoundingRect()
136 QRectF rectangle = rect();
137 rectangle.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
138 if ( rectangle != mCurrentRectangle )
140 prepareGeometryChange();
141 mCurrentRectangle = rectangle;
156 mCornerRadius = radius;
162 QPolygonF shapePolygon = mapToScene( calculatePolygon( 1.0 ) );
164 if ( shapePolygon.at( 0 ) != shapePolygon.constLast() )
165 shapePolygon << shapePolygon.at( 0 );
171 return mCurrentRectangle;
176 return mMaxSymbolBleed;
181 if ( mShapeStyleSymbol )
194 painter->setPen( Qt::NoPen );
195 painter->setBrush( Qt::NoBrush );
199 QVector<QPolygonF> rings;
206 QPolygonF QgsLayoutItemShape::calculatePolygon(
double scale )
const
208 QPolygonF shapePolygon;
212 QTransform t = QTransform::fromScale( 100, 100 );
214 QTransform ti = t.inverted();
221 QPainterPath ellipsePath;
222 ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
223 QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
224 shapePolygon = ti.map( ellipsePoly );
230 if ( mCornerRadius.
length() > 0 )
232 QPainterPath roundedRectPath;
233 double radius =
mLayout->convertToLayoutUnits( mCornerRadius ) * scale;
234 roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ), radius, radius );
235 QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
236 shapePolygon = ti.map( roundedPoly );
240 shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
246 shapePolygon << QPointF( 0, rect().height() * scale );
247 shapePolygon << QPointF( rect().width() * scale, rect().height() * scale );
248 shapePolygon << QPointF( rect().width() / 2.0 * scale, 0 );
249 shapePolygon << QPointF( 0, rect().height() * scale );
258 element.setAttribute( QStringLiteral(
"shapeType" ), mShape );
259 element.setAttribute( QStringLiteral(
"cornerRadiusMeasure" ), mCornerRadius.
encodeMeasurement() );
262 element.appendChild( shapeStyleElem );
269 mShape =
static_cast< Shape >( element.attribute( QStringLiteral(
"shapeType" ), QStringLiteral(
"0" ) ).toInt() );
270 if ( element.hasAttribute( QStringLiteral(
"cornerRadiusMeasure" ) ) )
273 mCornerRadius =
QgsLayoutMeasurement( element.attribute( QStringLiteral(
"cornerRadius" ), QStringLiteral(
"0" ) ).toDouble() );
275 QDomElement shapeStyleSymbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
276 if ( !shapeStyleSymbolElem.isNull() )
278 mShapeStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( shapeStyleSymbolElem, context ) );
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol using the given render context.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
A geometry is the spatial representation of a feature.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Layout item for basic filled shapes (e.g.
QRectF boundingRect() const override
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
static QgsLayoutItemShape * create(QgsLayout *layout)
Returns a new shape item for the specified layout.
double estimatedFrameBleed() const override
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
QString displayName() const override
Gets item display name.
QgsLayoutItemShape(QgsLayout *layout)
Constructor for QgsLayoutItemShape, with the specified parent layout.
QgsGeometry clipPath() const override
Returns the clipping path generated by this item, in layout coordinates.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void setSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to draw the shape.
QIcon icon() const override
Returns the item's icon.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsFillSymbol * symbol()
Returns the fill symbol used to draw the shape.
int type() const override
@ Rectangle
Rectangle shape.
@ Triangle
Triangle shape.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
void setCornerRadius(QgsLayoutMeasurement radius)
Sets the corner radius for rounded rectangle corners.
Base class for graphical items within a QgsLayout.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
@ FlagProvidesClipPath
Item can act as a clipping path provider (see clipPath())
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
void frameChanged()
Emitted if the item's frame style changes.
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
void clipPathChanged()
Emitted when the item's clipping path has changed.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
double length() const
Returns the length of the measurement.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A symbol entity for QgsStyle databases.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
@ RenderMillimeters
Millimeters.
Contains information relating to the style entity currently being visited.