47 if ( attributeChanged )
49 if ( mRequiresFormScope )
58 return new QQuickWidget( parent );
63 mWidget = qobject_cast<QQuickWidget *>( editor );
69 if ( !mQmlFile.open() )
75 mWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );
86 mWidget->engine()->clearComponentCache();
93 if ( mQmlCode == qmlCode )
101 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
102 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
103 while ( !ok && matchIt.hasNext() )
105 const QRegularExpressionMatch match = matchIt.next();
109 mRequiresFormScope = ok;
111 if ( !mQmlFile.open() )
117 mQmlFile.resize( 0 );
118 mQmlFile.write( mQmlCode.toUtf8() );
123void QgsQmlWidgetWrapper::setQmlContext( )
138 QmlExpression *qmlExpression =
new QmlExpression();
139 qmlExpression->setExpressionContext( expressionContext );
141 mWidget->rootContext()->setContextProperty(
"expression", qmlExpression );
150 mFormFeature = feature;
158 mExpressionContext = context;
161QVariant QmlExpression::evaluate(
const QString &expression )
const
164 exp.
prepare( &mExpressionContext );
165 return exp.
evaluate( &mExpressionContext );
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.
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...
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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...