Skip to content

Commit

Permalink
[api] Add text-along-line annotation item type
Browse files Browse the repository at this point in the history
This annotation item renders curved text along a linestring
  • Loading branch information
nyalldawson committed Mar 31, 2023
1 parent b9c0fc4 commit cd3a1bf
Show file tree
Hide file tree
Showing 19 changed files with 810 additions and 7 deletions.
Expand Up @@ -38,6 +38,10 @@ Abstract base class for annotation items which are drawn with :py:class:`QgsAnno
{
sipType = sipType_QgsAnnotationPointTextItem;
}
else if ( sipCpp->type() == QLatin1String( "linetext" ) )
{
sipType = sipType_QgsAnnotationLineTextItem;
}
else
{
sipType = 0;
Expand Down
Expand Up @@ -25,7 +25,7 @@ An annotation item which renders a line symbol along a line geometry.

QgsAnnotationLineItem( QgsCurve *curve /Transfer/ );
%Docstring
Constructor for QgsAnnotationLineItem, with the specified ``linestring``.
Constructor for QgsAnnotationLineItem, with the specified ``curve``.
%End
~QgsAnnotationLineItem();

Expand Down
@@ -0,0 +1,118 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/annotations/qgsannotationlinetextitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsAnnotationLineTextItem : QgsAnnotationItem
{
%Docstring(signature="appended")
An annotation item which renders text along a line geometry.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgsannotationlinetextitem.h"
%End
public:

QgsAnnotationLineTextItem( const QString &text, QgsCurve *curve /Transfer/ );
%Docstring
Constructor for QgsAnnotationLineTextItem, with the specified ``curve`` and ``text``.
%End
~QgsAnnotationLineTextItem();

virtual Qgis::AnnotationItemFlags flags() const;

virtual QString type() const;

virtual void render( QgsRenderContext &context, QgsFeedback *feedback );

virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;

virtual QList< QgsAnnotationItemNode > nodes() const;

virtual Qgis::AnnotationItemEditOperationResult applyEdit( QgsAbstractAnnotationItemEditOperation *operation );

virtual QgsAnnotationItemEditOperationTransientResults *transientEditResults( QgsAbstractAnnotationItemEditOperation *operation ) /Factory/;


static QgsAnnotationLineTextItem *create() /Factory/;
%Docstring
Creates a new linestring annotation item.
%End

virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );

virtual QgsRectangle boundingBox() const;

virtual QgsRectangle boundingBox( QgsRenderContext &context ) const;


virtual QgsAnnotationLineTextItem *clone() /Factory/;


const QgsCurve *geometry() const;
%Docstring
Returns the geometry of the item.

The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`setGeometry`
%End

void setGeometry( QgsCurve *geometry /Transfer/ );
%Docstring
Sets the ``geometry`` of the item. Ownership of ``geometry`` is transferred.

The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`geometry`
%End

QString text() const;
%Docstring
Returns the text rendered by the item.

.. seealso:: :py:func:`setText`
%End

void setText( const QString &text );
%Docstring
Sets the ``text`` rendered by the item.

.. seealso:: :py:func:`text`
%End

QgsTextFormat format() const;
%Docstring
Returns the text format used to render the text.

.. seealso:: :py:func:`setFormat`
%End

void setFormat( const QgsTextFormat &format );
%Docstring
Sets the text ``format`` used to render the text.

.. seealso:: :py:func:`format`
%End

private:
QgsAnnotationLineTextItem( const QgsAnnotationLineTextItem &other );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/annotations/qgsannotationlinetextitem.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -227,6 +227,7 @@
%Include auto_generated/annotations/qgsannotationitemregistry.sip
%Include auto_generated/annotations/qgsannotationlayer.sip
%Include auto_generated/annotations/qgsannotationlineitem.sip
%Include auto_generated/annotations/qgsannotationlinetextitem.sip
%Include auto_generated/annotations/qgsannotationmarkeritem.sip
%Include auto_generated/annotations/qgsannotationmanager.sip
%Include auto_generated/annotations/qgsannotationpointtextitem.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -207,6 +207,7 @@ set(QGIS_CORE_SRCS
annotations/qgsannotationlayer.cpp
annotations/qgsannotationlayerrenderer.cpp
annotations/qgsannotationlineitem.cpp
annotations/qgsannotationlinetextitem.cpp
annotations/qgsannotationmarkeritem.cpp
annotations/qgsannotationmanager.cpp
annotations/qgsannotationpointtextitem.cpp
Expand Down Expand Up @@ -1269,6 +1270,7 @@ set(QGIS_CORE_HDRS
annotations/qgsannotationlayer.h
annotations/qgsannotationlayerrenderer.h
annotations/qgsannotationlineitem.h
annotations/qgsannotationlinetextitem.h
annotations/qgsannotationmarkeritem.h
annotations/qgsannotationmanager.h
annotations/qgsannotationpointtextitem.h
Expand Down
6 changes: 4 additions & 2 deletions src/core/annotations/qgsannotationitem.h
Expand Up @@ -20,8 +20,6 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgscoordinatereferencesystem.h"
#include "qgslinestring.h"
#include "qgspolygon.h"

class QgsFeedback;
class QgsMarkerSymbol;
Expand Down Expand Up @@ -60,6 +58,10 @@ class CORE_EXPORT QgsAnnotationItem
{
sipType = sipType_QgsAnnotationPointTextItem;
}
else if ( sipCpp->type() == QLatin1String( "linetext" ) )
{
sipType = sipType_QgsAnnotationLineTextItem;
}
else
{
sipType = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/core/annotations/qgsannotationitemregistry.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsannotationlineitem.h"
#include "qgsannotationpolygonitem.h"
#include "qgsannotationpointtextitem.h"
#include "qgsannotationlinetextitem.h"
#include <QDomElement>

QgsAnnotationItemRegistry::QgsAnnotationItemRegistry( QObject *parent )
Expand All @@ -45,6 +46,8 @@ bool QgsAnnotationItemRegistry::populate()
QgsAnnotationPolygonItem::create ) );
mMetadata.insert( QStringLiteral( "pointtext" ), new QgsAnnotationItemMetadata( QStringLiteral( "pointtext" ), QObject::tr( "Text at point" ), QObject::tr( "Text at points" ),
QgsAnnotationPointTextItem::create ) );
mMetadata.insert( QStringLiteral( "linetext" ), new QgsAnnotationItemMetadata( QStringLiteral( "linetext" ), QObject::tr( "Text along line" ), QObject::tr( "Text along lines" ),
QgsAnnotationLineTextItem::create ) );
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/annotations/qgsannotationlineitem.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgslinesymbol.h"
#include "qgsannotationitemnode.h"
#include "qgsannotationitemeditoperation.h"
#include "qgscurve.h"
#include "qgslinestring.h"

QgsAnnotationLineItem::QgsAnnotationLineItem( QgsCurve *curve )
: QgsAnnotationItem()
Expand Down Expand Up @@ -201,6 +203,8 @@ QgsAnnotationLineItem *QgsAnnotationLineItem::clone()
return item.release();
}

void QgsAnnotationLineItem::setGeometry( QgsCurve *geometry ) { mCurve.reset( geometry ); }

const QgsLineSymbol *QgsAnnotationLineItem::symbol() const
{
return mSymbol.get();
Expand Down
4 changes: 2 additions & 2 deletions src/core/annotations/qgsannotationlineitem.h
Expand Up @@ -35,7 +35,7 @@ class CORE_EXPORT QgsAnnotationLineItem : public QgsAnnotationItem
public:

/**
* Constructor for QgsAnnotationLineItem, with the specified \a linestring.
* Constructor for QgsAnnotationLineItem, with the specified \a curve.
*/
QgsAnnotationLineItem( QgsCurve *curve SIP_TRANSFER );
~QgsAnnotationLineItem() override;
Expand Down Expand Up @@ -73,7 +73,7 @@ class CORE_EXPORT QgsAnnotationLineItem : public QgsAnnotationItem
*
* \see geometry()
*/
void setGeometry( QgsCurve *geometry SIP_TRANSFER ) { mCurve.reset( geometry ); }
void setGeometry( QgsCurve *geometry SIP_TRANSFER );

/**
* Returns the symbol used to render the item.
Expand Down

0 comments on commit cd3a1bf

Please sign in to comment.