31using namespace Qt::StringLiterals;
51 auto transformRing = [&context]( QPolygonF & pts )
67 pts.erase( std::remove_if( pts.begin(), pts.end(),
68 [](
const QPointF point )
70 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
73 QPointF *ptr = pts.data();
74 for (
int i = 0; i < pts.size(); ++i, ++ptr )
80 QPolygonF exterior = mPolygon->exteriorRing()->asQPolygonF();
81 transformRing( exterior );
82 QVector<QPolygonF> rings;
83 rings.reserve( mPolygon->numInteriorRings() );
84 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
86 QPolygonF ring = mPolygon->interiorRing( i )->asQPolygonF();
87 transformRing( ring );
91 mSymbol->startRender( context );
92 mSymbol->renderPolygon( exterior, rings.empty() ?
nullptr : &rings,
nullptr, context );
93 mSymbol->stopRender( context );
98 element.setAttribute( u
"wkt"_s, mPolygon->asWkt() );
107 QList< QgsAnnotationItemNode > res;
109 auto processRing = [&res](
const QgsCurve * ring,
int ringId )
113 res.reserve( res.size() + count );
114 for (
int i = 0; i < count; ++i )
120 if (
const QgsCurve *ring = mPolygon->exteriorRing() )
122 processRing( ring, 0 );
124 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
126 processRing( mPolygon->interiorRing( i ), i + 1 );
134 switch ( operation->
type() )
147 if ( mPolygon->deleteVertex( deleteOperation->
nodeId() ) )
158 mPolygon->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
159 if ( mPolygon->insertVertex( endOfSegmentVertex, segmentPoint ) )
167 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
168 mPolygon->transform( transform );
175 QgsPointXY center = mPolygon->boundingBox().center();
176 QTransform transform = QTransform::fromTranslate( center.
x(), center.
y() );
177 transform.rotate( -rotateOperation->
angle() );
178 transform.translate( -center.
x(), -center.
y() );
179 mPolygon->transform( transform );
189 switch ( operation->
type() )
194 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
195 if ( modifiedPolygon->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
205 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
206 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
207 modifiedPolygon->transform( transform );
214 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
215 QgsPointXY center = modifiedPolygon->boundingBox().center();
216 QTransform transform = QTransform::fromTranslate( center.
x(), center.
y() );
217 transform.rotate( -rotateOperation->
angle() );
218 transform.translate( -center.
x(), -center.
y() );
219 modifiedPolygon->transform( transform );
242 const QString wkt = element.attribute( u
"wkt"_s );
245 mPolygon.reset( polygon->clone() );
247 const QDomElement symbolElem = element.firstChildElement( u
"symbol"_s );
248 if ( !symbolElem.isNull() )
257 auto item = std::make_unique< QgsAnnotationPolygonItem >( mPolygon->clone() );
258 item->setSymbol( mSymbol->clone() );
259 item->copyCommonProperties(
this );;
260 return item.release();
265 return mPolygon->boundingBox();
275 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.
@ RotateItem
Rotate an item.
@ 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.
Annotation item edit operation consisting of rotating an item.
double angle() const
Returns the rotation angle value (in degrees clockwise).
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.