26#include "moc_qgshtmlwidgetwrapper.cpp"
47 if ( attributeChanged )
49 if ( mRequiresFormScope )
51 mFormFeature.setAttribute( attribute, newValue );
63 mWidget = qobject_cast<QgsWebView *>( editor );
68 mWidget->setHtml( mHtmlCode.replace(
"\n",
" " ) );
72 const int horizontalDpi = mWidget->logicalDpiX();
74 mWidget->setZoomFactor( horizontalDpi / 96.0 );
77 connect( page, &QWebPage::contentsChanged,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
78 connect( page, &QWebPage::loadFinished,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
93void QgsHtmlWidgetWrapper::checkGeometryNeeds()
101 NeedsGeometryEvaluator evaluator;
107 evaluator.setExpressionContext( expressionContext );
110 auto frame = webView.page()->mainFrame();
111 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, &evaluator] {
112 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), &evaluator );
115 webView.setHtml( mHtmlCode );
117 mNeedsGeometry = evaluator.needsGeometry();
122 mHtmlCode = htmlCode;
125 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
126 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mHtmlCode );
127 while ( !ok && matchIt.hasNext() )
129 const QRegularExpressionMatch match = matchIt.next();
133 mRequiresFormScope = ok;
135 checkGeometryNeeds();
138void QgsHtmlWidgetWrapper::setHtmlContext()
153 HtmlExpression *htmlExpression =
new HtmlExpression();
154 htmlExpression->setExpressionContext( expressionContext );
155 auto frame = mWidget->page()->mainFrame();
156 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, htmlExpression] {
157 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), htmlExpression );
160 mWidget->setHtml( mHtmlCode );
164void QgsHtmlWidgetWrapper::fixHeight()
166 QWebPage *page = mWidget->page();
167 const int docHeight { page->mainFrame()->contentsSize().height() };
168 mWidget->setFixedHeight( docHeight );
178 mFormFeature = feature;
184 return mNeedsGeometry;
191 mExpressionContext = context;
194QString HtmlExpression::evaluate(
const QString &expression )
const
197 exp.
prepare( &mExpressionContext );
198 return exp.
evaluate( &mExpressionContext ).toString();
201void NeedsGeometryEvaluator::evaluate(
const QString &expression )
204 exp.
prepare( &mExpressionContext );
210 mExpressionContext = context;
A collection of stubs to mimic the API of a QWebPage on systems where QtWebkit is not available.
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.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QVariant evaluate()
Evaluate the feature and return the result.
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 dataset.
QgsExpressionContext createExpressionContext() const final
This method needs to be reimplemented in all classes which implement this interface and return an exp...
A collection of stubs to mimic the API of QWebView on systems where the real library is not available...