QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
42 return QStringLiteral(
"pointtext" );
50 double x = mPoint.
x();
51 double y = mPoint.
y();
64 displayText.split(
'\n' ), context, mTextFormat );
71 element.setAttribute( QStringLiteral(
"text" ), mText );
73 element.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
75 QDomElement textFormatElem = document.createElement( QStringLiteral(
"pointTextFormat" ) );
76 textFormatElem.appendChild( mTextFormat.
writeXml( document, context ) );
77 element.appendChild( textFormatElem );
90 const double x = element.attribute( QStringLiteral(
"x" ) ).toDouble();
91 const double y = element.attribute( QStringLiteral(
"y" ) ).toDouble();
93 mText = element.attribute( QStringLiteral(
"text" ) );
94 mAngle = element.attribute( QStringLiteral(
"angle" ) ).toDouble();
95 mAlignment =
static_cast< Qt::Alignment
>( element.attribute( QStringLiteral(
"alignment" ) ).toInt() );
97 const QDomElement textFormatElem = element.firstChildElement( QStringLiteral(
"pointTextFormat" ) );
98 if ( !textFormatElem.isNull() )
100 const QDomNodeList textFormatNodeList = textFormatElem.elementsByTagName( QStringLiteral(
"text-style" ) );
101 const QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
102 mTextFormat.
readXml( textFormatElem, context );
111 std::unique_ptr< QgsAnnotationPointTextItem > item = std::make_unique< QgsAnnotationPointTextItem >( mText, mPoint );
112 item->setFormat( mTextFormat );
113 item->setAngle( mAngle );
114 item->setAlignment( mAlignment );
115 item->copyCommonProperties(
this );
116 return item.release();
137 return QgsRectangle( mPoint.
x(), mPoint.
y(), mPoint.
x() + widthInMapUnits, mPoint.
y() + heightInMapUnits );
147 switch ( operation->
type() )
152 mPoint = moveOperation->
after();
178 switch ( operation->
type() )
Scoped object for temporary override of the symbologyReferenceScale property of a QgsRenderContext.
@ DeleteNode
Delete a node.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsExpressionContext & expressionContext()
Gets the expression context.
The class is used as a container of context for various read/write operations on other objects.
Qgis::AnnotationItemFlags flags() const override
Returns item flags.
Point geometry type, with support for z-dimension and m-values.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
Annotation item edit operation consisting of translating (moving) an item.
virtual Type type() const =0
Returns the operation type.
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
Contains information about the context of a rendering operation.
QPointF toQPointF() const
Converts a point to a QPointF.
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
A rectangle specified with double values.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
QgsAnnotationPointTextItem * clone() override
Returns a clone of the item.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
~QgsAnnotationPointTextItem() override
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
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.
@ TranslateItem
Translate (move) an item.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags())
Draws text within a rectangle using the specified settings.
bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Annotation item edit operation consisting of moving a node.
QgsAnnotationPointTextItem(const QString &text, QgsPointXY point)
Constructor for QgsAnnotationPointTextItem, containing the specified text at the specified point.
Abstract base class for annotation item edit operations.
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.
QgsPoint after() const
Returns the node position after the move occurred (in layer coordinates).
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.
@ VertexHandle
Node is a handle for manipulating vertices.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
QgsAnnotationItemEditOperationTransientResults * transientEditResults(QgsAbstractAnnotationItemEditOperation *operation) override
Retrieves the results of a transient (in progress) edit operation on the item.
@ Success
Item was modified successfully.
Contains information about a node used for editing an annotation item.
A geometry is the spatial representation of a feature.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
Utility class for identifying a unique vertex within a geometry.
QgsTextFormat format() const
Returns the text format used to render the text.
Qgis::AnnotationItemEditOperationResult applyEdit(QgsAbstractAnnotationItemEditOperation *operation) override
Applies an edit operation to the item.
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
QList< QgsAnnotationItemNode > nodes() const override
Returns the nodes for the item, used for editing the item.
static HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
double translationY() const
Returns the y-axis translation, in layer units.
double translationX() const
Returns the x-axis translation, in layer units.
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...
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.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Encapsulates the transient results of an in-progress annotation edit operation.
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.
@ Invalid
Operation has invalid parameters for the item, no change occurred.