18#include "moc_qgsqmlwidgetwrapper.cpp"
48 if ( attributeChanged )
50 if ( mRequiresFormScope )
59 return new QQuickWidget( parent );
64 mWidget = qobject_cast<QQuickWidget *>( editor );
70 if ( !mQmlFile.open() )
76 mWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );
87 mWidget->engine()->clearComponentCache();
94 if ( mQmlCode == qmlCode )
102 const thread_local QRegularExpression expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
103 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
104 while ( !ok && matchIt.hasNext() )
106 const QRegularExpressionMatch match = matchIt.next();
110 mRequiresFormScope = ok;
112 if ( !mQmlFile.open() )
118 mQmlFile.resize( 0 );
119 mQmlFile.write( mQmlCode.toUtf8() );
124void QgsQmlWidgetWrapper::setQmlContext( )
139 QmlExpression *qmlExpression =
new QmlExpression();
140 qmlExpression->setExpressionContext( expressionContext );
142 mWidget->rootContext()->setContextProperty(
"expression", qmlExpression );
151 mFormFeature = feature;
159 mExpressionContext = context;
162QVariant QmlExpression::evaluate(
const QString &expression )
const
165 exp.
prepare( &mExpressionContext );
166 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...