42 mWidget = qobject_cast<QgsWebView *>( editor );
47 mWidget->setHtml( mHtmlCode.replace(
"\n",
" " ) );
51 const int horizontalDpi = mWidget->logicalDpiX();
53 mWidget->setZoomFactor( horizontalDpi / 96.0 );
56 connect( page, &QWebPage::contentsChanged,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
57 connect( page, &QWebPage::loadFinished,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
72void QgsHtmlWidgetWrapper::checkGeometryNeeds()
80 NeedsGeometryEvaluator evaluator;
84 evaluator.setExpressionContext( expressionContext );
86 auto frame = webView.page()->mainFrame();
87 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [ frame, &evaluator ]
89 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), &evaluator );
92 webView.setHtml( mHtmlCode );
94 mNeedsGeometry = evaluator.needsGeometry();
100 checkGeometryNeeds();
103void QgsHtmlWidgetWrapper::setHtmlContext( )
117 HtmlExpression *htmlExpression =
new HtmlExpression();
118 htmlExpression->setExpressionContext( expressionContext );
119 auto frame = mWidget->page()->mainFrame();
120 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [ = ]
122 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), htmlExpression );
125 mWidget->setHtml( mHtmlCode );
129void QgsHtmlWidgetWrapper::fixHeight()
132 const int docHeight { page->mainFrame()->contentsSize().height() };
133 mWidget->setFixedHeight( docHeight );
148 return mNeedsGeometry;
155 mExpressionContext = context;
158QString HtmlExpression::evaluate(
const QString &expression )
const
161 exp.
prepare( &mExpressionContext );
162 return exp.evaluate( &mExpressionContext ).toString();
165void NeedsGeometryEvaluator::evaluate(
const QString &expression )
168 exp.
prepare( &mExpressionContext );
169 mNeedsGeometry |= exp.needsGeometry();
174 mExpressionContext = context;
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
This class contains context information for attribute editor widgets.
QString attributeFormModeString() const
Returns given attributeFormMode as string.
QgsFeature parentFormFeature() const
Returns the feature of the currently edited parent form in its actual state.
static QgsExpressionContextScope * parentFormScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current parent attribute form/tab...
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table form...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
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.
Represents a vector layer which manages a vector based data sets.
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...