Skip to content

Commit

Permalink
[processing] Allow data type for numeric inputs to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 10, 2019
1 parent a0c74cf commit b5ed7f3
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ def setupUi(self):
self.parentCombo.setCurrentIndex(idx)
idx += 1
self.verticalLayout.addWidget(self.parentCombo)
else:
self.verticalLayout.addWidget(QLabel(self.tr('Number type')))
self.type_combo = QComboBox()
self.type_combo.addItem(self.tr('Float'), QgsProcessingParameterNumber.Double)
self.type_combo.addItem(self.tr('Integer'), QgsProcessingParameterNumber.Integer)
if self.param:
self.type_combo.setCurrentIndex(self.type_combo.findData(self.param.dataType()))
self.verticalLayout.addWidget(self.type_combo)

self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
self.minTextBox = QLineEdit()
Expand All @@ -245,7 +253,7 @@ def setupUi(self):
if self.param is not None:
default = self.param.defaultValue()
if self.param.dataType() == QgsProcessingParameterNumber.Integer:
default = int(math.floor(default))
default = int(math.floor(float(default)))
if default:
self.defaultTextBox.setText(str(default))
self.verticalLayout.addWidget(self.defaultTextBox)
Expand Down Expand Up @@ -445,7 +453,9 @@ def accept(self):
self.param.setParentParameterName(parent)
elif (self.paramType == parameters.PARAMETER_NUMBER or
isinstance(self.param, QgsProcessingParameterNumber)):
self.param = QgsProcessingParameterNumber(name, description, QgsProcessingParameterNumber.Double,

type = self.type_combo.currentData()
self.param = QgsProcessingParameterNumber(name, description, type,
self.defaultTextBox.text())
try:
vmin = self.minTextBox.text().strip()
Expand Down

0 comments on commit b5ed7f3

Please sign in to comment.