19 #include <QDomDocument> 24 , mDocument( new QTextDocument( QString() ) )
26 mDocument->setUseDesignMetrics(
true );
33 c->setDocument( mDocument.get() );
39 return mDocument.get();
45 mDocument.reset( doc->clone() );
53 QPainter *painter = context.
painter();
59 mDocument->setTextWidth( size.width() );
61 QRectF clipRect = QRectF( 0, 0, size.width(), size.height() );
62 if ( painter->hasClipping() )
67 clipRect = clipRect.intersected( painter->clipRegion().boundingRect() );
70 mDocument->drawContents( painter, clipRect );
75 QDomElement annotationElem = doc.createElement( QStringLiteral(
"TextAnnotationItem" ) );
78 annotationElem.setAttribute( QStringLiteral(
"document" ), mDocument->toHtml() );
80 _writeXml( annotationElem, doc, context );
81 elem.appendChild( annotationElem );
86 mDocument.reset(
new QTextDocument );
87 mDocument->setHtml( itemElem.attribute( QStringLiteral(
"document" ), QString() ) );
88 QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
89 if ( !annotationElem.isNull() )
The class is used as a container of context for various read/write operations on other objects...
An annotation item that displays formatted text from a QTextDocument document.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
QgsTextAnnotation * clone() const override
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
QgsTextAnnotation(QObject *parent=nullptr)
Constructor for QgsTextAnnotation.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
Abstract base class for annotation items which are drawn over a map.
void renderAnnotation(QgsRenderContext &context, QSizeF size) const override
Renders the annotation's contents to a target /a context at the specified /a size.
void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes the annotation state to a DOM element.
void setDocument(const QTextDocument *doc)
Sets the text document which will be rendered within the annotation.
void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context) override
Restores the annotation's state from a DOM element.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
const QTextDocument * document() const
Returns the text document which will be rendered within the annotation.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.