36 return QStringLiteral(
"polygon" );
42 auto transformRing = [&context]( QPolygonF & pts )
58 pts.erase( std::remove_if( pts.begin(), pts.end(),
59 [](
const QPointF point )
61 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
64 QPointF *ptr = pts.data();
65 for (
int i = 0; i < pts.size(); ++i, ++ptr )
71 QPolygonF exterior = mPolygon->exteriorRing()->asQPolygonF();
72 transformRing( exterior );
73 QVector<QPolygonF> rings;
74 rings.reserve( mPolygon->numInteriorRings() );
75 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
77 QPolygonF ring = mPolygon->interiorRing( i )->asQPolygonF();
78 transformRing( ring );
82 mSymbol->startRender( context );
83 mSymbol->renderPolygon( exterior, rings.empty() ?
nullptr : &rings,
nullptr, context );
84 mSymbol->stopRender( context );
89 element.setAttribute( QStringLiteral(
"wkt" ), mPolygon->asWkt() );
91 element.setAttribute( QStringLiteral(
"zIndex" ),
zIndex() );
104 const QString wkt = element.attribute( QStringLiteral(
"wkt" ) );
107 mPolygon.reset( polygon->clone() );
109 setZIndex( element.attribute( QStringLiteral(
"zIndex" ) ).toInt() );
111 const QDomElement symbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
112 if ( !symbolElem.isNull() )
113 setSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElem, context ) );
120 std::unique_ptr< QgsAnnotationPolygonItem > item = std::make_unique< QgsAnnotationPolygonItem >( mPolygon->clone() );
121 item->setSymbol( mSymbol->clone() );
122 item->setZIndex(
zIndex() );
123 return item.release();
128 return mPolygon->boundingBox();
133 return mSymbol.get();
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
void setZIndex(int index)
Sets the item's z index, which controls the order in which annotation items are rendered in the layer...
int zIndex() const
Returns the item's z index, which controls the order in which annotation items are rendered in the la...
An annotation item which renders a fill symbol for a polygon geometry.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
void render(QgsRenderContext &context, QgsFeedback *feedback) override
Renders the item to the specified render context.
void setSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the polygon item.
const QgsFillSymbol * symbol() const
Returns the symbol used to render the item.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
const QgsCurvePolygon * geometry() const
Returns the geometry of the item.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the item's state into an XML element.
QgsAnnotationPolygonItem * clone() override
Returns a clone of the item.
~QgsAnnotationPolygonItem() override
static QgsAnnotationPolygonItem * create()
Creates a new polygon annotation item.
QgsAnnotationPolygonItem(QgsCurvePolygon *polygon)
Constructor for QgsAnnotationPolygonItem, with the specified polygon geometry.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A geometry is the spatial representation of a feature.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.