Skip to content
Permalink
Browse files

Use parameter's name instead of description to save sql query

  • Loading branch information
pblottiere committed May 7, 2018
1 parent 610d99c commit e74e8360171581af56e9a2731eaa7ca2b014faea
Showing with 24 additions and 2 deletions.
  1. +24 −2 python/plugins/processing/algs/qgis/ui/ExecuteSQLWidget.py
@@ -82,7 +82,7 @@ def __init__(self, dialog):

def insert(self):
if self.mExpressionWidget.currentText():
exp = '[% {} %]'.format(self.mExpressionWidget.currentText())
exp = '[%{}%]'.format(self.mExpressionWidget.currentText())
self.mText.insertPlainText(exp)

def setValue(self, value):
@@ -95,6 +95,17 @@ def setValue(self, value):
and v.source() == QgsProcessingModelChildParameterSource.ExpressionText:
text = v.expressionText()

# replace parameter's name by expression (diverging after model save)
names = QgsExpression.referencedVariables(text)

strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterString, QgsProcessingParameterNumber], [])
model_params = [(self.dialog.resolveValueDescription(s), s) for s in strings]

for k, v in model_params:
if v.parameterName() in names:
text = text.replace('[% @{} %]'.format(v.parameterName()), '[% @{} %]'.format(k))

self.mText.setPlainText(text)

def value(self):
@@ -113,8 +124,19 @@ def _expressionValues(self, text):
model_params = [(self.dialog.resolveValueDescription(s), s) for s in strings]

variables = QgsExpression.referencedVariables(text)

# replace description by parameter's name (diverging after model save)
descriptions = QgsExpression.referencedVariables(text)

for k, v in model_params:
if k in descriptions:
text = text.replace('[% @{} %]'.format(k), '[% @{} %]'.format(v.parameterName()))

src = QgsProcessingModelChildParameterSource.fromExpressionText(text)

# add parameters currently used by the expression
expression_values = []
expression_values.append(QgsProcessingModelChildParameterSource.fromExpressionText(text))
expression_values.append(src)

for k, v in model_params:
if k in variables:

0 comments on commit e74e836

Please sign in to comment.
You can’t perform that action at this time.