mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[processing] Guess sensible step sizes for float spin boxes
This commit is contained in:
parent
ffd9707516
commit
86231d79fa
@ -29,6 +29,7 @@ import os
|
||||
|
||||
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 @@ class NumberInputPanel(BASE, WIDGET):
|
||||
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 @@ class NumberInputPanel(BASE, WIDGET):
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user