33 return QStringLiteral(
"pointtext" );
41 double x = mPoint.
x();
42 double y = mPoint.
y();
54 mText.split(
'\n' ), context, mTextFormat );
61 element.setAttribute( QStringLiteral(
"text" ), mText );
62 element.setAttribute( QStringLiteral(
"zIndex" ),
zIndex() );
64 element.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
66 QDomElement textFormatElem = document.createElement( QStringLiteral(
"pointTextFormat" ) );
67 textFormatElem.appendChild( mTextFormat.
writeXml( document, context ) );
68 element.appendChild( textFormatElem );
80 const double x = element.attribute( QStringLiteral(
"x" ) ).toDouble();
81 const double y = element.attribute( QStringLiteral(
"y" ) ).toDouble();
83 mText = element.attribute( QStringLiteral(
"text" ) );
84 mAngle = element.attribute( QStringLiteral(
"angle" ) ).toDouble();
85 mAlignment =
static_cast< Qt::Alignment
>( element.attribute( QStringLiteral(
"alignment" ) ).toInt() );
86 setZIndex( element.attribute( QStringLiteral(
"zIndex" ) ).toInt() );
88 const QDomElement textFormatElem = element.firstChildElement( QStringLiteral(
"pointTextFormat" ) );
89 if ( !textFormatElem.isNull() )
91 QDomNodeList textFormatNodeList = textFormatElem.elementsByTagName( QStringLiteral(
"text-style" ) );
92 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
93 mTextFormat.
readXml( textFormatElem, context );
101 std::unique_ptr< QgsAnnotationPointTextItem > item = std::make_unique< QgsAnnotationPointTextItem >( mText, mPoint );
102 item->setFormat( mTextFormat );
103 item->setAngle( mAngle );
104 item->setAlignment( mAlignment );
105 item->setZIndex(
zIndex() );
106 return item.release();
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
void setZIndex(int index)
Sets the item's z index, which controls the order in which annotation items are rendered in the layer...
int zIndex() const
Returns the item's z index, which controls the order in which annotation items are rendered in the la...
An annotation item which renders a text string at a point location.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
QgsTextFormat format() const
Returns the text format used to render the text.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
~QgsAnnotationPointTextItem() override
Qt::Alignment alignment() const
Returns the text's alignment relative to the reference point().
void setAlignment(Qt::Alignment alignment)
Sets the text's alignment relative to the reference point().
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
QgsAnnotationPointTextItem * clone() override
Returns a clone of the item.
static QgsAnnotationPointTextItem * create()
Creates a new text at point annotation item.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
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.
QgsAnnotationPointTextItem(const QString &text, QgsPointXY point)
Constructor for QgsAnnotationPointTextItem, containing the specified text at the specified point.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
A class to represent a 2D point.
QPointF toQPointF() const
Converts a point to a QPointF.
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.
Container for all settings relating to text rendering.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
static HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop)
Draws text within a rectangle using the specified settings.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.