Skip to content

Commit b5ed7f3

Browse files
committedMar 10, 2019
[processing] Allow data type for numeric inputs to be specified
1 parent a0c74cf commit b5ed7f3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ def setupUi(self):
229229
self.parentCombo.setCurrentIndex(idx)
230230
idx += 1
231231
self.verticalLayout.addWidget(self.parentCombo)
232+
else:
233+
self.verticalLayout.addWidget(QLabel(self.tr('Number type')))
234+
self.type_combo = QComboBox()
235+
self.type_combo.addItem(self.tr('Float'), QgsProcessingParameterNumber.Double)
236+
self.type_combo.addItem(self.tr('Integer'), QgsProcessingParameterNumber.Integer)
237+
if self.param:
238+
self.type_combo.setCurrentIndex(self.type_combo.findData(self.param.dataType()))
239+
self.verticalLayout.addWidget(self.type_combo)
232240

233241
self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
234242
self.minTextBox = QLineEdit()
@@ -245,7 +253,7 @@ def setupUi(self):
245253
if self.param is not None:
246254
default = self.param.defaultValue()
247255
if self.param.dataType() == QgsProcessingParameterNumber.Integer:
248-
default = int(math.floor(default))
256+
default = int(math.floor(float(default)))
249257
if default:
250258
self.defaultTextBox.setText(str(default))
251259
self.verticalLayout.addWidget(self.defaultTextBox)
@@ -445,7 +453,9 @@ def accept(self):
445453
self.param.setParentParameterName(parent)
446454
elif (self.paramType == parameters.PARAMETER_NUMBER or
447455
isinstance(self.param, QgsProcessingParameterNumber)):
448-
self.param = QgsProcessingParameterNumber(name, description, QgsProcessingParameterNumber.Double,
456+
457+
type = self.type_combo.currentData()
458+
self.param = QgsProcessingParameterNumber(name, description, type,
449459
self.defaultTextBox.text())
450460
try:
451461
vmin = self.minTextBox.text().strip()

0 commit comments

Comments
 (0)
Please sign in to comment.