Skip to content
Permalink
Browse files

[processing] Guess sensible step sizes for float spin boxes

  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent ffd9707 commit 86231d79fa8a9592cedb8356c8500567cf70d7bb
Showing with 15 additions and 0 deletions.
  1. +15 −0 python/plugins/processing/gui/NumberInputPanel.py
@@ -29,6 +29,7 @@

from PyQt4 import uic

from math import log10, floor
from processing.gui.NumberInputDialog import NumberInputDialog

pluginPath = os.path.split(os.path.dirname(__file__))[0]
@@ -45,6 +46,11 @@ def __init__(self, number, minimum, maximum, isInteger):
self.isInteger = isInteger
if self.isInteger:
self.spnValue.setDecimals(0)
else:
#Guess reasonable step value
if (maximum == 0 or maximum) and (minimum == 0 or minimum):
self.spnValue.setSingleStep(self.calculateStep(minimum, maximum))

if maximum == 0 or maximum:
self.spnValue.setMaximum(maximum)
else:
@@ -66,3 +72,12 @@ def showNumberInputDialog(self):

def getValue(self):
return self.spnValue.value()

def calculateStep(self, minimum, maximum):
valueRange = maximum - minimum
if valueRange <= 1.0:
step = valueRange / 10.0
# round to 1 significant figure
return round(step, -int(floor(log10(step))))
else:
return 1.0

0 comments on commit 86231d7

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