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