Skip to content

Commit 8f9f975

Browse files
committedSep 21, 2018
[processing] Show complete expression context in expression builder
for pre-calculated expressions Correctly exposes ALL the variables and functions available for use in pre-calculated expressions so that users actually know they can use these in their models!
1 parent 8e49e94 commit 8f9f975

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
 

‎python/gui/auto_generated/processing/qgsprocessingmodelerparameterwidget.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414

15-
class QgsProcessingModelerParameterWidget : QWidget
15+
class QgsProcessingModelerParameterWidget : QWidget, QgsExpressionContextGenerator
1616
{
1717
%Docstring
1818

@@ -117,6 +117,9 @@ Returns the current value of the parameter.
117117
.. seealso:: :py:func:`setWidgetValue`
118118
%End
119119

120+
virtual QgsExpressionContext createExpressionContext() const;
121+
122+
120123
};
121124

122125

‎src/gui/processing/qgsprocessingmodelerparameterwidget.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsprocessingguiregistry.h"
2323
#include "models/qgsprocessingmodelalgorithm.h"
2424
#include "qgsgui.h"
25+
#include "qgsexpressioncontext.h"
2526
#include <QHBoxLayout>
2627
#include <QToolButton>
2728
#include <QStackedWidget>
@@ -172,7 +173,23 @@ QgsProcessingModelChildParameterSource QgsProcessingModelerParameterWidget::valu
172173

173174
QgsExpressionContext QgsProcessingModelerParameterWidget::createExpressionContext() const
174175
{
175-
return QgsExpressionContext();
176+
QgsExpressionContext c = mContext.expressionContext();
177+
if ( mModel )
178+
{
179+
QgsExpressionContextScope *algorithmScope = QgsExpressionContextUtils::processingAlgorithmScope( mModel->childAlgorithm( mChildId ).algorithm(), QVariantMap(), mContext );
180+
c << algorithmScope;
181+
QgsExpressionContextScope *childScope = mModel->createExpressionContextScopeForChildAlgorithm( mChildId, mContext, QVariantMap(), QVariantMap() );
182+
c << childScope;
183+
184+
QStringList highlightedVariables = childScope->variableNames();
185+
QStringList highlightedFunctions = childScope->functionNames();
186+
highlightedVariables += algorithmScope->variableNames();
187+
highlightedFunctions += algorithmScope->functionNames();
188+
c.setHighlightedVariables( highlightedVariables );
189+
c.setHighlightedFunctions( highlightedFunctions );
190+
}
191+
192+
return c;
176193
}
177194

178195
void QgsProcessingModelerParameterWidget::sourceMenuAboutToShow()

‎src/gui/processing/qgsprocessingmodelerparameterwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class GUI_EXPORT QgsProcessingModelerParameterWidget : public QWidget, public Qg
143143
*/
144144
virtual QgsProcessingModelChildParameterSource value() const;
145145

146+
QgsExpressionContext createExpressionContext() const override;
147+
146148
private slots:
147149

148150
void sourceMenuAboutToShow();

0 commit comments

Comments
 (0)
Please sign in to comment.