18#include <nlohmann/json.hpp>
40#if defined( HAVE_WEBENGINE ) && defined( HAVE_PDF4QT )
44#include <QWebEnginePage>
45#include <QWebEngineSettings>
46#include <QWebEngineScript>
53#include <QAbstractTextDocumentLayout>
54#include <QCoreApplication>
56#include <QNetworkReply>
61#include <QtConcurrentRun>
64#include "moc_qgslayoutitemhtml.cpp"
66using namespace Qt::StringLiterals;
74 mPictureRasterizer->setMaxCacheSize( 10000 );
76 mBackgroundUpdateTimer =
new QTimer(
this );
77 mBackgroundUpdateTimer->setSingleShot(
true );
78 connect( mBackgroundUpdateTimer, &QTimer::timeout,
this, &QgsLayoutItemHtml::recreateCachedImageInBackground );
87 setExpressionContext(
mLayout->reportContext().feature(),
mLayout->reportContext().layer() );
98 mBackgroundUpdateTimer->stop();
100 cancelRunningRenderJob(
true );
132 frame->setVisible( label->isVisible() );
135 frame->setRotation( label->rotation() );
139 frame->setZValue( label->zValue() );
149 html->setUserStylesheetEnabled(
true );
150 html->setUserStylesheet( label->createStylesheet() );
183 switch ( mContentMode )
187 QString currentUrl = mUrl.toString();
194 currentUrl = currentUrl.trimmed();
197 if ( currentUrl.isEmpty() )
199 cancelPendingFetch();
200 finalizeLoadedHtml( QString(), QUrl(), evalContext );
204 if ( useCache && mHasFetchedHtml && currentUrl == mLastFetchedUrl )
206 cancelPendingFetch();
207 finalizeLoadedHtml( mFetchedHtml, QUrl( mActualFetchedUrl ), evalContext );
211 if ( !( useCache && mFetching && currentUrl == mPendingFetchUrl ) )
213 cancelPendingFetch();
214 mBackgroundUpdateTimer->stop();
215 cancelRunningRenderJob(
false );
217 mPendingFetchUrl = currentUrl;
218 mPendingExpressionContext = context ? std::optional< QgsExpressionContext >( *context ) : std::nullopt;
219 mCacheInvalidated =
true;
220 startFetchHtml( QUrl( currentUrl ) );
225 mPendingExpressionContext = *context;
231 waitForPendingFetch();
238 cancelPendingFetch();
239 const QUrl baseUrl = (
mLayout &&
mLayout->project() ) ? QUrl::fromLocalFile(
mLayout->project()->absoluteFilePath() ) : QUrl();
240 finalizeLoadedHtml( mHtml, baseUrl, evalContext );
245void QgsLayoutItemHtml::startFetchHtml(
const QUrl &url )
252void QgsLayoutItemHtml::cancelPendingFetch()
258 mPendingFetchUrl.clear();
259 mPendingExpressionContext.reset();
261 mFetcher->disconnect(
this );
263 mFetcher->deleteLater();
264 mFetcher =
new QgsNetworkContentFetcher(
this );
269void QgsLayoutItemHtml::waitForPendingFetch()
278 loop.exec( QEventLoop::ExcludeUserInputEvents );
282void QgsLayoutItemHtml::onHtmlFetched()
289 mFetchedHtml = mFetcher->contentAsString();
290 mActualFetchedUrl = mFetcher->reply() ? mFetcher->reply()->url().toString() : mPendingFetchUrl;
291 mLastFetchedUrl = mPendingFetchUrl;
292 mHasFetchedHtml =
true;
293 mPendingFetchUrl.clear();
295 const std::optional< QgsExpressionContext > savedContext = std::move( mPendingExpressionContext );
296 mPendingExpressionContext = {};
299 const QgsExpressionContext *evalContext = savedContext.has_value() ? &*savedContext : &scopedContext;
300 finalizeLoadedHtml( mFetchedHtml, QUrl( mActualFetchedUrl ), evalContext );
303void QgsLayoutItemHtml::finalizeLoadedHtml(
const QString &rawHtml,
const QUrl &baseUrl,
const QgsExpressionContext *context )
305 QString loadedHtml = rawHtml;
306 if ( mEvaluateExpressions && !loadedHtml.isEmpty() )
311 mEvaluatedHtml = loadedHtml;
312 mResolvedBaseUrl = baseUrl;
313 mCacheInvalidated =
true;
317 mBackgroundUpdateTimer->stop();
318 cancelRunningRenderJob(
false );
319 renderHtmlSynchronously();
325 mBackgroundUpdateTimer->start( 1 );
329void QgsLayoutItemHtml::recreateCachedImageInBackground()
334 cancelRunningRenderJob(
false );
336 const double frameWidthLayoutUnits = maxFrameWidth();
337 if ( frameWidthLayoutUnits <= 0 || mEvaluatedHtml.isEmpty() )
339 mCacheInvalidated =
false;
340 mLastRenderedWidth = frameWidthLayoutUnits;
341 mSize = QSizeF( 0, 0 );
342 mRenderedPicture = QPicture();
343 mRenderedPage = QImage();
344 mPictureRasterizer->clear();
354 mCacheInvalidated =
false;
355 mRenderJob = std::make_unique<
356 QgsLayoutItemHtmlRenderJob >( mEvaluatedHtml, mResolvedBaseUrl, mEnableUserStylesheet ? mUserStylesheet : QString(), mAtlasFeatureProperties, frameWidthLayoutUnits, layoutUnitsPerCssPixel() );
357 connect( mRenderJob.get(), &QgsLayoutItemHtmlRenderJob::finished,
this, &QgsLayoutItemHtml::htmlRenderFinished );
361void QgsLayoutItemHtml::htmlRenderFinished()
366 if ( !mRenderJob->success() && !mRenderJob->errorMessage().isEmpty() )
371 mLastRenderedWidth = mRenderJob->frameWidthLayoutUnits();
372 mSize = mRenderJob->size();
374 mRenderedPage = mRenderJob->renderedPage();
377 mPictureRasterizer->setPicture( mRenderedPicture );
387void QgsLayoutItemHtml::renderHtmlSynchronously()
391 waitForPendingFetch();
395 const double frameWidthLayoutUnits = maxFrameWidth();
396 mLastRenderedWidth = frameWidthLayoutUnits;
397 mCacheInvalidated =
false;
399 if ( frameWidthLayoutUnits <= 0 || mEvaluatedHtml.isEmpty() )
401 mSize = QSizeF( 0, 0 );
402 mRenderedPicture = QPicture();
403 mRenderedPage = QImage();
404 mPictureRasterizer->clear();
410 const double unitsPerCssPx = layoutUnitsPerCssPixel();
411 const double widthCssPx = frameWidthLayoutUnits / unitsPerCssPx;
413 mRenderedPicture = QPicture();
414 QPainter painter( &mRenderedPicture );
415 painter.setRenderHint( QPainter::Antialiasing,
true );
416 painter.setRenderHint( QPainter::TextAntialiasing,
true );
417 painter.setRenderHint( QPainter::SmoothPixmapTransform,
true );
419 QSizeF renderedSizeCssPx;
421 QgsHtmlRenderSettings htmlRenderSettings;
422 htmlRenderSettings.
setBaseUrl( mResolvedBaseUrl );
423 if ( mEnableUserStylesheet )
430 QString errorMessage;
431 if ( !
QgsWebEnginePage::renderBlocking( mEvaluatedHtml, &painter, QRectF( 0, 0, widthCssPx, 9999 ), errorMessage, renderedSizeCssPx, htmlRenderSettings,
nullptr ) )
438 const double heightCssPx = renderedSizeCssPx.height();
439 mRenderedPicture.setBoundingRect( QRect( 0, 0,
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) ) );
441 mSize = QSizeF( frameWidthLayoutUnits, heightCssPx * unitsPerCssPx );
443 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) );
444 if ( mUseSmartBreaks && !pageSizeCssPx.isEmpty() )
446 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
447 mRenderedPage.fill( Qt::transparent );
448 QPainter imagePainter( &mRenderedPage );
454 mRenderedPage = QImage();
457 mPictureRasterizer->setPicture( mRenderedPicture );
463double QgsLayoutItemHtml::maxFrameWidth()
const
468 maxWidth = std::max( maxWidth,
static_cast< double >(
frame->boundingRect().width() ) );
481 const double currentWidth = maxFrameWidth();
482 if ( !
qgsDoubleNear( currentWidth, mLastRenderedWidth ) && !mEvaluatedHtml.isEmpty() )
484 mCacheInvalidated =
true;
487 mBackgroundUpdateTimer->stop();
488 cancelRunningRenderJob(
false );
489 renderHtmlSynchronously();
494 mBackgroundUpdateTimer->start( 1 );
515 if (
mLayout->renderContext().isPreviewRender() )
519 if ( !mFetching && ( mCacheInvalidated || !
qgsDoubleNear( maxFrameWidth(), mLastRenderedWidth ) ) && !mRenderJob && !mBackgroundUpdateTimer->isActive() && !mEvaluatedHtml.isEmpty() )
521 mBackgroundUpdateTimer->start( 1 );
525 const QSize targetPixelSize = ( mSize * currentScaleFactor ).toSize();
526 const QImage previewImage = mPictureRasterizer->image( targetPixelSize );
528 if ( !previewImage.isNull() && !mSize.isEmpty() )
531 painter->scale( currentScaleFactor, currentScaleFactor );
532 painter->translate( -renderExtent.left(), -renderExtent.top() );
533 painter->setClipRect( renderExtent, Qt::IntersectClip );
534 painter->setRenderHint( QPainter::SmoothPixmapTransform,
true );
535 painter->drawImage( QRectF( QPointF( 0, 0 ), mSize ), previewImage );
537 else if ( mFetching || mRenderJob || mBackgroundUpdateTimer->isActive() || mPictureRasterizer->isRendering() )
542 painter->scale( currentScaleFactor, currentScaleFactor );
543 const QRectF frameRect( 0, 0, currentFrame->rect().width(), currentFrame->rect().height() );
544 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
545 painter->setPen( Qt::NoPen );
546 painter->drawRect( frameRect );
547 painter->setBrush( Qt::NoBrush );
550 messageFont.setPointSize( 12 );
551 painter->setFont( messageFont );
552 painter->setPen( QColor( 255, 255, 255, 255 ) );
553 painter->drawText( frameRect, Qt::AlignCenter, tr(
"Rendering HTML" ) );
561 waitForPendingFetch();
564 if ( mCacheInvalidated || mRenderJob || !
qgsDoubleNear( maxFrameWidth(), mLastRenderedWidth ) )
566 mBackgroundUpdateTimer->stop();
567 cancelRunningRenderJob(
false );
568 renderHtmlSynchronously();
572 painter->setRenderHint( QPainter::Antialiasing );
573 painter->setRenderHint( QPainter::SmoothPixmapTransform );
577 painter->translate( -renderExtent.left(), -renderExtent.top() );
578 painter->setClipRect( renderExtent, Qt::IntersectClip );
580 const double unitsPerCssPx = layoutUnitsPerCssPixel();
581 painter->scale( unitsPerCssPx, unitsPerCssPx );
585 Q_UNUSED( renderExtent )
586 if (
mLayout->renderContext().isPreviewRender() )
593 const QRectF painterRect = QRectF(
600 painter->setBrush( QBrush( QColor( 255, 125, 125, 125 ) ) );
601 painter->setPen( Qt::NoPen );
602 painter->drawRect( painterRect );
603 painter->setBrush( Qt::NoBrush );
605 painter->setPen( QColor( 200, 0, 0, 255 ) );
607 td.setTextWidth( painterRect.width() );
608 td.setHtml( u
"<span style=\"color: rgb(200,0,0);\"><b>%1</b><br>%2</span>"_s
609 .arg( tr(
"HTML rendering not available!" ), tr(
"The item cannot be rendered because this QGIS install was built without WebEngine or PDF4QT support." ) ) );
610 painter->setClipRect( painterRect );
611 QAbstractTextDocumentLayout::PaintContext ctx;
612 td.documentLayout()->draw( painter, ctx );
618double QgsLayoutItemHtml::layoutUnitsPerCssPixel()
const
626void QgsLayoutItemHtml::cancelRunningRenderJob(
bool block )
631 disconnect( mRenderJob.get(), &QgsLayoutItemHtmlRenderJob::finished,
this, &QgsLayoutItemHtml::htmlRenderFinished );
634 mRenderJob->cancelAndWait();
639 QgsLayoutItemHtmlRenderJob *oldJob = mRenderJob.release();
640 connect( oldJob, &QgsLayoutItemHtmlRenderJob::finished, oldJob, &QObject::deleteLater );
641 oldJob->cancelWithoutBlocking();
645void QgsLayoutItemHtml::updateFrames()
656 mPictureRasterizer->invalidate();
662 if ( c1.second < c2.second )
664 else if ( c1.second > c2.second )
666 else if ( c1.first > c2.first )
674 if ( mRenderedPage.isNull() || !mUseSmartBreaks )
679 const double unitsPerCssPx = layoutUnitsPerCssPixel();
681 const int idealPos =
static_cast< int >( yPos / unitsPerCssPx );
684 if ( idealPos >= mRenderedPage.height() )
689 const int maxSearchDistance =
static_cast< int >( mMaxBreakDistance / unitsPerCssPx );
695 bool currentPixelTransparent =
false;
696 bool previousPixelTransparent =
false;
698 QList< QPair<int, int> > candidates;
699 const int minRow = std::max( idealPos - maxSearchDistance, 0 );
700 for (
int candidateRow = idealPos; candidateRow >= minRow; --candidateRow )
703 currentColor = qRgba( 0, 0, 0, 0 );
705 for (
int col = 0; col < mRenderedPage.width(); ++col )
711 pixelColor = mRenderedPage.pixel( col, candidateRow );
712 currentPixelTransparent = qAlpha( pixelColor ) == 0;
713 if ( pixelColor != currentColor && !( currentPixelTransparent && previousPixelTransparent ) )
716 currentColor = pixelColor;
719 previousPixelTransparent = currentPixelTransparent;
721 candidates.append( qMakePair( candidateRow, changes ) );
725 std::sort( candidates.begin(), candidates.end(),
candidateSort );
732 const int maxCandidateRow = candidates[0].first;
733 int minCandidateRow = maxCandidateRow + 1;
734 const int minCandidateChanges = candidates[0].second;
736 QList< QPair<int, int> >::iterator it;
737 for ( it = candidates.begin(); it != candidates.end(); ++it )
739 if ( ( *it ).second != minCandidateChanges || ( *it ).first != minCandidateRow - 1 )
744 return ( minCandidateRow + ( maxCandidateRow - minCandidateRow ) / 2 ) * unitsPerCssPx;
746 minCandidateRow = ( *it ).first;
751 return candidates[0].first * unitsPerCssPx;
760 if ( mUseSmartBreaks && mRenderedPage.isNull() && !mRenderedPicture.isNull() && !mSize.isEmpty() )
762 const double unitsPerCssPx = layoutUnitsPerCssPixel();
763 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( mSize.width() / unitsPerCssPx ) ),
static_cast< int >( std::ceil( mSize.height() / unitsPerCssPx ) ) );
764 if ( !pageSizeCssPx.isEmpty() )
766 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
767 mRenderedPage.fill( Qt::transparent );
768 QPainter imagePainter( &mRenderedPage );
787 mUserStylesheet = stylesheet;
796 if ( mEnableUserStylesheet != stylesheetEnabled )
798 mEnableUserStylesheet = stylesheetEnabled;
806 return tr(
"<HTML frame>" );
811 htmlElem.setAttribute( u
"contentMode"_s, QString::number(
static_cast< int >( mContentMode ) ) );
812 htmlElem.setAttribute( u
"url"_s, mUrl.toString() );
813 htmlElem.setAttribute( u
"html"_s, mHtml );
814 htmlElem.setAttribute( u
"evaluateExpressions"_s, mEvaluateExpressions ?
"true" :
"false" );
815 htmlElem.setAttribute( u
"useSmartBreaks"_s, mUseSmartBreaks ?
"true" :
"false" );
816 htmlElem.setAttribute( u
"maxBreakDistance"_s, QString::number( mMaxBreakDistance ) );
817 htmlElem.setAttribute( u
"stylesheet"_s, mUserStylesheet );
818 htmlElem.setAttribute( u
"stylesheetEnabled"_s, mEnableUserStylesheet ?
"true" :
"false" );
826 if ( !contentModeOK )
830 mEvaluateExpressions = itemElem.attribute( u
"evaluateExpressions"_s, u
"true"_s ) ==
"true"_L1;
831 mUseSmartBreaks = itemElem.attribute( u
"useSmartBreaks"_s, u
"true"_s ) ==
"true"_L1;
832 mMaxBreakDistance = itemElem.attribute( u
"maxBreakDistance"_s, u
"10"_s ).toDouble();
833 mHtml = itemElem.attribute( u
"html"_s );
834 mUserStylesheet = itemElem.attribute( u
"stylesheet"_s );
835 mEnableUserStylesheet = itemElem.attribute( u
"stylesheetEnabled"_s, u
"false"_s ) ==
"true"_L1;
838 const QString urlString = itemElem.attribute( u
"url"_s );
839 if ( !urlString.isEmpty() )
851 return mFetching || mRenderJob || mBackgroundUpdateTimer->isActive() || ( mPictureRasterizer && mPictureRasterizer->isRendering() );
856 mExpressionFeature = feature;
857 mExpressionLayer = layer;
867 QgsLayoutItemMap *referenceMap =
mLayout->referenceMap();
869 mDistanceArea.setSourceCrs( referenceMap->
crs(),
mLayout->project()->transformContext() );
873 mDistanceArea.setEllipsoid(
mLayout->project()->ellipsoid() );
879 QgsJsonExporter exporter( layer );
880 exporter.setIncludeRelated(
true );
885 mAtlasFeatureProperties.clear();
889void QgsLayoutItemHtml::refreshExpressionContext()
891 QgsVectorLayer *vl =
nullptr;
896 vl =
mLayout->reportContext().layer();
897 feature =
mLayout->reportContext().feature();
900 setExpressionContext( feature, vl );
920QgsLayoutItemHtmlRenderJob::QgsLayoutItemHtmlRenderJob(
921 const QString &html,
const QUrl &baseUrl,
const QString &userStylesheet,
const QVariantMap &featureJson,
double frameWidthLayoutUnits,
double unitsPerCssPx
924 , mBaseUrl( baseUrl )
925 , mUserStylesheet( userStylesheet )
926 , mFeatureJson( featureJson )
927 , mFrameWidthLayoutUnits( frameWidthLayoutUnits )
928 , mUnitsPerCssPx( unitsPerCssPx )
930 connect( &mWatcher, &QFutureWatcher< void >::finished,
this, &QgsLayoutItemHtmlRenderJob::finished );
933void QgsLayoutItemHtmlRenderJob::start()
935 mWatcher.setFuture( QtConcurrent::run( [
this]() { run(); } ) );
938void QgsLayoutItemHtmlRenderJob::cancelWithoutBlocking()
943void QgsLayoutItemHtmlRenderJob::cancelAndWait()
946 mWatcher.waitForFinished();
949bool QgsLayoutItemHtmlRenderJob::isCanceled()
const
951 return mFeedback.isCanceled();
954void QgsLayoutItemHtmlRenderJob::run()
957 const double widthCssPx = mFrameWidthLayoutUnits / mUnitsPerCssPx;
959 QPainter painter( &mPicture );
960 QSizeF renderedSizeCssPx;
967 mSuccess =
QgsWebEnginePage::renderBlocking( mHtml, &painter, QRectF( 0, 0, widthCssPx, 9999 ), mErrorMessage, renderedSizeCssPx, htmlRenderSettings, &mFeedback );
970 if ( mFeedback.isCanceled() )
973 const double heightCssPx = renderedSizeCssPx.height();
974 mPicture.setBoundingRect( QRect( 0, 0,
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) ) );
976 mSize = QSizeF( mFrameWidthLayoutUnits, heightCssPx * mUnitsPerCssPx );
978 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) );
979 if ( !pageSizeCssPx.isEmpty() )
981 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
982 mRenderedPage.fill( Qt::transparent );
983 QPainter imagePainter( &mRenderedPage );
989 mErrorMessage = tr(
"Rendering HTML requires a QGIS build with WebEngine and PDF4QT support" );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Encapsulates settings for rendering HTML content.
void setUserStylesheet(const QString &stylesheet)
Sets the user stylesheet CSS rules to use while rendering the HTML content.
void setBaseUrl(const QUrl &url)
Sets the base url to use when resolving relative links.
void setFeatureJson(const QVariantMap &json)
Sets the feature json (as a variant map).
static QVariant jsonToVariant(const json &value)
Converts a JSON value to a QVariant, in case of parsing error an invalid QVariant is returned.
int type() const override
Returns unique multiframe type id.
QSizeF totalSize() const override
Returns the total size of the multiframe's content, in layout units.
void setUrl(const QUrl &url)
Sets the url for content to display in the item when the item is using the QgsLayoutItemHtml::Url mod...
void invalidateCache()
Invalidates cached renders.
ContentMode
Source modes for the HTML content to render in the item.
@ ManualHtml
HTML content is manually set for the item.
@ Url
Using this mode item fetches its content via a url.
static bool isSupported()
Returns true if HTML item rendering is supported on the system.
void setEvaluateExpressions(bool evaluateExpressions)
Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
QString html() const
Returns the HTML source displayed in the item if the item is using the QgsLayoutItemHtml::ManualHtml ...
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
~QgsLayoutItemHtml() override
double maxBreakDistance() const
Returns the maximum distance allowed when calculating where to place page breaks in the html.
void previewRefreshed()
Emitted whenever the item's preview has been refreshed.
static QgsLayoutItemHtml * createFromLabel(QgsLayoutItemLabel *label)
Returns a new QgsLayoutItemHtml matching the content and rendering of a given label.
static QgsLayoutItemHtml * create(QgsLayout *layout)
Returns a new QgsLayoutItemHtml for the specified parent layout.
bool evaluateExpressions() const
Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content.
double findNearbyPageBreak(double yPos) override
Finds the optimal position to break a frame at.
QUrl url() const
Returns the URL of the content displayed in the item if the item is using the QgsLayoutItemHtml::Url ...
void setMaxBreakDistance(double distance)
Sets the maximum distance allowed when calculating where to place page breaks in the html.
void setUserStylesheetEnabled(bool enabled)
Sets whether user stylesheets are enabled for the HTML content.
void setHtml(const QString &html)
Sets the html to display in the item when the item is using the QgsLayoutItemHtml::ManualHtml mode.
QString displayName() const override
Returns the multiframe display name.
void setUseSmartBreaks(bool useSmartBreaks)
Sets whether the html item should use smart breaks.
void recalculateFrameSizes() override
Recalculates the frame sizes for the current viewport dimensions.
void setUserStylesheet(const QString &stylesheet)
Sets the user stylesheet CSS rules to use while rendering the HTML content.
QIcon icon() const override
Returns the item's icon.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
QgsLayoutItemHtml(QgsLayout *layout)
Constructor for QgsLayoutItemHtml, with the specified parent layout.
void loadHtml(bool useCache=false, const QgsExpressionContext *context=nullptr)
Reloads the html source from the url and redraws the item.
void render(QgsLayoutItemRenderContext &context, const QRectF &renderExtent, int frameIndex) override
Renders a portion of the multiframe's content into a render context.
bool renderInProgress() const override
Returns true if the multiframe is currently rendering content in a background thread.
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
A layout item subclass for text labels.
QString currentText() const
Returns the text as it appears on the label (with evaluated expressions and other dynamic content).
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
@ LayoutHtml
Html multiframe item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QColor backgroundColor(bool useDataDefined=true) const
Returns the background color for this item.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
double itemOpacity() const
Returns the item's opacity.
ReferencePoint referencePoint() const
Returns the reference point for positioning of the layout item.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
bool frameEnabled() const
Returns true if the item includes a frame.
QColor frameStrokeColor() const
Returns the frame's stroke color.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
int frameCount() const
Returns the number of frames associated with this multiframe.
QgsLayoutMultiFrame(QgsLayout *layout)
Construct a new multiframe item, attached to the specified layout.
void contentsChanged()
Emitted when the contents of the multi frame have changed and the frames must be redrawn.
QgsLayoutFrame * frame(int index) const
Returns the child frame at a specified index from the multiframe.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QList< QgsLayoutFrame * > mFrameItems
friend class QgsLayoutFrame
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of its component frames.
int frameIndex(QgsLayoutFrame *frame) const
Returns the index of a frame within the multiframe.
void backgroundTaskCountChanged(int count)
Emitted whenever the number of background tasks the multi frame is executing changes.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
@ SourceUrl
Html source url.
@ AllProperties
All properties for item.
void changed()
Emitted certain settings in the context is changed, e.g.
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated.
QgsCoordinateReferenceSystem crs
HTTP network content fetcher.
void fetchContent(const QUrl &url, const QString &authcfg=QString(), const QgsHttpHeaders &headers=QgsHttpHeaders())
Fetches content from a remote URL and handles redirects.
void finished()
Emitted when content has loaded.
static QPicture deepCopyQPicture(const QPicture &picture)
Deep copies a QPicture, making a copy which is safe to use in a different thread.
static void drawPicture(QPainter *painter, const QPointF &point, const QPicture &picture)
Draws a picture onto a painter, correctly applying workarounds to avoid issues with incorrect scaling...
Rasterizes and caches a QPicture as a QImage at a requested size.
void rendered()
Emitted when a background rasterization finishes and a new cached image is available.
A container for the context for various read/write operations on objects.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
Scoped object for saving and restoring a QPainter object's state.
Represents a vector layer which manages a vector based dataset.
static bool renderBlocking(const QString &html, QPainter *painter, const QRectF &painterRect, QString &errorMessage, QSizeF &renderedSize, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
Renders HTML content to a painter asynchronously.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
bool candidateSort(QPair< int, int > c1, QPair< int, int > c2)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)