24#include <QDomDocument>
27#include "moc_qgstextannotation.cpp"
31 , mDocument( new QTextDocument( QString() ) )
33 mDocument->setUseDesignMetrics(
true );
38 auto c = std::make_unique<QgsTextAnnotation>();
40 c->setDocument( mDocument.get() );
46 return mDocument.get();
52 mDocument.reset( doc->clone() );
60 QPainter *painter = context.
painter();
68 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
69 context.
painter()->scale( scaleFactor, scaleFactor );
72 mDocument->setTextWidth( size.width() );
74 QRectF clipRect = QRectF( 0, 0, size.width(), size.height() );
75 if ( painter->hasClipping() )
80 clipRect = clipRect.intersected( painter->clipRegion().boundingRect() );
83 mDocument->drawContents( painter, clipRect );
88 QDomElement annotationElem = doc.createElement( QStringLiteral(
"TextAnnotationItem" ) );
91 annotationElem.setAttribute( QStringLiteral(
"document" ), mDocument->toHtml() );
93 _writeXml( annotationElem, doc, context );
94 elem.appendChild( annotationElem );
99 mDocument = std::make_unique<QTextDocument>( );
100 mDocument->setHtml( itemElem.attribute( QStringLiteral(
"document" ), QString() ) );
101 const QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
102 if ( !annotationElem.isNull() )
104 _readXml( annotationElem, context );
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.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
QgsAnnotation(QObject *parent=nullptr)
Constructor for QgsAnnotation.
bool isCanceled() const
Tells whether the operation has been canceled already.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
Scoped object for saving and restoring a QPainter object's state.
QgsTextAnnotation * clone() const override
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes the annotation state to a DOM element.
void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context) override
Restores the annotation's state from a DOM element.
const QTextDocument * document() const
Returns the text document which will be rendered within the annotation.
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(QObject *parent=nullptr)
Constructor for QgsTextAnnotation.
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