Skip to content
Permalink
Browse files

Refactor fields configuration in the modeler does not insist on layer

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 12, 2017
1 parent 3abff0e commit b619dcb00a74c1e802451d0f6947e834db3630ea
@@ -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

@@ -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
@@ -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()
@@ -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):
@@ -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()
@@ -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:

0 comments on commit b619dcb

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