31using namespace Qt::StringLiterals;
59 smoothed = smoothed.
smooth( );
77 pts.erase( std::remove_if( pts.begin(), pts.end(),
78 [](
const QPointF point )
80 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
83 QPointF *ptr = pts.data();
84 for (
int i = 0; i < pts.size(); ++i, ++ptr )
98 element.setAttribute( u
"wkt"_s, mCurve->asWkt() );
99 element.setAttribute( u
"text"_s, mText );
101 element.setAttribute( u
"offsetFromLine"_s,
qgsDoubleToString( mOffsetFromLineDistance ) );
105 QDomElement textFormatElem = document.createElement( u
"lineTextFormat"_s );
106 textFormatElem.appendChild( mTextFormat.writeXml( document, context ) );
107 element.appendChild( textFormatElem );
116 QList< QgsAnnotationItemNode > res;
118 for (
auto it = mCurve->vertices_begin(); it != mCurve->vertices_end(); ++it, ++i )
127 switch ( operation->
type() )
140 if ( mCurve->deleteVertex( deleteOperation->
nodeId() ) )
151 mCurve->closestSegment( addOperation->
point(), segmentPoint, endOfSegmentVertex );
152 if ( mCurve->insertVertex( endOfSegmentVertex, segmentPoint ) )
160 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
161 mCurve->transform( transform );
168 QgsPointXY center = mCurve->boundingBox().center();
169 QTransform transform = QTransform::fromTranslate( center.
x(), center.
y() );
170 transform.rotate( -rotateOperation->
angle() );
171 transform.translate( -center.
x(), -center.
y() );
172 mCurve->transform( transform );
182 switch ( operation->
type() )
187 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
188 if ( modifiedCurve->moveVertex( moveOperation->
nodeId(),
QgsPoint( moveOperation->
after() ) ) )
198 const QTransform transform = QTransform::fromTranslate( moveOperation->
translationX(), moveOperation->
translationY() );
199 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
200 modifiedCurve->transform( transform );
207 std::unique_ptr< QgsCurve > modifiedCurve( mCurve->clone() );
208 QgsPointXY center = modifiedCurve->boundingBox().center();
209 QTransform transform = QTransform::fromTranslate( center.
x(), center.
y() );
210 transform.rotate( -rotateOperation->
angle() );
211 transform.translate( -center.
x(), -center.
y() );
212 modifiedCurve->transform( transform );
230 const QString wkt = element.attribute( u
"wkt"_s );
233 mCurve.reset( curve->clone() );
235 mText = element.attribute( u
"text"_s );
236 const QDomElement textFormatElem = element.firstChildElement( u
"lineTextFormat"_s );
237 if ( !textFormatElem.isNull() )
239 const QDomNodeList textFormatNodeList = textFormatElem.elementsByTagName( u
"text-style"_s );
240 const QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
241 mTextFormat.readXml( textFormatElem, context );
244 mOffsetFromLineDistance = element.attribute( u
"offsetFromLine"_s ).toDouble();
259 return mCurve->boundingBox();
266 const double lineOffsetInMapUnits = std::fabs( context.
convertToMapUnits( mOffsetFromLineDistance, mOffsetFromLineUnit, mOffsetFromLineScale ) );
275 return mCurve->boundingBox().buffered( heightInMapUnits + lineOffsetInMapUnits );
280 auto item = std::make_unique< QgsAnnotationLineTextItem >( mText, mCurve->clone() );
281 item->setFormat( mTextFormat );
282 item->setOffsetFromLine( mOffsetFromLineDistance );
283 item->setOffsetFromLineUnit( mOffsetFromLineUnit );
284 item->setOffsetFromLineMapUnitScale( mOffsetFromLineScale );
285 item->copyCommonProperties(
this );
286 return item.release();
@ VertexHandle
Node is a handle for manipulating vertices.
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
@ 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.
@ Millimeters
Millimeters.
@ ExtendLineToFitText
When a string is too long for the line, extend the line's final segment to fit the entire string.
@ UseBaselinePlacement
Generate placement based on the character baselines instead of centers.
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.
double offsetFromLine() const
Returns the offset distance from the line geometry() to the text's baseline.
void setGeometry(QgsCurve *geometry)
Sets the geometry of the item.
void render(QgsRenderContext &context, QgsFeedback *feedback) override
Renders the item to the specified render context.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
const QgsCurve * geometry() const
Returns the geometry of the item.
QgsAnnotationItemEditOperationTransientResults * transientEditResultsV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Retrieves the results of a transient (in progress) edit operation on the item.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
static QgsAnnotationLineTextItem * create()
Creates a new linestring annotation item.
QgsAnnotationLineTextItem * 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.
QgsAnnotationLineTextItem(const QString &text, QgsCurve *curve)
Constructor for QgsAnnotationLineTextItem, with the specified curve and text.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the item's state into an XML element.
QString text() const
Returns the text rendered by the item.
~QgsAnnotationLineTextItem() override
Qgis::AnnotationItemFlags flags() const override
Returns item flags.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
Qgis::AnnotationItemEditOperationResult applyEditV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Applies an edit operation to the item.
QgsTextFormat format() const
Returns the text format used to render the text.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...
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.
QPolygonF asQPolygonF() const
Returns contents of the geometry as a QPolygonF.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QgsGeometry smooth(unsigned int iterations=1, double offset=0.25, double minimumDistance=-1.0, double maxAngle=180.0) const
Smooths a geometry by rounding off corners using the Chaikin algorithm.
Line string geometry type, with support for z-dimension and m-values.
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.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
QgsExpressionContext & expressionContext()
Gets the expression context.
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.
Scoped object for temporary override of the symbologyReferenceScale property of a QgsRenderContext.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Container for all settings relating to text rendering.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
static void drawTextOnLine(const QPolygonF &line, const QString &text, QgsRenderContext &context, const QgsTextFormat &format, double offsetAlongLine=0, double offsetFromLine=0, Qgis::CurvedTextFlags flags=Qgis::CurvedTextFlag::UseBaselinePlacement|Qgis::CurvedTextFlag::TruncateStringWhenLineIsTooShort)
Draws text along a line using the specified settings.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Utility class for identifying a unique vertex within a geometry.