42 mWidget = qobject_cast<QgsWebView *>( editor );
47 mWidget->setHtml( mHtmlCode.replace(
"\n",
"\\n" ) );
50 const int horizontalDpi = mWidget->logicalDpiX();
52 mWidget->setZoomFactor( horizontalDpi / 96.0 );
55 connect( page, &QWebPage::contentsChanged,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
56 connect( page, &QWebPage::loadFinished,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
71 void QgsHtmlWidgetWrapper::checkGeometryNeeds()
79 NeedsGeometryEvaluator evaluator;
83 evaluator.setExpressionContext( expressionContext );
85 auto frame = webView.page()->mainFrame();
86 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [ frame, &evaluator ]
88 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), &evaluator );
91 webView.setHtml( mHtmlCode );
93 mNeedsGeometry = evaluator.needsGeometry();
102 void QgsHtmlWidgetWrapper::setHtmlContext( )
116 HtmlExpression *htmlExpression =
new HtmlExpression();
117 htmlExpression->setExpressionContext( expressionContext );
118 auto frame = mWidget->page()->mainFrame();
119 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [ = ]
121 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), htmlExpression );
124 mWidget->setHtml( mHtmlCode );
128 void QgsHtmlWidgetWrapper::fixHeight()
131 const int docHeight { page->mainFrame()->contentsSize().height() };
132 mWidget->setFixedHeight( docHeight );
147 return mNeedsGeometry;
154 mExpressionContext = context;
157 QString HtmlExpression::evaluate(
const QString &expression )
const
160 exp.
prepare( &mExpressionContext );
161 return exp.
evaluate( &mExpressionContext ).toString();
164 void NeedsGeometryEvaluator::evaluate(
const QString &expression )
167 exp.
prepare( &mExpressionContext );
173 mExpressionContext = context;