29#include "moc_qgsqmlwidgetwrapper.cpp"
31using namespace Qt::StringLiterals;
52 if ( attributeChanged )
54 if ( mRequiresFormScope )
56 mFormFeature.setAttribute( attribute, newValue );
63 return new QQuickWidget( parent );
68 mWidget = qobject_cast<QQuickWidget *>( editor );
74 if ( !mQmlFile.open() )
80 QUrl sourceUrl = QUrl::fromLocalFile( mQmlFile.fileName() );
81 sourceUrl.setQuery( u
"t=%1"_s.arg( QDateTime::currentSecsSinceEpoch() ) );
82 mWidget->setSource( sourceUrl );
93 mWidget->engine()->clearComponentCache();
100 if ( mQmlCode == qmlCode )
108 const thread_local QRegularExpression
109 expRe( QStringLiteral( R
"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
110 QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
111 while ( !ok && matchIt.hasNext() )
113 const QRegularExpressionMatch match = matchIt.next();
117 mRequiresFormScope = ok;
119 if ( !mQmlFile.open() )
125 mQmlFile.resize( 0 );
126 mQmlFile.write( mQmlCode.toUtf8() );
130void QgsQmlWidgetWrapper::setQmlContext()
145 QmlExpression *qmlExpression =
new QmlExpression();
146 qmlExpression->setExpressionContext( expressionContext );
148 mWidget->rootContext()->setContextProperty(
"expression", qmlExpression );
157 mFormFeature = feature;
165 mExpressionContext = context;
168QVariant QmlExpression::evaluate(
const QString &expression )
const
171 exp.
prepare( &mExpressionContext );
172 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...