|
20 | 20 | #include "qgsprocessingparameters.h"
|
21 | 21 | #include "qgsprocessingmodelerparameterwidget.h"
|
22 | 22 | #include "qgspropertyoverridebutton.h"
|
| 23 | +#include "qgsexpressioncontext.h" |
| 24 | +#include "models/qgsprocessingmodelalgorithm.h" |
23 | 25 | #include <QLabel>
|
24 | 26 | #include <QHBoxLayout>
|
25 | 27 |
|
@@ -101,6 +103,7 @@ QWidget *QgsAbstractProcessingParameterWidgetWrapper::createWrappedWidget( QgsPr
|
101 | 103 | hLayout->addWidget( mPropertyButton );
|
102 | 104 | mPropertyButton->init( 0, QgsProperty(), mParameterDefinition->dynamicPropertyDefinition() );
|
103 | 105 | mPropertyButton->registerEnabledWidget( mWidget, false );
|
| 106 | + mPropertyButton->registerExpressionContextGenerator( this ); |
104 | 107 |
|
105 | 108 | wrappedWidget = new QWidget();
|
106 | 109 | wrappedWidget->setLayout( hLayout );
|
@@ -211,6 +214,47 @@ void QgsAbstractProcessingParameterWidgetWrapper::postInitialize( const QList<Qg
|
211 | 214 | }
|
212 | 215 | }
|
213 | 216 |
|
| 217 | +QgsExpressionContext QgsAbstractProcessingParameterWidgetWrapper::createExpressionContext() const |
| 218 | +{ |
| 219 | + // Get a processing context to start with |
| 220 | + QgsProcessingContext *context = nullptr; |
| 221 | + std::unique_ptr< QgsProcessingContext > tmpContext; |
| 222 | + if ( mProcessingContextGenerator ) |
| 223 | + context = mProcessingContextGenerator->processingContext(); |
| 224 | + |
| 225 | + if ( !context ) |
| 226 | + { |
| 227 | + tmpContext = qgis::make_unique< QgsProcessingContext >(); |
| 228 | + context = tmpContext.get(); |
| 229 | + } |
| 230 | + |
| 231 | + QgsExpressionContext c = context->expressionContext(); |
| 232 | + |
| 233 | + if ( mPropertyButton->vectorLayer() ) |
| 234 | + c << QgsExpressionContextUtils::layerScope( mPropertyButton->vectorLayer() ); |
| 235 | + |
| 236 | + if ( mWidgetContext.model() ) |
| 237 | + { |
| 238 | + const QgsProcessingAlgorithm *alg = nullptr; |
| 239 | + if ( mWidgetContext.model()->childAlgorithms().contains( mWidgetContext.modelChildAlgorithmId() ) ) |
| 240 | + alg = mWidgetContext.model()->childAlgorithm( mWidgetContext.modelChildAlgorithmId() ).algorithm(); |
| 241 | + |
| 242 | + QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( alg, QVariantMap(), *context ); |
| 243 | + c << algorithmScope; |
| 244 | + QgsExpressionContextScope *childScope = mWidgetContext.model()->createExpressionContextScopeForChildAlgorithm( mWidgetContext.modelChildAlgorithmId(), *context, QVariantMap(), QVariantMap() ); |
| 245 | + c << childScope; |
| 246 | + |
| 247 | + QStringList highlightedVariables = childScope->variableNames(); |
| 248 | + QStringList highlightedFunctions = childScope->functionNames(); |
| 249 | + highlightedVariables += algorithmScope->variableNames(); |
| 250 | + highlightedFunctions += algorithmScope->functionNames(); |
| 251 | + c.setHighlightedVariables( highlightedVariables ); |
| 252 | + c.setHighlightedFunctions( highlightedFunctions ); |
| 253 | + } |
| 254 | + |
| 255 | + return c; |
| 256 | +} |
| 257 | + |
214 | 258 | void QgsAbstractProcessingParameterWidgetWrapper::parentLayerChanged( QgsAbstractProcessingParameterWidgetWrapper *wrapper )
|
215 | 259 | {
|
216 | 260 | if ( wrapper )
|
|
0 commit comments