Skip to content

Commit cd3a1bf

Browse files
committedMar 31, 2023
[api] Add text-along-line annotation item type
This annotation item renders curved text along a linestring
1 parent b9c0fc4 commit cd3a1bf

19 files changed

+810
-7
lines changed
 

‎python/core/auto_generated/annotations/qgsannotationitem.sip.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Abstract base class for annotation items which are drawn with :py:class:`QgsAnno
3838
{
3939
sipType = sipType_QgsAnnotationPointTextItem;
4040
}
41+
else if ( sipCpp->type() == QLatin1String( "linetext" ) )
42+
{
43+
sipType = sipType_QgsAnnotationLineTextItem;
44+
}
4145
else
4246
{
4347
sipType = 0;

‎python/core/auto_generated/annotations/qgsannotationlineitem.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ An annotation item which renders a line symbol along a line geometry.
2525

2626
QgsAnnotationLineItem( QgsCurve *curve /Transfer/ );
2727
%Docstring
28-
Constructor for QgsAnnotationLineItem, with the specified ``linestring``.
28+
Constructor for QgsAnnotationLineItem, with the specified ``curve``.
2929
%End
3030
~QgsAnnotationLineItem();
3131

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/annotations/qgsannotationlinetextitem.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsAnnotationLineTextItem : QgsAnnotationItem
14+
{
15+
%Docstring(signature="appended")
16+
An annotation item which renders text along a line geometry.
17+
18+
.. versionadded:: 3.32
19+
%End
20+
21+
%TypeHeaderCode
22+
#include "qgsannotationlinetextitem.h"
23+
%End
24+
public:
25+
26+
QgsAnnotationLineTextItem( const QString &text, QgsCurve *curve /Transfer/ );
27+
%Docstring
28+
Constructor for QgsAnnotationLineTextItem, with the specified ``curve`` and ``text``.
29+
%End
30+
~QgsAnnotationLineTextItem();
31+
32+
virtual Qgis::AnnotationItemFlags flags() const;
33+
34+
virtual QString type() const;
35+
36+
virtual void render( QgsRenderContext &context, QgsFeedback *feedback );
37+
38+
virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
39+
40+
virtual QList< QgsAnnotationItemNode > nodes() const;
41+
42+
virtual Qgis::AnnotationItemEditOperationResult applyEdit( QgsAbstractAnnotationItemEditOperation *operation );
43+
44+
virtual QgsAnnotationItemEditOperationTransientResults *transientEditResults( QgsAbstractAnnotationItemEditOperation *operation ) /Factory/;
45+
46+
47+
static QgsAnnotationLineTextItem *create() /Factory/;
48+
%Docstring
49+
Creates a new linestring annotation item.
50+
%End
51+
52+
virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
53+
54+
virtual QgsRectangle boundingBox() const;
55+
56+
virtual QgsRectangle boundingBox( QgsRenderContext &context ) const;
57+
58+
59+
virtual QgsAnnotationLineTextItem *clone() /Factory/;
60+
61+
62+
const QgsCurve *geometry() const;
63+
%Docstring
64+
Returns the geometry of the item.
65+
66+
The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.
67+
68+
.. seealso:: :py:func:`setGeometry`
69+
%End
70+
71+
void setGeometry( QgsCurve *geometry /Transfer/ );
72+
%Docstring
73+
Sets the ``geometry`` of the item. Ownership of ``geometry`` is transferred.
74+
75+
The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.
76+
77+
.. seealso:: :py:func:`geometry`
78+
%End
79+
80+
QString text() const;
81+
%Docstring
82+
Returns the text rendered by the item.
83+
84+
.. seealso:: :py:func:`setText`
85+
%End
86+
87+
void setText( const QString &text );
88+
%Docstring
89+
Sets the ``text`` rendered by the item.
90+
91+
.. seealso:: :py:func:`text`
92+
%End
93+
94+
QgsTextFormat format() const;
95+
%Docstring
96+
Returns the text format used to render the text.
97+
98+
.. seealso:: :py:func:`setFormat`
99+
%End
100+
101+
void setFormat( const QgsTextFormat &format );
102+
%Docstring
103+
Sets the text ``format`` used to render the text.
104+
105+
.. seealso:: :py:func:`format`
106+
%End
107+
108+
private:
109+
QgsAnnotationLineTextItem( const QgsAnnotationLineTextItem &other );
110+
};
111+
112+
/************************************************************************
113+
* This file has been generated automatically from *
114+
* *
115+
* src/core/annotations/qgsannotationlinetextitem.h *
116+
* *
117+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
118+
************************************************************************/

‎python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
%Include auto_generated/annotations/qgsannotationitemregistry.sip
228228
%Include auto_generated/annotations/qgsannotationlayer.sip
229229
%Include auto_generated/annotations/qgsannotationlineitem.sip
230+
%Include auto_generated/annotations/qgsannotationlinetextitem.sip
230231
%Include auto_generated/annotations/qgsannotationmarkeritem.sip
231232
%Include auto_generated/annotations/qgsannotationmanager.sip
232233
%Include auto_generated/annotations/qgsannotationpointtextitem.sip

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ set(QGIS_CORE_SRCS
207207
annotations/qgsannotationlayer.cpp
208208
annotations/qgsannotationlayerrenderer.cpp
209209
annotations/qgsannotationlineitem.cpp
210+
annotations/qgsannotationlinetextitem.cpp
210211
annotations/qgsannotationmarkeritem.cpp
211212
annotations/qgsannotationmanager.cpp
212213
annotations/qgsannotationpointtextitem.cpp
@@ -1269,6 +1270,7 @@ set(QGIS_CORE_HDRS
12691270
annotations/qgsannotationlayer.h
12701271
annotations/qgsannotationlayerrenderer.h
12711272
annotations/qgsannotationlineitem.h
1273+
annotations/qgsannotationlinetextitem.h
12721274
annotations/qgsannotationmarkeritem.h
12731275
annotations/qgsannotationmanager.h
12741276
annotations/qgsannotationpointtextitem.h

‎src/core/annotations/qgsannotationitem.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "qgis_core.h"
2121
#include "qgis_sip.h"
2222
#include "qgscoordinatereferencesystem.h"
23-
#include "qgslinestring.h"
24-
#include "qgspolygon.h"
2523

2624
class QgsFeedback;
2725
class QgsMarkerSymbol;
@@ -60,6 +58,10 @@ class CORE_EXPORT QgsAnnotationItem
6058
{
6159
sipType = sipType_QgsAnnotationPointTextItem;
6260
}
61+
else if ( sipCpp->type() == QLatin1String( "linetext" ) )
62+
{
63+
sipType = sipType_QgsAnnotationLineTextItem;
64+
}
6365
else
6466
{
6567
sipType = 0;

‎src/core/annotations/qgsannotationitemregistry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsannotationlineitem.h"
2121
#include "qgsannotationpolygonitem.h"
2222
#include "qgsannotationpointtextitem.h"
23+
#include "qgsannotationlinetextitem.h"
2324
#include <QDomElement>
2425

2526
QgsAnnotationItemRegistry::QgsAnnotationItemRegistry( QObject *parent )
@@ -45,6 +46,8 @@ bool QgsAnnotationItemRegistry::populate()
4546
QgsAnnotationPolygonItem::create ) );
4647
mMetadata.insert( QStringLiteral( "pointtext" ), new QgsAnnotationItemMetadata( QStringLiteral( "pointtext" ), QObject::tr( "Text at point" ), QObject::tr( "Text at points" ),
4748
QgsAnnotationPointTextItem::create ) );
49+
mMetadata.insert( QStringLiteral( "linetext" ), new QgsAnnotationItemMetadata( QStringLiteral( "linetext" ), QObject::tr( "Text along line" ), QObject::tr( "Text along lines" ),
50+
QgsAnnotationLineTextItem::create ) );
4851
return true;
4952
}
5053

‎src/core/annotations/qgsannotationlineitem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgslinesymbol.h"
2222
#include "qgsannotationitemnode.h"
2323
#include "qgsannotationitemeditoperation.h"
24+
#include "qgscurve.h"
25+
#include "qgslinestring.h"
2426

2527
QgsAnnotationLineItem::QgsAnnotationLineItem( QgsCurve *curve )
2628
: QgsAnnotationItem()
@@ -201,6 +203,8 @@ QgsAnnotationLineItem *QgsAnnotationLineItem::clone()
201203
return item.release();
202204
}
203205

206+
void QgsAnnotationLineItem::setGeometry( QgsCurve *geometry ) { mCurve.reset( geometry ); }
207+
204208
const QgsLineSymbol *QgsAnnotationLineItem::symbol() const
205209
{
206210
return mSymbol.get();

‎src/core/annotations/qgsannotationlineitem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CORE_EXPORT QgsAnnotationLineItem : public QgsAnnotationItem
3535
public:
3636

3737
/**
38-
* Constructor for QgsAnnotationLineItem, with the specified \a linestring.
38+
* Constructor for QgsAnnotationLineItem, with the specified \a curve.
3939
*/
4040
QgsAnnotationLineItem( QgsCurve *curve SIP_TRANSFER );
4141
~QgsAnnotationLineItem() override;
@@ -73,7 +73,7 @@ class CORE_EXPORT QgsAnnotationLineItem : public QgsAnnotationItem
7373
*
7474
* \see geometry()
7575
*/
76-
void setGeometry( QgsCurve *geometry SIP_TRANSFER ) { mCurve.reset( geometry ); }
76+
void setGeometry( QgsCurve *geometry SIP_TRANSFER );
7777

7878
/**
7979
* Returns the symbol used to render the item.

0 commit comments

Comments
 (0)