27#include "moc_qgshtmlwidgetwrapper.cpp"
29using namespace Qt::StringLiterals;
50 if ( attributeChanged )
52 if ( mRequiresFormScope )
54 mFormFeature.setAttribute( attribute, newValue );
66 mWidget = qobject_cast<QgsWebView *>( editor );
71 mWidget->setHtml( mHtmlCode.replace(
"\n",
" " ) );
84void QgsHtmlWidgetWrapper::checkGeometryNeeds()
92 NeedsGeometryEvaluator evaluator;
98 evaluator.setExpressionContext( expressionContext );
101 auto frame = webView.page()->mainFrame();
102 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, &evaluator] {
103 frame->addToJavaScriptWindowObject( u
"expression"_s, &evaluator );
106 webView.setHtml( mHtmlCode );
108 mNeedsGeometry = evaluator.needsGeometry();
113 mHtmlCode = htmlCode;
116 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
117 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mHtmlCode );
118 while ( !ok && matchIt.hasNext() )
120 const QRegularExpressionMatch match = matchIt.next();
124 mRequiresFormScope = ok;
126 checkGeometryNeeds();
129void QgsHtmlWidgetWrapper::setHtmlContext()
144 HtmlExpression *htmlExpression =
new HtmlExpression();
145 htmlExpression->setExpressionContext( expressionContext );
146 auto frame = mWidget->page()->mainFrame();
147 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, htmlExpression] {
148 frame->addToJavaScriptWindowObject( u
"expression"_s, htmlExpression );
151 mWidget->setHtml( mHtmlCode );
160 mFormFeature = feature;
166 return mNeedsGeometry;
173 mExpressionContext = context;
176QString HtmlExpression::evaluate(
const QString &expression )
const
179 exp.
prepare( &mExpressionContext );
180 return exp.
evaluate( &mExpressionContext ).toString();
183void NeedsGeometryEvaluator::evaluate(
const QString &expression )
186 exp.
prepare( &mExpressionContext );
192 mExpressionContext = context;
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...