41 return QStringLiteral(
"polygon" );
47 auto transformRing = [&context]( QPolygonF & pts )
63 pts.erase( std::remove_if( pts.begin(), pts.end(),
64 [](
const QPointF point )
66 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
69 QPointF *ptr = pts.data();
70 for (
int i = 0; i < pts.size(); ++i, ++ptr )
76 QPolygonF exterior = mPolygon->exteriorRing()->asQPolygonF();
77 transformRing( exterior );
78 QVector<QPolygonF> rings;
79 rings.reserve( mPolygon->numInteriorRings() );
80 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
82 QPolygonF ring = mPolygon->interiorRing( i )->asQPolygonF();
83 transformRing( ring );
87 mSymbol->startRender( context );
88 mSymbol->renderPolygon( exterior, rings.empty() ?
nullptr : &rings,
nullptr, context );
89 mSymbol->stopRender( context );
94 element.setAttribute( QStringLiteral(
"wkt" ), mPolygon->asWkt() );
103 QList< QgsAnnotationItemNode > res;
105 auto processRing = [&res](
const QgsCurve * ring,
int ringId )
109 res.reserve( res.size() + count );
110 for (
int i = 0; i < count; ++i )
116 if (
const QgsCurve *ring = mPolygon->exteriorRing() )
118 processRing( ring, 0 );
120 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
122 processRing( mPolygon->interiorRing( i ), i + 1 );
130 switch ( operation->
type() )
143 if ( mPolygon->deleteVertex( deleteOperation->
nodeId() ) )
154 mPolygon->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
155 if ( mPolygon->insertVertex( endOfSegmentVertex, segmentPoint ) )
163 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
164 mPolygon->transform( transform );
174 switch ( operation->
type() )
179 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
180 if ( modifiedPolygon->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
190 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
191 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
192 modifiedPolygon->transform( transform );
215 const QString wkt = element.attribute( QStringLiteral(
"wkt" ) );
218 mPolygon.reset( polygon->clone() );
220 const QDomElement symbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
221 if ( !symbolElem.isNull() )
230 auto item = std::make_unique< QgsAnnotationPolygonItem >( mPolygon->clone() );
231 item->setSymbol( mSymbol->clone() );
232 item->copyCommonProperties(
this );;
233 return item.release();
238 return mPolygon->boundingBox();
248 return mSymbol.get();
@ VertexHandle
Node is a handle for manipulating vertices.
@ SupportsReferenceScale
Item supports reference scale based rendering.
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
@ Invalid
Operation has invalid parameters for the item, no change occurred.
@ Success
Item was modified successfully.
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
Abstract base class for annotation item edit operations.
@ DeleteNode
Delete a node.
@ TranslateItem
Translate (move) an item.
virtual Type type() const =0
Returns the operation type.
Encapsulates the context for an annotation item edit operation.
Annotation item edit operation consisting of adding a node.
QgsPoint point() const
Returns the node position (in layer coordinates).
Annotation item edit operation consisting of deleting a node.
QgsVertexId nodeId() const
Returns the deleted node ID.
Annotation item edit operation consisting of moving a node.
QgsPoint after() const
Returns the node position after the move occurred (in layer coordinates).
QgsVertexId nodeId() const
Returns the associated node ID.
Encapsulates the transient results of an in-progress annotation edit operation.
Annotation item edit operation consisting of translating (moving) an item.
double translationY() const
Returns the y-axis translation, in layer units.
double translationX() const
Returns the x-axis translation, in layer units.
Contains information about a node used for editing an annotation item.
virtual bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
virtual bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
Qgis::AnnotationItemEditOperationResult applyEditV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Applies an edit operation to the item.
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.
const QgsCurvePolygon * geometry() const
Returns the geometry of the item.
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...
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.
void setGeometry(QgsCurvePolygon *geometry)
Sets the geometry of the item.
Qgis::AnnotationItemFlags flags() const override
Returns item flags.
QgsAnnotationPolygonItem * clone() const override
Returns a clone of the item.
QList< QgsAnnotationItemNode > nodesV2(const QgsAnnotationItemEditContext &context) const override
Returns the nodes for the item, used for editing the item.
~QgsAnnotationPolygonItem() override
static QgsAnnotationPolygonItem * create()
Creates a new polygon annotation item.
QgsAnnotationPolygonItem(QgsCurvePolygon *polygon)
Constructor for QgsAnnotationPolygonItem, with the specified polygon geometry.
QgsAnnotationItemEditOperationTransientResults * transientEditResultsV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Retrieves the results of a transient (in progress) edit operation on the item.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
Abstract base class for curved geometry type.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual bool isClosed() const
Returns true if the curve is closed.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
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 Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
Point geometry type, with support for z-dimension and m-values.
A container for the context for various read/write operations on 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 std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Utility class for identifying a unique vertex within a geometry.