Skip to content

Commit

Permalink
Refactor fields configuration in the modeler does not insist on layer
Browse files Browse the repository at this point in the history
Inside the modeler, there is not enough knowledge about the layer on
which the refactor fields algorithm will run.
Let's be graceful with error messages here therefore.
  • Loading branch information
m-kuhn committed Dec 14, 2017
1 parent 3abff0e commit b619dcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Expand Up @@ -137,8 +137,8 @@ def prepareAlgorithm(self, parameters, context, feedback):
if expression.hasParserError():
raise QgsProcessingException(
self.tr(u'Parser error in expression "{}": {}')
.format(str(expression.expression()),
str(expression.parserErrorString())))
.format(expression.expression(),
expression.parserErrorString()))
self.expressions.append(expression)
return True

Expand All @@ -160,8 +160,8 @@ def processFeature(self, feature, context, feedback):
if expression.hasEvalError():
raise QgsProcessingException(
self.tr(u'Evaluation error in expression "{}": {}')
.format(str(expression.expression()),
str(expression.parserErrorString())))
.format(expression.expression(),
expression.parserErrorString()))
attributes.append(value)
feature.setAttributes(attributes)
self._row_number += 1
Expand Down
9 changes: 6 additions & 3 deletions python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
Expand Up @@ -225,8 +225,7 @@ def loadLayerFields(self, layer):

self._mapping = []
if layer is not None:
dp = layer.dataProvider()
for field in dp.fields():
for field in layer.fields():
self._mapping.append(self.newField(field))

self.endResetModel()
Expand Down Expand Up @@ -263,6 +262,7 @@ def createEditor(self, parent, option, index):
editor.registerExpressionContextGenerator(index.model().contextGenerator())
editor.fieldChanged.connect(self.on_expression_fieldChange)
editor.setAutoFillBackground(True)
editor.setAllowEvalErrors(self.parent().dialogType == DIALOG_MODELER)
return editor

def setEditorData(self, editor, index):
Expand Down Expand Up @@ -303,6 +303,7 @@ def __init__(self, parent=None):

self.layerCombo.setAllowEmptyLayer(True)
self.layerCombo.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.dialogType = None

def configure(self):
self.model = FieldsMappingModel()
Expand Down Expand Up @@ -472,7 +473,9 @@ def __init__(self, *args, **kwargs):
self._layer = None

def createWidget(self):
return FieldsMappingPanel()
panel = FieldsMappingPanel()
panel.dialogType = self.dialogType
return panel

def postInitialize(self, wrappers):
for wrapper in wrappers:
Expand Down

0 comments on commit b619dcb

Please sign in to comment.