QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
38 return QStringLiteral(
"polygon" );
44 auto transformRing = [&context]( QPolygonF & pts )
60 pts.erase( std::remove_if( pts.begin(), pts.end(),
61 [](
const QPointF point )
63 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
66 QPointF *ptr = pts.data();
67 for (
int i = 0; i < pts.size(); ++i, ++ptr )
73 QPolygonF exterior = mPolygon->exteriorRing()->asQPolygonF();
74 transformRing( exterior );
75 QVector<QPolygonF> rings;
76 rings.reserve( mPolygon->numInteriorRings() );
77 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
79 QPolygonF ring = mPolygon->interiorRing( i )->asQPolygonF();
80 transformRing( ring );
84 mSymbol->startRender( context );
85 mSymbol->renderPolygon( exterior, rings.empty() ?
nullptr : &rings,
nullptr, context );
86 mSymbol->stopRender( context );
91 element.setAttribute( QStringLiteral(
"wkt" ), mPolygon->asWkt() );
100 QList< QgsAnnotationItemNode > res;
102 auto processRing = [&res](
const QgsCurve * ring,
int ringId )
106 res.reserve( res.size() + count );
107 for (
int i = 0; i < count; ++i )
113 if (
const QgsCurve *ring = mPolygon->exteriorRing() )
115 processRing( ring, 0 );
117 for (
int i = 0; i < mPolygon->numInteriorRings(); ++i )
119 processRing( mPolygon->interiorRing( i ), i + 1 );
127 switch ( operation->
type() )
140 if ( mPolygon->deleteVertex( deleteOperation->
nodeId() ) )
151 mPolygon->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
152 if ( mPolygon->insertVertex( endOfSegmentVertex, segmentPoint ) )
160 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
161 mPolygon->transform( transform );
171 switch ( operation->
type() )
176 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
177 if ( modifiedPolygon->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
187 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
188 std::unique_ptr< QgsCurvePolygon > modifiedPolygon( mPolygon->clone() );
189 modifiedPolygon->transform( transform );
207 const QString wkt = element.attribute( QStringLiteral(
"wkt" ) );
210 mPolygon.reset( polygon->clone() );
212 const QDomElement symbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
213 if ( !symbolElem.isNull() )
214 setSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElem, context ) );
222 std::unique_ptr< QgsAnnotationPolygonItem > item = std::make_unique< QgsAnnotationPolygonItem >( mPolygon->clone() );
223 item->setSymbol( mSymbol->clone() );
224 item->copyCommonProperties(
this );;
225 return item.release();
230 return mPolygon->boundingBox();
235 return mSymbol.get();
Abstract base class for curved geometry type.
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.
@ DeleteNode
Delete a node.
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.
Point geometry type, with support for z-dimension and m-values.
Annotation item edit operation consisting of translating (moving) an item.
Curve polygon geometry type.
Annotation item edit operation consisting of deleting a node.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsAnnotationItemEditOperationTransientResults * transientEditResults(QgsAbstractAnnotationItemEditOperation *operation) override
Retrieves the results of a transient (in progress) edit operation on the item.
virtual Type type() const =0
Returns the operation 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.
QgsPoint point() const
Returns the node position (in layer coordinates).
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsVertexId nodeId() const
Returns the associated node ID.
const QgsCurvePolygon * geometry() const
Returns the geometry of the item.
Custom exception class for Coordinate Reference System related exceptions.
@ TranslateItem
Translate (move) an item.
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.
bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
QList< QgsAnnotationItemNode > nodes() const override
Returns the nodes for the item, used for editing the item.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
QgsVertexId nodeId() const
Returns the deleted node ID.
Annotation item edit operation consisting of moving a node.
Abstract base class for annotation item edit operations.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
A class to represent a 2D point.
QgsPoint after() const
Returns the node position after the move occurred (in layer coordinates).
@ VertexHandle
Node is a handle for manipulating vertices.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
@ Success
Item was modified successfully.
Contains information about a node used for editing an annotation item.
A geometry is the spatial representation of a feature.
Utility class for identifying a unique vertex within a geometry.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void setSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the polygon item.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
Qgis::AnnotationItemEditOperationResult applyEdit(QgsAbstractAnnotationItemEditOperation *operation) override
Applies an edit operation to the item.
Annotation item edit operation consisting of adding a node.
double translationY() const
Returns the y-axis translation, in layer units.
double translationX() const
Returns the x-axis translation, in layer units.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
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.
Encapsulates the transient results of an in-progress annotation edit operation.
static QgsAnnotationPolygonItem * create()
Creates a new polygon annotation item.
@ Invalid
Operation has invalid parameters for the item, no change occurred.