Skip to content
Permalink
Browse files

[processing] Fix random selection count parameter

Remove a bunch of manual "max" values for numeric parameters
where the maximum just represents a 'large number' and not a real
constraint, and let the default parameter max value handling kick in instead.

In the case of random selection the max value exceeded the possible
range for integers in spin boxes and broke the widget.

Fixes #20015
  • Loading branch information
nyalldawson committed Oct 5, 2018
1 parent e3e9297 commit 8cad2a6e16698d0dfcfc876d3ddd1cc9e2a0499b
@@ -62,7 +62,7 @@ def initAlgorithm(self, config=None):
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 0.00, 999999.99))
1, False, 0.00))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))

def name(self):
@@ -66,7 +66,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.PIXEL_SIZE,
self.tr('Pixel size'),
QgsProcessingParameterNumber.Double,
0.1, False, 0.01, 999))
0.1, False, 0.01))
self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Constant value'),
QgsProcessingParameterNumber.Double,
@@ -99,7 +99,7 @@ def initAlgorithm(self, config=None):

self.addParameter(QgsProcessingParameterDistance(self.RADIUS,
self.tr('Radius'),
100.0, self.INPUT, False, 0.0, 9999999999.99))
100.0, self.INPUT, False, 0.0))

radius_field_param = QgsProcessingParameterField(self.RADIUS_FIELD,
self.tr('Radius from field'),
@@ -113,9 +113,9 @@ def initAlgorithm(self, config=None):

class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):

def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None, maxValue=None,
def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None,
default=None, optional=False):
QgsProcessingParameterNumber.__init__(self, name, description, QgsProcessingParameterNumber.Double, default, optional, minValue, maxValue)
QgsProcessingParameterNumber.__init__(self, name, description, QgsProcessingParameterNumber.Double, default, optional, minValue)
self.parent_layer = parent_layer
self.radius_param = radius_param
self.radius_field_param = radius_field_param
@@ -130,7 +130,6 @@ def clone(self):
radius_param=self.RADIUS,
radius_field_param=self.RADIUS_FIELD,
minValue=0.0,
maxValue=9999999999,
default=0.1)
pixel_size_param.setMetadata({
'widget_wrapper': {
@@ -64,7 +64,7 @@ def initAlgorithm(self, config=None):
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 0.00, 999999.99))
1, False, 0.00))
self.addParameter(QgsProcessingParameterNumber(self.AZIMUTH,
self.tr('Azimuth (horizontal angle)'), QgsProcessingParameterNumber.Double,
300, False, 0, 360))
@@ -69,7 +69,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.BOUNDARY_LAYER,
self.tr('Boundary layer'), [QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterNumber(self.STEP,
self.tr('Step'), type=QgsProcessingParameterNumber.Double, minValue=0.0, maxValue=999999999.999999, defaultValue=100.0))
self.tr('Step'), type=QgsProcessingParameterNumber.Double, minValue=0.0, defaultValue=100.0))
self.addParameter(QgsProcessingParameterBoolean(self.USE_PERCENTAGE,
self.tr('Use % of area instead of absolute value'), defaultValue=False))

@@ -101,7 +101,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterEnum(self.MATRIX_TYPE,
self.tr('Output matrix type'), options=self.mat_types, defaultValue=0))
self.addParameter(QgsProcessingParameterNumber(self.NEAREST_POINTS,
self.tr('Use only the nearest (k) target points'), type=QgsProcessingParameterNumber.Integer, minValue=0, maxValue=9999, defaultValue=0))
self.tr('Use only the nearest (k) target points'), type=QgsProcessingParameterNumber.Integer, minValue=0, defaultValue=0))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Distance matrix'), QgsProcessing.TypeVectorPoint))

@@ -66,7 +66,7 @@ def initAlgorithm(self, config=None):

self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Number/percentage of selected features'), QgsProcessingParameterNumber.Integer,
10, False, 0.0, 999999999999.0))
10, False, 0.0))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Extracted (random)')))

@@ -72,7 +72,7 @@ def initAlgorithm(self, config=None):

self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Number/percentage of selected features'), QgsProcessingParameterNumber.Integer,
10, False, 0.0, 999999999999.0))
10, False, 0.0))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Extracted (random stratified)')))

@@ -80,7 +80,7 @@ def initAlgorithm(self, config=None):
self.tr('Method'), self.methods, False, 0))
self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Number/percentage of selected features'), QgsProcessingParameterNumber.Integer,
10, False, 0.0, 999999999999.0))
10, False, 0.0))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Selected (random)')))

def name(self):
@@ -86,7 +86,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Number/percentage of selected features'),
QgsProcessingParameterNumber.Integer,
10, False, 0.0, 999999999999.0))
10, False, 0.0))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Selected (stratified random)')))

def name(self):
@@ -71,15 +71,14 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterEnum(self.SHAPE,
self.tr('Buffer shape'), options=self.shapes))
self.addParameter(QgsProcessingParameterDistance(self.WIDTH, self.tr('Width'), parentParameterName=self.INPUT,
minValue=0.0000001, maxValue=999999999.0, defaultValue=1.0))
minValue=0.0000001, defaultValue=1.0))
self.addParameter(QgsProcessingParameterDistance(self.HEIGHT, self.tr('Height'), parentParameterName=self.INPUT,
minValue=0.0000001, maxValue=999999999.0, defaultValue=1.0))
minValue=0.0000001, defaultValue=1.0))
self.addParameter(QgsProcessingParameterNumber(self.ROTATION, self.tr('Rotation'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=360.0, optional=True))
self.addParameter(QgsProcessingParameterNumber(self.SEGMENTS,
self.tr('Number of segments'),
minValue=1,
maxValue=999999999,
defaultValue=36))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
@@ -90,7 +90,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.SEGMENTS,
self.tr('Number of segments'),
minValue=1,
maxValue=999999999,
defaultValue=36))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
@@ -81,9 +81,9 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
self.tr('Input extent'), optional=False))
self.addParameter(QgsProcessingParameterDistance(self.SPACING,
self.tr('Point spacing/count'), 100, self.CRS, False, 0.000001, 999999999.999999999))
self.tr('Point spacing/count'), 100, self.CRS, False, 0.000001))
self.addParameter(QgsProcessingParameterDistance(self.INSET,
self.tr('Initial inset from corner (LH side)'), 0.0, self.CRS, False, 0.0, 9999.9999))
self.tr('Initial inset from corner (LH side)'), 0.0, self.CRS, False, 0.0))
self.addParameter(QgsProcessingParameterBoolean(self.RANDOMIZE,
self.tr('Apply random offset to point spacing'), False))
self.addParameter(QgsProcessingParameterBoolean(self.IS_SPACING,
@@ -108,7 +108,7 @@ def initAlgorithm(self, config=None):
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), type=QgsProcessingParameterNumber.Double,
minValue=0.00, maxValue=999999.99, defaultValue=1.0))
minValue=0.00, defaultValue=1.0))
self.addParameter(QgsProcessingParameterBoolean(self.AUTO_COLORS,
self.tr('Generate relief classes automatically'),
defaultValue=False))
@@ -62,7 +62,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'),
QgsProcessingParameterNumber.Double,
1, False, 0.00, 999999.99))
1, False, 0.00))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Ruggedness')))

def name(self):
@@ -118,7 +118,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.TRAVEL_COST,
self.tr('Travel cost (distance for "Shortest", time for "Fastest")'),
QgsProcessingParameterNumber.Double,
0.0, False, 0, 99999999.99))
0.0, False, 0))

params = []
params.append(QgsProcessingParameterField(self.DIRECTION_FIELD,
@@ -147,10 +147,10 @@ def initAlgorithm(self, config=None):
params.append(QgsProcessingParameterNumber(self.DEFAULT_SPEED,
self.tr('Default speed (km/h)'),
QgsProcessingParameterNumber.Double,
5.0, False, 0, 99999999.99))
5.0, False, 0))
params.append(QgsProcessingParameterDistance(self.TOLERANCE,
self.tr('Topology tolerance'),
0.0, self.INPUT, False, 0, 99999999.99))
0.0, self.INPUT, False, 0))
params.append(QgsProcessingParameterBoolean(self.INCLUDE_BOUNDS,
self.tr('Include upper/lower bound points'),
defaultValue=False))
@@ -115,7 +115,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.TRAVEL_COST,
self.tr('Travel cost (distance for "Shortest", time for "Fastest")'),
QgsProcessingParameterNumber.Double,
0.0, False, 0, 99999999.99))
0.0, False, 0))

params = []
params.append(QgsProcessingParameterField(self.DIRECTION_FIELD,
@@ -144,10 +144,10 @@ def initAlgorithm(self, config=None):
params.append(QgsProcessingParameterNumber(self.DEFAULT_SPEED,
self.tr('Default speed (km/h)'),
QgsProcessingParameterNumber.Double,
5.0, False, 0, 99999999.99))
5.0, False, 0))
params.append(QgsProcessingParameterDistance(self.TOLERANCE,
self.tr('Topology tolerance'),
0.0, self.INPUT, False, 0, 99999999.99))
0.0, self.INPUT, False, 0))
params.append(QgsProcessingParameterBoolean(self.INCLUDE_BOUNDS,
self.tr('Include upper/lower bound points'),
defaultValue=False))
@@ -62,7 +62,7 @@ def initAlgorithm(self, config=None):
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 0.00, 999999.99))
1, False, 0.00))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Slope')))

def name(self):
@@ -64,7 +64,7 @@ def initAlgorithm(self, config=None):
QgsProcessing.TypeVectorPolygon]))

self.addParameter(QgsProcessingParameterDistance(self.TOLERANCE, self.tr('Tolerance'), parentParameterName=self.INPUT,
minValue=0.00000001, maxValue=9999999999, defaultValue=10.0))
minValue=0.00000001, defaultValue=10.0))

self.modes = [self.tr('Prefer aligning nodes, insert extra vertices where required'),
self.tr('Prefer closest point, insert extra vertices where required'),
@@ -82,7 +82,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterDistance(self.MIN_DISTANCE,
self.tr('Minimum distance between features'),
parentParameterName=self.INPUT, minValue=0.0,
maxValue=999999999.0, defaultValue=0.0))
defaultValue=0.0))
balance_by = [self.tr('By feature count'),
self.tr('By assigned area'),
self.tr('By distance between colors')]
@@ -78,7 +78,7 @@ def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterNumber(
self.BUFFER, self.tr('Buffer region (% of extent)'),
minValue=0.0, maxValue=9999999999, defaultValue=0.0))
minValue=0.0, defaultValue=0.0))
self.addParameter(
QgsProcessingParameterFeatureSink(
self.OUTPUT, self.tr('Voronoi polygons'),

0 comments on commit 8cad2a6

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