QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
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 = qgis::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();
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
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.
The class is used as a container of context for various read/write operations on other objects.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
Contains information about the context of a rendering operation.
QPointF toQPointF() const
Converts a point to a QPointF.
A rectangle specified with double values.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QgsAnnotationPointTextItem * clone() override
Returns a clone of the item.
~QgsAnnotationPointTextItem() override
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Container for all settings relating to text rendering.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the item's state into an XML element.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsAnnotationPointTextItem(const QString &text, QgsPointXY point)
Constructor for QgsAnnotationPointTextItem, containing the specified text at the specified point.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
A class to represent a 2D point.
void setAlignment(Qt::Alignment alignment)
Sets the text's alignment relative to the reference point().
static QgsAnnotationPointTextItem * create()
Creates a new text at point annotation item.
int zIndex() const
Returns the item's z index, which controls the order in which annotation items are rendered in the la...
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
QgsTextFormat format() const
Returns the text format used to render the text.
static HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
void render(QgsRenderContext &context, QgsFeedback *feedback) override
Renders the item to the specified render context.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void setZIndex(int index)
Sets the item's z index, which controls the order in which annotation items are rendered in the layer...
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Qt::Alignment alignment() const
Returns the text's alignment relative to the reference point().
An annotation item which renders a text string at a point location.