42 mWidget = qobject_cast<QgsWebView *>( editor );
47 mWidget->setHtml( mHtmlCode );
50 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
51 const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
53 const int horizontalDpi = mWidget->logicalDpiX();
56 mWidget->setZoomFactor( horizontalDpi / 96.0 );
59 connect( page, &QWebPage::contentsChanged,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
60 connect( page, &QWebPage::loadFinished,
this, [ = ](
bool ) { fixHeight(); }, Qt::ConnectionType::UniqueConnection );
79 void QgsHtmlWidgetWrapper::setHtmlContext( )
93 HtmlExpression *htmlExpression =
new HtmlExpression();
94 htmlExpression->setExpressionContext( expressionContext );
95 mWidget->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled,
true );
96 auto frame = mWidget->page()->mainFrame();
97 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [ = ]
99 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), htmlExpression );
102 mWidget->setHtml( mHtmlCode );
106 void QgsHtmlWidgetWrapper::fixHeight()
109 int docHeight { page->mainFrame()->contentsSize().height() };
110 mWidget->setFixedHeight( docHeight );
126 mExpressionContext = context;
129 QString HtmlExpression::evaluate(
const QString &expression )
const
132 exp.
prepare( &mExpressionContext );
133 return exp.
evaluate( &mExpressionContext ).toString();