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] { frame->addToJavaScriptWindowObject( u
"expression"_s, &evaluator ); } );
104 webView.setHtml( mHtmlCode );
106 mNeedsGeometry = evaluator.needsGeometry();
111 mHtmlCode = htmlCode;
114 const thread_local QRegularExpression
115 expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
116 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mHtmlCode );
117 while ( !ok && matchIt.hasNext() )
119 const QRegularExpressionMatch match = matchIt.next();
123 mRequiresFormScope = ok;
125 checkGeometryNeeds();
128void QgsHtmlWidgetWrapper::setHtmlContext()
143 HtmlExpression *htmlExpression =
new HtmlExpression();
144 htmlExpression->setExpressionContext( expressionContext );
145 auto frame = mWidget->page()->mainFrame();
146 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, htmlExpression] { frame->addToJavaScriptWindowObject( u
"expression"_s, htmlExpression ); } );
148 mWidget->setHtml( mHtmlCode );
157 mFormFeature = feature;
163 return mNeedsGeometry;
170 mExpressionContext = context;
173QString HtmlExpression::evaluate(
const QString &expression )
const
176 exp.
prepare( &mExpressionContext );
177 return exp.
evaluate( &mExpressionContext ).toString();
180void NeedsGeometryEvaluator::evaluate(
const QString &expression )
183 exp.
prepare( &mExpressionContext );
189 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...