Skip to content

Commit aa17df1

Browse files
author
Médéric RIBREUX
committedNov 4, 2017
* Add new GRASS 7.2 algorithms.
* Fix ParameterRange GUI. * Fix Multiple values Enum support.
1 parent 6c81895 commit aa17df1

21 files changed

+536
-221
lines changed
 

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ def processInputs(self, parameters, context):
399399
layerName = '{}_{}'.format(paramName, idx)
400400
# Add a raster layer
401401
if layer.type() == QgsMapLayer.RasterLayer:
402-
self.exportRasterLayer(layerName, layer)
402+
self.loadRasterLayer(layerName, layer)
403403
# Add a vector layer
404404
elif layer.type() == QgsMapLayer.VectorLayer:
405-
self.exportVectorLayer(layerName, layer)
405+
self.loadVectorLayer(layerName, layer)
406406

407407
self.postInputs()
408408

@@ -531,7 +531,7 @@ def processCommand(self, parameters, context, delOutputs=False):
531531
self.parameterAsFileOutput(
532532
parameters, outName, context))
533533
# For folders destination
534-
if isinstance(out, QgsProcessingParameterFolderDestination):
534+
elif isinstance(out, QgsProcessingParameterFolderDestination):
535535
# We need to add a unique temporary basename
536536
uniqueBasename = outName + self.uniqueSuffix
537537
command += ' {}={}'.format(outName, uniqueBasename)

‎python/plugins/processing/algs/grass7/TODO.md

Lines changed: 202 additions & 178 deletions
Large diffs are not rendered by default.

‎python/plugins/processing/algs/grass7/description/r.aspect.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎python/plugins/processing/algs/grass7/description/r.median.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
r.out.mat
2+
Exports a GRASS raster to a binary MAT-File
3+
Raster (r.*)
4+
QgsProcessingParameterRasterLayer|input|Input raster|None|False
5+
QgsProcessingParameterFileDestination|output|MAT File|Mat files (*.mat)|None|False
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
r.out.mpeg
2+
Converts raster map series to MPEG movie
3+
Raster (r.*)
4+
QgsProcessingParameterMultipleLayers|view1|Name of input raster map(s) for view no.1|5|None|False
5+
QgsProcessingParameterMultipleLayers|view2|Name of input raster map(s) for view no.2|5|None|True
6+
QgsProcessingParameterMultipleLayers|view3|Name of input raster map(s) for view no.3|5|None|True
7+
QgsProcessingParameterMultipleLayers|view4|Name of input raster map(s) for view no.4|5|None|True
8+
QgsProcessingParameterNumber|quality|Quality factor (1 = highest quality, lowest compression)|QgsProcessingParameterNumber.Integer|3|True|1|5
9+
QgsProcessingParameterFileDestination|output|MPEG file|MPEG files (*.mpeg;*.mpg)|None|False
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
r.out.pov
2+
Converts a raster map layer into a height-field file for POV-Ray
3+
Raster (r.*)
4+
QgsProcessingParameterRasterLayer|input|Input raster|None|False
5+
QgsProcessingParameterNumber|hftype|Height-field type (0=actual heights 1=normalized)|QgsProcessingParameterNumber.Integer|0|True|0|1
6+
QgsProcessingParameterNumber|bias|Elevation bias|QgsProcessingParameterNumber.Double|None|True|None|None
7+
QgsProcessingParameterNumber|scale|Vertical scaling factor|QgsProcessingParameterNumber.Double|None|True|None|None
8+
QgsProcessingParameterFileDestination|output|Name of output povray file (TGA height field file)|Povray files (*.pov)|None|False

‎python/plugins/processing/algs/grass7/description/r.out.ppm.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Converts a raster layer to a PPM image file at the pixel resolution of the curre
33
Raster (r.*)
44
QgsProcessingParameterRasterLayer|input|Input raster layer|None|False
55
QgsProcessingParameterBoolean|-g|Output greyscale instead of color|True
6-
QgsProcessingParameterFileDestination|output|PPM|Txt files (*.txt)|None|False
6+
QgsProcessingParameterFileDestination|output|PPM|PPM files (*.ppm)|None|False
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
r.out.ppm3
2+
Converts 3 GRASS raster layers (R,G,B) to a PPM image file
3+
Raster (r.*)
4+
QgsProcessingParameterRasterLayer|red|Name of raster map to be used for <red>|None|False
5+
QgsProcessingParameterRasterLayer|green|Name of raster map to be used for <green>|None|False
6+
QgsProcessingParameterRasterLayer|blue|Name of raster map to be used for <blue>|None|False
7+
QgsProcessingParameterBoolean|-c|Add comments to describe the region|False|True
8+
QgsProcessingParameterFileDestination|output|Name for new PPM file|PPM files (*.ppm)|None|False
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
r.out.vtk
2+
Converts raster maps into the VTK-ASCII format
3+
Raster (r.*)
4+
QgsProcessingParameterMultipleLayers|input|Input raster|3|None|False
5+
QgsProcessingParameterRasterLayer|elevation|Input elevation raster map|None|True
6+
QgsProcessingParameterNumber|null|Value to represent no data cell|QgsProcessingParameterNumber.Double|-9999.99|True|None|None
7+
QgsProcessingParameterNumber|z|Constant elevation (if no elevation map is specified)|QgsProcessingParameterNumber.Double|0.0|True|None|None
8+
QgsProcessingParameterMultipleLayers|rgbmaps|Three (r,g,b) raster maps to create RGB values|3|None|True
9+
QgsProcessingParameterMultipleLayers|vectormaps|Three (x,y,z) raster maps to create vector values|3|None|True
10+
QgsProcessingParameterNumber|zscale|Scale factor for elevation|QgsProcessingParameterNumber.Double|1.0|True|None|None
11+
QgsProcessingParameterNumber|precision|Number of significant digits|QgsProcessingParameterNumber.Integer|12|False|0|20
12+
*QgsProcessingParameterBoolean|-p|Create VTK point data instead of VTK cell data|False|True
13+
*QgsProcessingParameterBoolean|-s|Use structured grid for elevation (not recommended)|False|True
14+
*QgsProcessingParameterBoolean|-t|Use polydata-trianglestrips for elevation grid creation|False|True
15+
*QgsProcessingParameterBoolean|-v|Use polydata-vertices for elevation grid creation|False|True
16+
*QgsProcessingParameterBoolean|-o|Scale factor affects the origin (if no elevation map is given)|False|True
17+
*QgsProcessingParameterBoolean|-c|Correct the coordinates to match the VTK-OpenGL precision|False|True
18+
QgsProcessingParameterFileDestination|output|VTK File|Vtk files (*.vtk)|None|False
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
r.proj
2+
Re-projects a vector map from one location to the current location
3+
Raster (r.*)
4+
QgsProcessingParameterRasterLayer|input|Input raster to reproject|None|False
5+
QgsProcessingParameterCrs|crs|New coordinate reference system|None|False
6+
QgsProcessingParameterEnum|method|Interpolation method to use|nearest;bilinear;bicubic;lanczos;bilinear_f;bicubic_f;lanczos_f|False|0|True
7+
QgsProcessingParameterNumber|memory|Maximum memory to be used (in MB)|QgsProcessingParameterNumber.Integer|300|True|0|None
8+
QgsProcessingParameterNumber|resolution|Resolution of output raster map|QgsProcessingParameterNumber.Double|1.0|True|0.0|None
9+
*QgsProcessingParameterBoolean|-n|Do not perform region cropping optimization|False|True
10+
QgsProcessingParameterRasterDestination|output|Reprojected raster

‎python/plugins/processing/algs/grass7/description/r.slope.aspect.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ r.slope.aspect
22
Generates raster layers of slope, aspect, curvatures and partial derivatives from a elevation raster layer.
33
Raster (r.*)
44
QgsProcessingParameterRasterLayer|elevation|Elevation|None|False
5-
QgsProcessingParameterEnum|format|Format for reporting the slope|degrees;percent
6-
QgsProcessingParameterEnum|precision|Type of output aspect and slope layer|FCELL;CELL;DCELL
5+
QgsProcessingParameterEnum|format|Format for reporting the slope|degrees;percent|False|0|True
6+
QgsProcessingParameterEnum|precision|Type of output aspect and slope layer|FCELL;CELL;DCELL|False|0|True
77
QgsProcessingParameterBoolean|-a|Do not align the current region to the elevation layer|True
88
QgsProcessingParameterNumber|zscale|Multiplicative factor to convert elevation units to meters|QgsProcessingParameterNumber.Double|1.0|False|None|None
99
QgsProcessingParameterNumber|min_slope|Minimum slope val. (in percent) for which aspect is computed|QgsProcessingParameterNumber.Double|0.0|False|None|None
10-
QgsProcessingParameterRasterDestination|slope|Slope
11-
QgsProcessingParameterRasterDestination|aspect|Aspect
12-
QgsProcessingParameterRasterDestination|pcurvature|Profile curvature
13-
QgsProcessingParameterRasterDestination|tcurvature|Tangential curvature
14-
QgsProcessingParameterRasterDestination|dx|First order partial derivative dx (E-W slope)
15-
QgsProcessingParameterRasterDestination|dy|First order partial derivative dy (N-S slope)
16-
QgsProcessingParameterRasterDestination|dxx|Second order partial derivative dxx
17-
QgsProcessingParameterRasterDestination|dyy|Second order partial derivative dyy
18-
QgsProcessingParameterRasterDestination|dxy|Second order partial derivative dxy
10+
QgsProcessingParameterRasterDestination|slope|Slope|None|True
11+
QgsProcessingParameterRasterDestination|aspect|Aspect|None|True
12+
QgsProcessingParameterRasterDestination|pcurvature|Profile curvature|None|True
13+
QgsProcessingParameterRasterDestination|tcurvature|Tangential curvature|None|True
14+
QgsProcessingParameterRasterDestination|dx|First order partial derivative dx (E-W slope)|None|True
15+
QgsProcessingParameterRasterDestination|dy|First order partial derivative dy (N-S slope)|None|True
16+
QgsProcessingParameterRasterDestination|dxx|Second order partial derivative dxx|None|True
17+
QgsProcessingParameterRasterDestination|dyy|Second order partial derivative dyy|None|True
18+
QgsProcessingParameterRasterDestination|dxy|Second order partial derivative dxy|None|True
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
r.stats.zonal
2+
Calculates category or object oriented statistics (accumulator-based statistics)
3+
Raster (r.*)
4+
QgsProcessingParameterRasterLayer|base|Base raster|None|False
5+
QgsProcessingParameterRasterLayer|cover|Cover raster|None|False
6+
QgsProcessingParameterEnum|method|Method of object-based statistic|count;sum;min;max;range;average;avedev;variance;stddev;skewness;kurtosis;variance2;stddev2;skewness2;kurtosis2|False|0
7+
*QgsProcessingParameterBoolean|-c|Cover values extracted from the category labels of the cover map|False|True
8+
*QgsProcessingParameterBoolean|-r|Create reclass map with statistics as category labels|False|True
9+
QgsProcessingParameterRasterDestination|output|Resultant raster
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
v.decimate
2+
Decimates a point cloud
3+
Vector (v.*)
4+
QgsProcessingParameterVectorLayer|input|Input vector|1|None|False
5+
QgsProcessingParameterRange|zrange|Filter range for z data (min,max)|QgsProcessingParameterNumber.Integer|None|True
6+
QgsProcessingParameterString|cats|Category values|None|False|True
7+
QgsProcessingParameterNumber|skip|Throw away every n-th point|QgsProcessingParameterNumber.Integer|None|True|0|None
8+
QgsProcessingParameterNumber|preserve|Preserve only every n-th point|QgsProcessingParameterNumber.Integer|None|True|0|None
9+
QgsProcessingParameterNumber|offset|Skip first n points|QgsProcessingParameterNumber.Integer|None|True|0|None
10+
QgsProcessingParameterNumber|limit|Copy only n points|QgsProcessingParameterNumber.Integer|None|True|0|None
11+
QgsProcessingParameterNumber|zdiff|Minimal difference of z values|QgsProcessingParameterNumber.Double|None|True|None|None
12+
QgsProcessingParameterNumber|cell_limit|Preserve only n points per grid cell|QgsProcessingParameterNumber.Integer|None|True|0|None
13+
*QgsProcessingParameterBoolean|-g|Apply grid-based decimation|False|True
14+
*QgsProcessingParameterBoolean|-f|Use only first point in grid cell during grid-based decimation|False|True
15+
*QgsProcessingParameterBoolean|-c|Only one point per cat in grid cell|False|True
16+
*QgsProcessingParameterBoolean|-z|Use z in grid decimation|False|True
17+
*QgsProcessingParameterBoolean|-x|Store only the coordinates, throw away categories|False|True
18+
*QgsProcessingParameterBoolean|-b|Do not build topology|False|True
19+
QgsProcessingParameterVectorDestination|output|Output vector map
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
v.in.e00
2+
Imports E00 file into a vector map
3+
Vector (v.*)
4+
QgsProcessingParameterFile|input|Name of input E00 file|0|e00|None|False
5+
QgsProcessingParameterEnum|type|Input feature type|point;line;area|True|0|True
6+
QgsProcessingParameterVectorDestination|output|Name of output vector
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
v.proj
2+
Re-projects a vector map from one location to the current location
3+
Vector (v.*)
4+
QgsProcessingParameterVectorLayer|input|Input vector to reproject|-1|None|False
5+
QgsProcessingParameterCrs|crs|New coordinate reference system|None|False
6+
QgsProcessingParameterNumber|smax|Maximum segment length in meters in output vector map|QgsProcessingParameterNumber.Double|10000.0|True|0.0|None
7+
*QgsProcessingParameterBoolean|-z|Assume z coordinate is ellipsoidal height and transform if possible|False|True
8+
*QgsProcessingParameterBoolean|-w|Disable wrapping to -180,180 for latlon output|False|True
9+
QgsProcessingParameterVectorDestination|output|Output vector map
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
r_proj.py
6+
---------
7+
Date : October 2017
8+
Copyright : (C) 2017 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'October 2017'
22+
__copyright__ = '(C) 2017, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from qgis.core import QgsProcessingParameterString
29+
from ..Grass7Utils import isWindows
30+
31+
32+
def processInputs(alg, parameters, context):
33+
# Grab the projection from the input vector layer
34+
layer = alg.parameterAsLayer(parameters, 'input', context)
35+
layerCrs = layer.crs().toProj4()
36+
37+
# Creates a new location with this Crs
38+
newLocation = 'newProj{}'.format(alg.uniqueSuffix)
39+
alg.commands.append('g.proj proj4="{}" location={}'.format(
40+
layerCrs, newLocation))
41+
42+
# Go to the newly created location
43+
alg.commands.append('g.mapset mapset=PERMANENT location={}'.format(
44+
newLocation))
45+
46+
# Import the layer
47+
alg.loadRasterLayerFromParameter(
48+
'input', parameters, context, False)
49+
50+
# Go back to default location
51+
alg.commands.append('g.mapset mapset=PERMANENT location=temp_location')
52+
53+
# Grab the projected Crs
54+
crs = alg.parameterAsCrs(parameters, 'crs', context)
55+
alg.commands.append('g.proj -c proj4="{}"'.format(
56+
crs.toProj4(), newLocation))
57+
58+
# Remove crs parameter
59+
alg.removeParameter('crs')
60+
61+
# Add the location parameter with proper value
62+
location = QgsProcessingParameterString(
63+
'location',
64+
'new location',
65+
'newProj{}'.format(alg.uniqueSuffix)
66+
)
67+
alg.addParameter(location)
68+
69+
# And set the region
70+
grassName = alg.exportedLayers['input']
71+
# We use the shell to capture the results from r.proj -g
72+
if isWindows():
73+
# TODO: make some tests under a non POSIX shell
74+
alg.commands.append('set regVar=')
75+
alg.commands.append('for /f "delims=" %%a in (\'r.proj -g input="{}" location="{}"\') do @set theValue=%%a'.format(
76+
grassName, newLocation))
77+
alg.commands.append('g.region -a %regVar%')
78+
else:
79+
alg.commands.append('g.region -a $(r.proj -g input="{}" location="{}")'.format(
80+
grassName, newLocation))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
v_proj.py
6+
---------
7+
Date : November 2017
8+
Copyright : (C) 2017 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'November 2017'
22+
__copyright__ = '(C) 2017, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from qgis.core import QgsProcessingParameterString
29+
30+
31+
def processInputs(alg, parameters, context):
32+
# Grab the projection from the input vector layer
33+
layer = alg.parameterAsLayer(parameters, 'input', context)
34+
alg.setSessionProjectionFromLayer(layer)
35+
layerCrs = layer.crs().toProj4()
36+
37+
# Creates a new location with this Crs
38+
newLocation = 'newProj{}'.format(alg.uniqueSuffix)
39+
alg.commands.append('g.proj proj4="{}" location={}'.format(
40+
layerCrs, newLocation))
41+
42+
# Go to the newly created location
43+
alg.commands.append('g.mapset mapset=PERMANENT location={}'.format(
44+
newLocation))
45+
46+
# Import the layer
47+
alg.loadVectorLayerFromParameter(
48+
'input', parameters, context, False)
49+
50+
# Go back to default location
51+
alg.commands.append('g.mapset mapset=PERMANENT location=temp_location')
52+
53+
# Grab the projected Crs
54+
crs = alg.parameterAsCrs(parameters, 'crs', context)
55+
alg.commands.append('g.proj -c proj4="{}"'.format(
56+
crs.toProj4(), newLocation))
57+
58+
# Remove crs parameter
59+
alg.removeParameter('crs')
60+
61+
# Add the location parameter with proper value
62+
location = QgsProcessingParameterString(
63+
'location',
64+
'new location',
65+
'newProj{}'.format(alg.uniqueSuffix)
66+
)
67+
alg.addParameter(location)

‎python/plugins/processing/core/parameters.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
QgsProcessingParameterMatrix,
5959
QgsProcessingParameterFile,
6060
QgsProcessingParameterField,
61-
QgsProcessingParameterRasterDestination, # NOQA
61+
QgsProcessingParameterRasterDestination,
6262
QgsProcessingParameterVectorDestination,
6363
QgsProcessingParameterFileDestination,
6464
QgsProcessingParameterFolderDestination,
@@ -630,7 +630,11 @@ def getParameterFromString(s):
630630
if len(params) > 3:
631631
params[3] = True if params[3].lower() == 'true' else False
632632
if len(params) > 4:
633-
params[4] = int(params[4])
633+
# For multiple values; default value is a list of int
634+
if params[3] == True:
635+
params[4] = [int(v) for v in params[4].split(',')]
636+
else:
637+
params[4] = int(params[4])
634638
if len(params) > 5:
635639
params[5] = True if params[5].lower() == 'true' else False
636640
elif clazz == QgsProcessingParameterFeatureSource:
@@ -684,6 +688,9 @@ def getParameterFromString(s):
684688
elif clazz == QgsProcessingParameterFolderDestination:
685689
if len(params) > 3:
686690
params[3] = True if params[3].lower() == 'true' else False
691+
elif clazz == QgsProcessingParameterRasterDestination:
692+
if len(params) > 3:
693+
params[3] = True if params[3].lower() == 'true' else False
687694
elif clazz == QgsProcessingParameterVectorDestination:
688695
if len(params) > 2:
689696
if params[2].lower().endswith('point'):

‎python/plugins/processing/gui/RangePanel.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import os
2929

3030
from qgis.PyQt import uic
31+
from qgis.PyQt.QtCore import pyqtSignal
32+
from qgis.PyQt.QtWidgets import QDialog
33+
34+
from qgis.core import QgsProcessingParameterNumber
3135

3236
pluginPath = os.path.split(os.path.dirname(__file__))[0]
3337
WIDGET, BASE = uic.loadUiType(
@@ -36,26 +40,52 @@
3640

3741
class RangePanel(BASE, WIDGET):
3842

43+
hasChanged = pyqtSignal()
44+
3945
def __init__(self, param):
4046
super(RangePanel, self).__init__(None)
4147
self.setupUi(self)
4248

43-
self.isInteger = param.isInteger
44-
if self.isInteger:
49+
self.param = param
50+
# Integer or Double range
51+
if self.param.dataType() == QgsProcessingParameterNumber.Integer:
4552
self.spnMin.setDecimals(0)
4653
self.spnMax.setDecimals(0)
4754

48-
values = param.default.split(',')
49-
minVal = float(values[0])
50-
maxVal = float(values[1])
51-
self.spnMin.setValue(minVal)
52-
self.spnMax.setValue(maxVal)
55+
if param.defaultValue() is not None:
56+
self.setValue(param.defaultValue())
57+
values = self.getValues()
58+
59+
# Spin range logic
60+
self.spnMin.valueChanged.connect(lambda: self.setMinMax())
61+
self.spnMax.valueChanged.connect(lambda: self.setMaxMin())
5362

54-
self.spnMin.setMaximum(maxVal)
55-
self.spnMin.setMinimum(minVal)
63+
def setMinMax(self):
64+
values = self.getValues()
65+
if values[0] >= values[1]:
66+
self.spnMax.setValue(values[0])
67+
self.hasChanged.emit()
5668

57-
self.spnMax.setMaximum(maxVal)
58-
self.spnMax.setMinimum(minVal)
69+
def setMaxMin(self):
70+
values = self.getValues()
71+
if values[0] >= values[1]:
72+
self.spnMin.setValue(values[1])
73+
self.hasChanged.emit()
5974

6075
def getValue(self):
6176
return '{},{}'.format(self.spnMin.value(), self.spnMax.value())
77+
78+
def getValues(self):
79+
value = self.getValue()
80+
if value:
81+
return [float(a) for a in value.split(',')]
82+
83+
def setValue(self, value):
84+
try:
85+
values = value.split(',')
86+
minVal = float(values[0])
87+
maxVal = float(values[1])
88+
self.spnMin.setValue(float(minVal))
89+
self.spnMax.setValue(float(maxVal))
90+
except:
91+
return

‎python/plugins/processing/gui/wrappers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
from qgis.utils import iface
9898

9999
from processing.gui.NumberInputPanel import NumberInputPanel, ModellerNumberInputPanel
100+
from processing.gui.RangePanel import RangePanel
100101
from processing.modeler.MultilineTextPanel import MultilineTextPanel
101102
from processing.gui.PointSelectionPanel import PointSelectionPanel
102103
from processing.core.parameters import (ParameterBoolean,
@@ -700,6 +701,23 @@ def value(self):
700701
return self.widget.getValue()
701702

702703

704+
class RangeWidgetWrapper(WidgetWrapper):
705+
706+
def createWidget(self):
707+
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
708+
widget = RangePanel(self.param)
709+
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
710+
return widget
711+
#else:
712+
# return ModellerNumberInputPanel(self.param, self.dialog)
713+
714+
def setValue(self, value):
715+
self.widget.setValue(value)
716+
717+
def value(self):
718+
return self.widget.getValue()
719+
720+
703721
class MapLayerWidgetWrapper(WidgetWrapper):
704722
NOT_SELECTED = '[Not selected]'
705723

@@ -1463,6 +1481,7 @@ def validator(v):
14631481

14641482

14651483
class WidgetWrapperFactory:
1484+
14661485
"""
14671486
Factory for parameter widget wrappers
14681487
"""
@@ -1529,6 +1548,8 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
15291548
wrapper = BandWidgetWrapper
15301549
elif param.type() == 'layer':
15311550
wrapper = MapLayerWidgetWrapper
1551+
elif param.type() == 'range':
1552+
wrapper = RangeWidgetWrapper
15321553
else:
15331554
assert False, param.type()
15341555
return wrapper(param, dialog, row, col)

0 commit comments

Comments
 (0)
Please sign in to comment.