28#include "moc_qgsqmlwidgetwrapper.cpp"
49 if ( attributeChanged )
51 if ( mRequiresFormScope )
53 mFormFeature.setAttribute( attribute, newValue );
60 return new QQuickWidget( parent );
65 mWidget = qobject_cast<QQuickWidget *>( editor );
71 if ( !mQmlFile.open() )
77 mWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );
88 mWidget->engine()->clearComponentCache();
95 if ( mQmlCode == qmlCode )
103 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
104 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
105 while ( !ok && matchIt.hasNext() )
107 const QRegularExpressionMatch match = matchIt.next();
111 mRequiresFormScope = ok;
113 if ( !mQmlFile.open() )
119 mQmlFile.resize( 0 );
120 mQmlFile.write( mQmlCode.toUtf8() );
125void QgsQmlWidgetWrapper::setQmlContext()
140 QmlExpression *qmlExpression =
new QmlExpression();
141 qmlExpression->setExpressionContext( expressionContext );
143 mWidget->rootContext()->setContextProperty(
"expression", qmlExpression );
152 mFormFeature = feature;
160 mExpressionContext = context;
163QVariant QmlExpression::evaluate(
const QString &expression )
const
166 exp.
prepare( &mExpressionContext );
167 return exp.
evaluate( &mExpressionContext );
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.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
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...