Skip to content

Commit

Permalink
[processing] Guess sensible step sizes for float spin boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent ffd9707 commit 86231d7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/plugins/processing/gui/NumberInputPanel.py
Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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.