Skip to content

Commit eb360e0

Browse files
committedMar 26, 2014
[processing] fixed display ad handling of optional table fields in parameters panel
1 parent cbeb528 commit eb360e0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed
 

‎python/plugins/processing/algs/ftools/MeanCoords.py‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ def defineCharacteristics(self):
5050
[ParameterVector.VECTOR_TYPE_ANY]))
5151
self.addParameter(ParameterTableField(self.WEIGHT, 'Weight field',
5252
MeanCoords.POINTS,
53-
ParameterTableField.DATA_TYPE_NUMBER))
53+
ParameterTableField.DATA_TYPE_NUMBER,
54+
optional = True))
5455
self.addParameter(ParameterTableField(self.UID, 'Unique ID field',
5556
MeanCoords.POINTS,
56-
ParameterTableField.DATA_TYPE_NUMBER))
57+
ParameterTableField.DATA_TYPE_NUMBER,
58+
optional = True))
5759

5860
self.addOutput(OutputVector(MeanCoords.OUTPUT, 'Result'))
5961

@@ -63,8 +65,17 @@ def processAlgorithm(self, progress):
6365
weightField = self.getParameterValue(self.WEIGHT)
6466
uniqueField = self.getParameterValue(self.UID)
6567

66-
weightIndex = layer.fieldNameIndex(weightField)
67-
uniqueIndex = layer.fieldNameIndex(uniqueField)
68+
print weightField, uniqueField
69+
70+
if weightField is None:
71+
weightIndex = -1
72+
else:
73+
weightIndex = layer.fieldNameIndex(weightField)
74+
75+
if uniqueField is None:
76+
uniqueIndex = -1
77+
else:
78+
uniqueIndex = layer.fieldNameIndex(uniqueField)
6879

6980
fieldList = [QgsField('MEAN_X', QVariant.Double, '', 24, 15),
7081
QgsField('MEAN_Y', QVariant.Double, '', 24, 15),
@@ -82,7 +93,10 @@ def processAlgorithm(self, progress):
8293
for feat in features:
8394
current += 1
8495
progress.setPercentage(current * total)
85-
clazz = str(feat.attributes()[uniqueIndex]).strip()
96+
if uniqueIndex == -1:
97+
clazz = "Single class"
98+
else:
99+
clazz = str(feat.attributes()[uniqueIndex]).strip()
86100
if weightIndex == -1:
87101
weight = 1.00
88102
else:

‎python/plugins/processing/gui/AlgorithmExecutionDialog.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def setParamValue(self, param, widget):
190190
elif isinstance(param, ParameterRange):
191191
return param.setValue(widget.getValue())
192192
if isinstance(param, ParameterTableField):
193+
if param.optional and widget.currentIndex() == 0:
194+
return param.setValue(None)
193195
return param.setValue(widget.currentText())
194196
elif isinstance(param, ParameterMultipleInput):
195197
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:

‎python/plugins/processing/gui/ParametersPanel.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ def getWidgetFromParameter(self, param):
268268
else:
269269
layers = dataobjects.getTables()
270270
if len(layers) > 0:
271+
if param.optional:
272+
item.addItem("[not set]")
271273
item.addItems(self.getFields(layers[0], param.datatype))
272274
elif isinstance(param, ParameterSelection):
273275
item = QtGui.QComboBox()

0 commit comments

Comments
 (0)
Please sign in to comment.