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() );
184 switch ( mContentMode )
188 QString currentUrl = mUrl.toString();
195 currentUrl = currentUrl.trimmed();
198 if ( currentUrl.isEmpty() )
200 cancelPendingFetch();
201 finalizeLoadedHtml( QString(), QUrl(), evalContext );
205 if ( useCache && mHasFetchedHtml && currentUrl == mLastFetchedUrl )
207 cancelPendingFetch();
208 finalizeLoadedHtml( mFetchedHtml, QUrl( mActualFetchedUrl ), evalContext );
212 if ( !( useCache && mFetching && currentUrl == mPendingFetchUrl ) )
214 cancelPendingFetch();
215 mBackgroundUpdateTimer->stop();
216 cancelRunningRenderJob(
false );
218 mPendingFetchUrl = currentUrl;
219 mPendingExpressionContext = context ? std::optional< QgsExpressionContext >( *context ) : std::nullopt;
220 mCacheInvalidated =
true;
221 startFetchHtml( QUrl( currentUrl ) );
226 mPendingExpressionContext = *context;
232 waitForPendingFetch();
239 cancelPendingFetch();
240 const QUrl baseUrl = (
mLayout &&
mLayout->project() ) ? QUrl::fromLocalFile(
mLayout->project()->absoluteFilePath() ) : QUrl();
241 finalizeLoadedHtml( mHtml, baseUrl, evalContext );
246void QgsLayoutItemHtml::startFetchHtml(
const QUrl &url )
253void QgsLayoutItemHtml::cancelPendingFetch()
259 mPendingFetchUrl.clear();
260 mPendingExpressionContext.reset();
262 mFetcher->disconnect(
this );
264 mFetcher->deleteLater();
265 mFetcher =
new QgsNetworkContentFetcher(
this );
270void QgsLayoutItemHtml::waitForPendingFetch()
279 loop.exec( QEventLoop::ExcludeUserInputEvents );
283void QgsLayoutItemHtml::onHtmlFetched()
290 mFetchedHtml = mFetcher->contentAsString();
291 mActualFetchedUrl = mFetcher->reply() ? mFetcher->reply()->url().toString() : mPendingFetchUrl;
292 mLastFetchedUrl = mPendingFetchUrl;
293 mHasFetchedHtml =
true;
294 mPendingFetchUrl.clear();
296 const std::optional< QgsExpressionContext > savedContext = std::move( mPendingExpressionContext );
297 mPendingExpressionContext = {};
300 const QgsExpressionContext *evalContext = savedContext.has_value() ? &*savedContext : &scopedContext;
301 finalizeLoadedHtml( mFetchedHtml, QUrl( mActualFetchedUrl ), evalContext );
304void QgsLayoutItemHtml::finalizeLoadedHtml(
const QString &rawHtml,
const QUrl &baseUrl,
const QgsExpressionContext *context )
306 QString loadedHtml = rawHtml;
307 if ( mEvaluateExpressions && !loadedHtml.isEmpty() )
312 mEvaluatedHtml = loadedHtml;
313 mResolvedBaseUrl = baseUrl;
314 mCacheInvalidated =
true;
318 mBackgroundUpdateTimer->stop();
319 cancelRunningRenderJob(
false );
320 renderHtmlSynchronously();
326 mBackgroundUpdateTimer->start( 1 );
330void QgsLayoutItemHtml::recreateCachedImageInBackground()
335 cancelRunningRenderJob(
false );
337 const double frameWidthLayoutUnits = maxFrameWidth();
338 if ( frameWidthLayoutUnits <= 0 || mEvaluatedHtml.isEmpty() )
340 mCacheInvalidated =
false;
341 mLastRenderedWidth = frameWidthLayoutUnits;
342 mSize = QSizeF( 0, 0 );
343 mRenderedPicture = QPicture();
344 mRenderedPage = QImage();
345 mPictureRasterizer->clear();
355 mCacheInvalidated =
false;
356 mRenderJob = std::make_unique<
357 QgsLayoutItemHtmlRenderJob >( mEvaluatedHtml, mResolvedBaseUrl, mEnableUserStylesheet ? mUserStylesheet : QString(), mAtlasFeatureProperties, frameWidthLayoutUnits, layoutUnitsPerCssPixel() );
358 connect( mRenderJob.get(), &QgsLayoutItemHtmlRenderJob::finished,
this, &QgsLayoutItemHtml::htmlRenderFinished );
362void QgsLayoutItemHtml::htmlRenderFinished()
367 if ( !mRenderJob->success() && !mRenderJob->errorMessage().isEmpty() )
372 mLastRenderedWidth = mRenderJob->frameWidthLayoutUnits();
373 mSize = mRenderJob->size();
375 mRenderedPage = mRenderJob->renderedPage();
378 mPictureRasterizer->setPicture( mRenderedPicture );
388void QgsLayoutItemHtml::renderHtmlSynchronously()
392 waitForPendingFetch();
396 const double frameWidthLayoutUnits = maxFrameWidth();
397 mLastRenderedWidth = frameWidthLayoutUnits;
398 mCacheInvalidated =
false;
400 if ( frameWidthLayoutUnits <= 0 || mEvaluatedHtml.isEmpty() )
402 mSize = QSizeF( 0, 0 );
403 mRenderedPicture = QPicture();
404 mRenderedPage = QImage();
405 mPictureRasterizer->clear();
411 const double unitsPerCssPx = layoutUnitsPerCssPixel();
412 const double widthCssPx = frameWidthLayoutUnits / unitsPerCssPx;
414 QString errorMessage;
415 mRenderedPicture = QPicture();
416 QPainter painter( &mRenderedPicture );
417 painter.setRenderHint( QPainter::Antialiasing,
true );
418 painter.setRenderHint( QPainter::TextAntialiasing,
true );
419 painter.setRenderHint( QPainter::SmoothPixmapTransform,
true );
421 QSizeF renderedSizeCssPx;
423 QgsHtmlRenderSettings htmlRenderSettings;
424 htmlRenderSettings.
setBaseUrl( mResolvedBaseUrl );
425 if ( mEnableUserStylesheet )
432 if ( !
QgsWebEnginePage::renderBlocking( mEvaluatedHtml, &painter, QRectF( 0, 0, widthCssPx, 9999 ), errorMessage, renderedSizeCssPx, htmlRenderSettings,
nullptr ) )
439 const double heightCssPx = renderedSizeCssPx.height();
440 mRenderedPicture.setBoundingRect( QRect( 0, 0,
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) ) );
442 mSize = QSizeF( frameWidthLayoutUnits, heightCssPx * unitsPerCssPx );
444 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) );
445 if ( mUseSmartBreaks && !pageSizeCssPx.isEmpty() )
447 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
448 mRenderedPage.fill( Qt::transparent );
449 QPainter imagePainter( &mRenderedPage );
455 mRenderedPage = QImage();
458 mPictureRasterizer->setPicture( mRenderedPicture );
464double QgsLayoutItemHtml::maxFrameWidth()
const
469 maxWidth = std::max( maxWidth,
static_cast< double >(
frame->boundingRect().width() ) );
482 const double currentWidth = maxFrameWidth();
483 if ( !
qgsDoubleNear( currentWidth, mLastRenderedWidth ) && !mEvaluatedHtml.isEmpty() )
485 mCacheInvalidated =
true;
488 mBackgroundUpdateTimer->stop();
489 cancelRunningRenderJob(
false );
490 renderHtmlSynchronously();
495 mBackgroundUpdateTimer->start( 1 );
516 if (
mLayout->renderContext().isPreviewRender() )
520 if ( !mFetching && ( mCacheInvalidated || !
qgsDoubleNear( maxFrameWidth(), mLastRenderedWidth ) ) && !mRenderJob && !mBackgroundUpdateTimer->isActive() && !mEvaluatedHtml.isEmpty() )
522 mBackgroundUpdateTimer->start( 1 );
526 const QSize targetPixelSize = ( mSize * currentScaleFactor ).toSize();
527 const QImage previewImage = mPictureRasterizer->image( targetPixelSize );
529 if ( !previewImage.isNull() && !mSize.isEmpty() )
532 painter->scale( currentScaleFactor, currentScaleFactor );
533 painter->translate( -renderExtent.left(), -renderExtent.top() );
534 painter->setClipRect( renderExtent, Qt::IntersectClip );
535 painter->setRenderHint( QPainter::SmoothPixmapTransform,
true );
536 painter->drawImage( QRectF( QPointF( 0, 0 ), mSize ), previewImage );
538 else if ( mFetching || mRenderJob || mBackgroundUpdateTimer->isActive() || mPictureRasterizer->isRendering() )
543 painter->scale( currentScaleFactor, currentScaleFactor );
544 const QRectF frameRect( 0, 0, currentFrame->rect().width(), currentFrame->rect().height() );
545 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
546 painter->setPen( Qt::NoPen );
547 painter->drawRect( frameRect );
548 painter->setBrush( Qt::NoBrush );
551 messageFont.setPointSize( 12 );
552 painter->setFont( messageFont );
553 painter->setPen( QColor( 255, 255, 255, 255 ) );
554 painter->drawText( frameRect, Qt::AlignCenter, tr(
"Rendering HTML" ) );
562 waitForPendingFetch();
565 if ( mCacheInvalidated || mRenderJob || !
qgsDoubleNear( maxFrameWidth(), mLastRenderedWidth ) )
567 mBackgroundUpdateTimer->stop();
568 cancelRunningRenderJob(
false );
569 renderHtmlSynchronously();
573 painter->setRenderHint( QPainter::Antialiasing );
574 painter->setRenderHint( QPainter::SmoothPixmapTransform );
578 painter->translate( -renderExtent.left(), -renderExtent.top() );
579 painter->setClipRect( renderExtent, Qt::IntersectClip );
581 const double unitsPerCssPx = layoutUnitsPerCssPixel();
582 painter->scale( unitsPerCssPx, unitsPerCssPx );
586 Q_UNUSED( renderExtent )
587 if (
mLayout->renderContext().isPreviewRender() )
594 const QRectF painterRect = QRectF(
601 painter->setBrush( QBrush( QColor( 255, 125, 125, 125 ) ) );
602 painter->setPen( Qt::NoPen );
603 painter->drawRect( painterRect );
604 painter->setBrush( Qt::NoBrush );
606 painter->setPen( QColor( 200, 0, 0, 255 ) );
608 td.setTextWidth( painterRect.width() );
609 td.setHtml( u
"<span style=\"color: rgb(200,0,0);\"><b>%1</b><br>%2</span>"_s
610 .arg( tr(
"HTML rendering not available!" ), tr(
"The item cannot be rendered because this QGIS install was built without WebEngine or PDF4QT support." ) ) );
611 painter->setClipRect( painterRect );
612 QAbstractTextDocumentLayout::PaintContext ctx;
613 td.documentLayout()->draw( painter, ctx );
619double QgsLayoutItemHtml::layoutUnitsPerCssPixel()
const
627void QgsLayoutItemHtml::cancelRunningRenderJob(
bool block )
632 disconnect( mRenderJob.get(), &QgsLayoutItemHtmlRenderJob::finished,
this, &QgsLayoutItemHtml::htmlRenderFinished );
635 mRenderJob->cancelAndWait();
640 QgsLayoutItemHtmlRenderJob *oldJob = mRenderJob.release();
641 connect( oldJob, &QgsLayoutItemHtmlRenderJob::finished, oldJob, &QObject::deleteLater );
642 oldJob->cancelWithoutBlocking();
646void QgsLayoutItemHtml::updateFrames()
657 mPictureRasterizer->invalidate();
663 if ( c1.second < c2.second )
665 else if ( c1.second > c2.second )
667 else if ( c1.first > c2.first )
675 if ( mRenderedPage.isNull() || !mUseSmartBreaks )
680 const double unitsPerCssPx = layoutUnitsPerCssPixel();
682 const int idealPos =
static_cast< int >( yPos / unitsPerCssPx );
685 if ( idealPos >= mRenderedPage.height() )
690 const int maxSearchDistance =
static_cast< int >( mMaxBreakDistance / unitsPerCssPx );
696 bool currentPixelTransparent =
false;
697 bool previousPixelTransparent =
false;
699 QList< QPair<int, int> > candidates;
700 const int minRow = std::max( idealPos - maxSearchDistance, 0 );
701 for (
int candidateRow = idealPos; candidateRow >= minRow; --candidateRow )
704 currentColor = qRgba( 0, 0, 0, 0 );
706 for (
int col = 0; col < mRenderedPage.width(); ++col )
712 pixelColor = mRenderedPage.pixel( col, candidateRow );
713 currentPixelTransparent = qAlpha( pixelColor ) == 0;
714 if ( pixelColor != currentColor && !( currentPixelTransparent && previousPixelTransparent ) )
717 currentColor = pixelColor;
720 previousPixelTransparent = currentPixelTransparent;
722 candidates.append( qMakePair( candidateRow, changes ) );
726 std::sort( candidates.begin(), candidates.end(),
candidateSort );
733 const int maxCandidateRow = candidates[0].first;
734 int minCandidateRow = maxCandidateRow + 1;
735 const int minCandidateChanges = candidates[0].second;
737 QList< QPair<int, int> >::iterator it;
738 for ( it = candidates.begin(); it != candidates.end(); ++it )
740 if ( ( *it ).second != minCandidateChanges || ( *it ).first != minCandidateRow - 1 )
745 return ( minCandidateRow + ( maxCandidateRow - minCandidateRow ) / 2 ) * unitsPerCssPx;
747 minCandidateRow = ( *it ).first;
752 return candidates[0].first * unitsPerCssPx;
761 if ( mUseSmartBreaks && mRenderedPage.isNull() && !mRenderedPicture.isNull() && !mSize.isEmpty() )
763 const double unitsPerCssPx = layoutUnitsPerCssPixel();
764 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( mSize.width() / unitsPerCssPx ) ),
static_cast< int >( std::ceil( mSize.height() / unitsPerCssPx ) ) );
765 if ( !pageSizeCssPx.isEmpty() )
767 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
768 mRenderedPage.fill( Qt::transparent );
769 QPainter imagePainter( &mRenderedPage );
788 mUserStylesheet = stylesheet;
797 if ( mEnableUserStylesheet != stylesheetEnabled )
799 mEnableUserStylesheet = stylesheetEnabled;
807 return tr(
"<HTML frame>" );
812 htmlElem.setAttribute( u
"contentMode"_s, QString::number(
static_cast< int >( mContentMode ) ) );
813 htmlElem.setAttribute( u
"url"_s, mUrl.toString() );
814 htmlElem.setAttribute( u
"html"_s, mHtml );
815 htmlElem.setAttribute( u
"evaluateExpressions"_s, mEvaluateExpressions ?
"true" :
"false" );
816 htmlElem.setAttribute( u
"useSmartBreaks"_s, mUseSmartBreaks ?
"true" :
"false" );
817 htmlElem.setAttribute( u
"maxBreakDistance"_s, QString::number( mMaxBreakDistance ) );
818 htmlElem.setAttribute( u
"stylesheet"_s, mUserStylesheet );
819 htmlElem.setAttribute( u
"stylesheetEnabled"_s, mEnableUserStylesheet ?
"true" :
"false" );
827 if ( !contentModeOK )
831 mEvaluateExpressions = itemElem.attribute( u
"evaluateExpressions"_s, u
"true"_s ) ==
"true"_L1;
832 mUseSmartBreaks = itemElem.attribute( u
"useSmartBreaks"_s, u
"true"_s ) ==
"true"_L1;
833 mMaxBreakDistance = itemElem.attribute( u
"maxBreakDistance"_s, u
"10"_s ).toDouble();
834 mHtml = itemElem.attribute( u
"html"_s );
835 mUserStylesheet = itemElem.attribute( u
"stylesheet"_s );
836 mEnableUserStylesheet = itemElem.attribute( u
"stylesheetEnabled"_s, u
"false"_s ) ==
"true"_L1;
839 const QString urlString = itemElem.attribute( u
"url"_s );
840 if ( !urlString.isEmpty() )
852 return mFetching || mRenderJob || mBackgroundUpdateTimer->isActive() || ( mPictureRasterizer && mPictureRasterizer->isRendering() );
857 mExpressionFeature = feature;
858 mExpressionLayer = layer;
868 QgsLayoutItemMap *referenceMap =
mLayout->referenceMap();
870 mDistanceArea.setSourceCrs( referenceMap->
crs(),
mLayout->project()->transformContext() );
874 mDistanceArea.setEllipsoid(
mLayout->project()->ellipsoid() );
880 QgsJsonExporter exporter( layer );
881 exporter.setIncludeRelated(
true );
886 mAtlasFeatureProperties.clear();
890void QgsLayoutItemHtml::refreshExpressionContext()
892 QgsVectorLayer *vl =
nullptr;
897 vl =
mLayout->reportContext().layer();
898 feature =
mLayout->reportContext().feature();
901 setExpressionContext( feature, vl );
921QgsLayoutItemHtmlRenderJob::QgsLayoutItemHtmlRenderJob(
922 const QString &html,
const QUrl &baseUrl,
const QString &userStylesheet,
const QVariantMap &featureJson,
double frameWidthLayoutUnits,
double unitsPerCssPx
925 , mBaseUrl( baseUrl )
926 , mUserStylesheet( userStylesheet )
927 , mFeatureJson( featureJson )
928 , mFrameWidthLayoutUnits( frameWidthLayoutUnits )
929 , mUnitsPerCssPx( unitsPerCssPx )
931 connect( &mWatcher, &QFutureWatcher< void >::finished,
this, &QgsLayoutItemHtmlRenderJob::finished );
934void QgsLayoutItemHtmlRenderJob::start()
936 mWatcher.setFuture( QtConcurrent::run( [
this]() { run(); } ) );
939void QgsLayoutItemHtmlRenderJob::cancelWithoutBlocking()
944void QgsLayoutItemHtmlRenderJob::cancelAndWait()
947 mWatcher.waitForFinished();
950bool QgsLayoutItemHtmlRenderJob::isCanceled()
const
952 return mFeedback.isCanceled();
955void QgsLayoutItemHtmlRenderJob::run()
958 const double widthCssPx = mFrameWidthLayoutUnits / mUnitsPerCssPx;
960 QPainter painter( &mPicture );
961 QSizeF renderedSizeCssPx;
968 mSuccess =
QgsWebEnginePage::renderBlocking( mHtml, &painter, QRectF( 0, 0, widthCssPx, 9999 ), mErrorMessage, renderedSizeCssPx, htmlRenderSettings, &mFeedback );
971 if ( mFeedback.isCanceled() )
974 const double heightCssPx = renderedSizeCssPx.height();
975 mPicture.setBoundingRect( QRect( 0, 0,
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) ) );
977 mSize = QSizeF( mFrameWidthLayoutUnits, heightCssPx * mUnitsPerCssPx );
979 const QSize pageSizeCssPx(
static_cast< int >( std::ceil( widthCssPx ) ),
static_cast< int >( std::ceil( heightCssPx ) ) );
980 if ( !pageSizeCssPx.isEmpty() )
982 mRenderedPage = QImage( pageSizeCssPx, QImage::Format_ARGB32 );
983 mRenderedPage.fill( Qt::transparent );
984 QPainter imagePainter( &mRenderedPage );
990 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)