18#include "moc_qgshtmlwidgetwrapper.cpp"
45 if ( attributeChanged )
47 if ( mRequiresFormScope )
61 mWidget = qobject_cast<QgsWebView *>( editor );
66 mWidget->setHtml( mHtmlCode.replace(
"\n",
" " ) );
70 const int horizontalDpi = mWidget->logicalDpiX();
72 mWidget->setZoomFactor( horizontalDpi / 96.0 );
75 connect( page, &QWebPage::contentsChanged,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
76 connect( page, &QWebPage::loadFinished,
this, &QgsHtmlWidgetWrapper::fixHeight, Qt::ConnectionType::UniqueConnection );
91void QgsHtmlWidgetWrapper::checkGeometryNeeds()
99 NeedsGeometryEvaluator evaluator;
105 evaluator.setExpressionContext( expressionContext );
108 auto frame = webView.page()->mainFrame();
109 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [frame, &evaluator] {
110 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), &evaluator );
113 webView.setHtml( mHtmlCode );
115 mNeedsGeometry = evaluator.needsGeometry();
120 mHtmlCode = htmlCode;
123 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
124 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mHtmlCode );
125 while ( !ok && matchIt.hasNext() )
127 const QRegularExpressionMatch match = matchIt.next();
131 mRequiresFormScope = ok;
133 checkGeometryNeeds();
136void QgsHtmlWidgetWrapper::setHtmlContext()
151 HtmlExpression *htmlExpression =
new HtmlExpression();
152 htmlExpression->setExpressionContext( expressionContext );
153 auto frame = mWidget->page()->mainFrame();
154 connect( frame, &QWebFrame::javaScriptWindowObjectCleared, frame, [=] {
155 frame->addToJavaScriptWindowObject( QStringLiteral(
"expression" ), htmlExpression );
158 mWidget->setHtml( mHtmlCode );
162void QgsHtmlWidgetWrapper::fixHeight()
165 const int docHeight { page->mainFrame()->contentsSize().height() };
166 mWidget->setFixedHeight( docHeight );
176 mFormFeature = feature;
182 return mNeedsGeometry;
189 mExpressionContext = context;
192QString HtmlExpression::evaluate(
const QString &expression )
const
195 exp.
prepare( &mExpressionContext );
196 return exp.evaluate( &mExpressionContext ).toString();
199void NeedsGeometryEvaluator::evaluate(
const QString &expression )
202 exp.
prepare( &mExpressionContext );
203 mNeedsGeometry |= exp.needsGeometry();
208 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...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
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 ...