QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
20 #include <QDomDocument>
25 , mDocument( new QTextDocument( QString() ) )
27 mDocument->setUseDesignMetrics(
true );
34 c->setDocument( mDocument.get() );
40 return mDocument.get();
46 mDocument.reset( doc->clone() );
54 QPainter *painter = context.
painter();
62 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
63 context.
painter()->scale( scaleFactor, scaleFactor );
66 mDocument->setTextWidth( size.width() );
68 QRectF clipRect = QRectF( 0, 0, size.width(), size.height() );
69 if ( painter->hasClipping() )
74 clipRect = clipRect.intersected( painter->clipRegion().boundingRect() );
77 mDocument->drawContents( painter, clipRect );
82 QDomElement annotationElem = doc.createElement( QStringLiteral(
"TextAnnotationItem" ) );
85 annotationElem.setAttribute( QStringLiteral(
"document" ), mDocument->toHtml() );
87 _writeXml( annotationElem, doc, context );
88 elem.appendChild( annotationElem );
93 mDocument.reset(
new QTextDocument );
94 mDocument->setHtml( itemElem.attribute( QStringLiteral(
"document" ), QString() ) );
95 const QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
96 if ( !annotationElem.isNull() )
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QgsTextAnnotation(QObject *parent=nullptr)
Constructor for QgsTextAnnotation.
void renderAnnotation(QgsRenderContext &context, QSizeF size) const override
Renders the annotation's contents to a target /a context at the specified /a size.
void setDocument(const QTextDocument *doc)
Sets the text document which will be rendered within the annotation.
QgsTextAnnotation * clone() const override
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context) override
Restores the annotation's state from a DOM element.
Abstract base class for annotation items which are drawn over a map.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
Scoped object for saving and restoring a QPainter object's state.
void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes the annotation state to a DOM element.
const QTextDocument * document() const
Returns the text document which will be rendered within the annotation.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
An annotation item that displays formatted text from a QTextDocument document.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
QPainter * painter()
Returns the destination QPainter for the render operation.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.