37 return QStringLiteral(
"linestring" );
42 QPolygonF pts = mCurve->asQPolygonF();
58 pts.erase( std::remove_if( pts.begin(), pts.end(),
59 [](
const QPointF point )
61 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
64 QPointF *ptr = pts.data();
65 for (
int i = 0; i < pts.size(); ++i, ++ptr )
70 mSymbol->startRender( context );
71 mSymbol->renderPolyline( pts,
nullptr, context );
72 mSymbol->stopRender( context );
77 element.setAttribute( QStringLiteral(
"wkt" ), mCurve->asWkt() );
86 QList< QgsAnnotationItemNode > res;
88 for (
auto it = mCurve->vertices_begin(); it != mCurve->vertices_end(); ++it, ++i )
97 switch ( operation->
type() )
110 if ( mCurve->deleteVertex( deleteOperation->
nodeId() ) )
121 mCurve->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
122 if ( mCurve->insertVertex( endOfSegmentVertex, segmentPoint ) )
130 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
131 mCurve->transform( transform );
141 switch ( operation->
type() )
146 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
147 if ( modifiedCurve->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
157 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
158 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
159 modifiedCurve->transform( transform );
177 const QString wkt = element.attribute( QStringLiteral(
"wkt" ) );
179 if (
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >(
geometry.constGet() ) )
180 mCurve.reset( curve->clone() );
182 const QDomElement symbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
183 if ( !symbolElem.isNull() )
184 setSymbol( QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( symbolElem, context ) );
193 return mCurve->boundingBox();
198 std::unique_ptr< QgsAnnotationLineItem > item = std::make_unique< QgsAnnotationLineItem >( mCurve->clone() );
199 item->setSymbol( mSymbol->clone() );
200 item->copyCommonProperties(
this );
201 return item.release();
206 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 linestring.
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.
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.