39 return QStringLiteral(
"linestring" );
44 QPolygonF pts = mCurve->asQPolygonF();
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 )
72 mSymbol->startRender( context );
73 mSymbol->renderPolyline( pts,
nullptr, context );
74 mSymbol->stopRender( context );
79 element.setAttribute( QStringLiteral(
"wkt" ), mCurve->asWkt() );
88 QList< QgsAnnotationItemNode > res;
90 for (
auto it = mCurve->vertices_begin(); it != mCurve->vertices_end(); ++it, ++i )
99 switch ( operation->
type() )
112 if ( mCurve->deleteVertex( deleteOperation->
nodeId() ) )
123 mCurve->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
124 if ( mCurve->insertVertex( endOfSegmentVertex, segmentPoint ) )
132 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
133 mCurve->transform( transform );
143 switch ( operation->
type() )
148 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
149 if ( modifiedCurve->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
159 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
160 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
161 modifiedCurve->transform( transform );
179 const QString wkt = element.attribute( QStringLiteral(
"wkt" ) );
181 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >(
geometry.constGet() ) )
182 mCurve.reset( curve->clone() );
184 const QDomElement symbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
185 if ( !symbolElem.isNull() )
186 setSymbol( QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( symbolElem, context ) );
195 return mCurve->boundingBox();
200 std::unique_ptr< QgsAnnotationLineItem > item = std::make_unique< QgsAnnotationLineItem >( mCurve->clone() );
201 item->setSymbol( mSymbol->clone() );
202 item->copyCommonProperties(
this );
203 return item.release();
210 return mSymbol.get();
@ VertexHandle
Node is a handle for manipulating vertices.
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...
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.
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.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
An annotation item which renders a line symbol along a line geometry.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
~QgsAnnotationLineItem() override
QgsAnnotationLineItem(QgsCurve *curve)
Constructor for QgsAnnotationLineItem, with the specified curve.
void setSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the marker item.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
void setGeometry(QgsCurve *geometry)
Sets the geometry of the item.
QgsAnnotationItemEditOperationTransientResults * transientEditResults(QgsAbstractAnnotationItemEditOperation *operation) override
Retrieves the results of a transient (in progress) edit operation on the item.
QList< QgsAnnotationItemNode > nodes() const override
Returns the nodes for the item, used for editing the item.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
Qgis::AnnotationItemEditOperationResult applyEdit(QgsAbstractAnnotationItemEditOperation *operation) override
Applies an edit operation to the item.
const QgsCurve * geometry() const
Returns the geometry of the item.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the item's state into an XML element.
void render(QgsRenderContext &context, QgsFeedback *feedback) override
Renders the item to the specified render context.
const QgsLineSymbol * symbol() const
Returns the symbol used to render the item.
QgsAnnotationLineItem * clone() override
Returns a clone of the item.
static QgsAnnotationLineItem * create()
Creates a new linestring annotation item.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A geometry is the spatial representation of a feature.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
Line string geometry type, with support for z-dimension and m-values.
A line symbol type, for rendering LineString and MultiLineString geometries.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
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.
Utility class for identifying a unique vertex within a geometry.