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
104 expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
105 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
106 while ( !ok && matchIt.hasNext() )
108 const QRegularExpressionMatch match = matchIt.next();
112 mRequiresFormScope = ok;
114 if ( !mQmlFile.open() )
120 mQmlFile.resize( 0 );
121 mQmlFile.write( mQmlCode.toUtf8() );
126void QgsQmlWidgetWrapper::setQmlContext()
141 QmlExpression *qmlExpression =
new QmlExpression();
142 qmlExpression->setExpressionContext( expressionContext );
144 mWidget->rootContext()->setContextProperty(
"expression", qmlExpression );
153 mFormFeature = feature;
161 mExpressionContext = context;
164QVariant QmlExpression::evaluate(
const QString &expression )
const
167 exp.
prepare( &mExpressionContext );
168 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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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...