QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
30 #include <QDomElement>
34 #include <QGraphicsProxyWidget>
44 mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
45 mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
48 connect( mWebPage->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared,
this, &QgsHtmlAnnotation::javascript );
55 c->setSourceFile( mHtmlFile );
61 QFile file( htmlFile );
63 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
69 QTextStream in( &file );
70 in.setCodec(
"UTF-8" );
71 mHtmlSource = in.readAll();
88 const double scaleFactor = context.
painter()->device()->logicalDpiX() / 96.0;
89 context.
painter()->scale( scaleFactor, scaleFactor );
92 mWebPage->setViewportSize( size.toSize() );
93 mWebPage->mainFrame()->render( context.
painter() );
100 QSizeF widgetMinSize = QSizeF( 0, 0 );
106 return QSizeF( 0, 0 );
112 QDomElement formAnnotationElem = doc.createElement( QStringLiteral(
"HtmlAnnotationItem" ) );
113 formAnnotationElem.setAttribute( QStringLiteral(
"htmlfile" ),
sourceFile() );
115 _writeXml( formAnnotationElem, doc, context );
116 elem.appendChild( formAnnotationElem );
121 mHtmlFile = itemElem.attribute( QStringLiteral(
"htmlfile" ), QString() );
122 QDomElement annotationElem = itemElem.firstChildElement( QStringLiteral(
"AnnotationItem" ) );
123 if ( !annotationElem.isNull() )
125 _readXml( annotationElem, context );
129 if ( !
mapLayer() && itemElem.hasAttribute( QStringLiteral(
"vectorLayer" ) ) )
145 if ( feature.
isValid() && vectorLayer )
153 newText = mHtmlSource;
155 mWebPage->mainFrame()->setHtml( newText );
159 void QgsHtmlAnnotation::javascript()
161 QWebFrame *frame = mWebPage->mainFrame();
162 frame->addToJavaScriptWindowObject( QStringLiteral(
"layer" ),
mapLayer() );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsHtmlAnnotation(QObject *parent=nullptr)
Constructor for QgsHtmlAnnotation.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
The class is used as a container of context for various read/write operations on other objects.
QgsHtmlAnnotation * clone() const override
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
void setSourceFile(const QString &htmlFile)
Sets the file path for the source HTML file.
void renderAnnotation(QgsRenderContext &context, QSizeF size) const override
Renders the annotation's contents to a target /a context at the specified /a size.
Contains information about the context of a rendering operation.
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
QWebPage subclass which redirects JavaScript errors and console output to the QGIS message log.
Abstract base class for annotation items which are drawn over a map.
QString sourceFile() const
Returns the file path for the source HTML file.
bool isValid() const
Returns the validity of this feature.
void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context) override
Restores the annotation's state from a DOM element.
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set.
QSizeF minimumFrameSize() const override
Returns the minimum frame size for the annotation.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
An annotation item that embeds HTML content.
Scoped object for saving and restoring a QPainter object's state.
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
void setAssociatedFeature(const QgsFeature &feature) override
Sets the feature associated with 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
Represents a vector layer which manages a vector based data sets.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes the annotation state to a DOM element.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QPainter * painter()
Returns the destination QPainter for the render operation.
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 copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
The QWebFrame class is a collection of stubs to mimic the API of a QWebFrame on systems where QtWebki...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setMapLayer(QgsMapLayer *layer)
Sets the map layer associated with the annotation.