QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
24 #include <QDomDocument>
25 #include <QDomElement>
38 c->setFilePath( mFilePath );
45 QDomElement svgAnnotationElem = doc.createElement( QStringLiteral(
"SVGAnnotationItem" ) );
46 svgAnnotationElem.setAttribute( QStringLiteral(
"file" ),
filePath );
47 _writeXml( svgAnnotationElem, doc, context );
48 elem.appendChild( svgAnnotationElem );
55 QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
56 if ( !annotationElem.isNull() )
64 QPainter *painter = context.
painter();
71 QRect viewBox = mSvgRenderer.viewBox();
72 if ( viewBox.isValid() )
74 double widthRatio = size.width() / viewBox.width();
75 double heightRatio = size.height() / viewBox.height();
76 double renderWidth = 0;
77 double renderHeight = 0;
78 if ( widthRatio <= heightRatio )
80 renderWidth = size.width();
81 renderHeight = viewBox.height() * widthRatio;
85 renderHeight = size.height();
86 renderWidth = viewBox.width() * heightRatio;
89 mSvgRenderer.render( painter, QRectF( 0, 0, renderWidth,
97 mSvgRenderer.load( mFilePath );
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.
QgsSvgAnnotation * clone() const override
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
void renderAnnotation(QgsRenderContext &context, QSizeF size) const override
Renders the annotation's contents to a target /a context at the specified /a size.
void setFilePath(const QString &file)
Sets the file path for the source SVG file.
Contains information about the context of a rendering operation.
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
An annotation which renders the contents of an SVG file.
Abstract base class for annotation items which are drawn over a map.
QgsSvgAnnotation(QObject *parent=nullptr)
Constructor for QgsSvgAnnotation.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes the annotation state to a DOM element.
QString filePath() const
Returns the file path for the source SVG file.
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
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context) override
Restores the annotation's state from a DOM element.
QPainter * painter()
Returns the destination QPainter for the render operation.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.