Skip to content

Commit

Permalink
Adapt more code to c++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent ef59d0c commit 189f804
Show file tree
Hide file tree
Showing 41 changed files with 306 additions and 332 deletions.
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

__revision__ = '$Format:%H$'

from qgis.core import QgsProcessingParameterDefinition

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterString
Expand Down Expand Up @@ -111,7 +113,7 @@ def __init__(self):
None, False, True))

for param in params:
param.isAdvanced = True
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)

self.addOutput(OutputDirectory(self.OUTPUTDIR,
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

__revision__ = '$Format:%H$'

from qgis.core import QgsProcessingParameterDefinition

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterSelection
Expand Down Expand Up @@ -107,7 +109,7 @@ def __init__(self):
None, False, True))

for param in params:
param.isAdvanced = True
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)

self.addOutput(OutputDirectory(self.TARGETDIR,
Expand Down
29 changes: 15 additions & 14 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
QgsApplication,
QgsProcessingUtils,
QgsMessageLog,
QgsProcessingAlgorithm)
QgsProcessingAlgorithm,
QgsProcessingParameterDefinition)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
Expand Down Expand Up @@ -183,7 +184,7 @@ def defineCharacteristicsFromFile(self):
vectorOutputs += 1
if isinstance(output, OutputHTML):
self.addOutput(OutputFile("rawoutput",
self.tr("{0} (raw output)").format(output.description),
self.tr("{0} (raw output)").format(output.description()),
"txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:
Expand All @@ -203,17 +204,17 @@ def defineCharacteristicsFromFile(self):
param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER,
'v.in.ogr snap tolerance (-1 = no snap)',
-1, None, -1.0)
param.isAdvanced = True
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)
param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER,
'v.in.ogr min area', 0, None, 0.0001)
param.isAdvanced = True
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)
if vectorOutputs == 1:
param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER,
'v.out.ogr output type',
self.OUTPUT_TYPES)
param.isAdvanced = True
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)

def getDefaultCellsize(self):
Expand Down Expand Up @@ -395,36 +396,36 @@ def processCommand(self, parameters):
command += ' ' + ' '.join(self.hardcodedStrings)

# Add algorithm command
for param in self.parameters:
for param in self.parameterDefinitions():
if param.value is None or param.value == '':
continue
if param.name in [self.GRASS_REGION_CELLSIZE_PARAMETER, self.GRASS_REGION_EXTENT_PARAMETER, self.GRASS_MIN_AREA_PARAMETER, self.GRASS_SNAP_TOLERANCE_PARAMETER, self.GRASS_OUTPUT_TYPE_PARAMETER, self.GRASS_REGION_ALIGN_TO_RESOLUTION]:
continue
if isinstance(param, (ParameterRaster, ParameterVector)):
value = param.value
if value in list(self.exportedLayers.keys()):
command += ' ' + param.name + '=' \
command += ' ' + param.name() + '=' \
+ self.exportedLayers[value]
else:
command += ' ' + param.name + '=' + value
command += ' ' + param.name() + '=' + value
elif isinstance(param, ParameterMultipleInput):
s = param.value
for layer in list(self.exportedLayers.keys()):
s = s.replace(layer, self.exportedLayers[layer])
s = s.replace(';', ',')
command += ' ' + param.name + '=' + s
command += ' ' + param.name() + '=' + s
elif isinstance(param, ParameterBoolean):
if param.value:
command += ' ' + param.name
command += ' ' + param.name()
elif isinstance(param, ParameterSelection):
idx = int(param.value)
command += ' ' + param.name + '=' + str(param.options[idx][1])
command += ' ' + param.name() + '=' + str(param.options[idx][1])
elif isinstance(param, ParameterString):
command += ' ' + param.name + '="' + str(param.value) + '"'
command += ' ' + param.name() + '="' + str(param.value) + '"'
elif isinstance(param, ParameterPoint):
command += ' ' + param.name + '=' + str(param.value)
command += ' ' + param.name() + '=' + str(param.value)
else:
command += ' ' + param.name + '="' + str(param.value) + '"'
command += ' ' + param.name() + '="' + str(param.value) + '"'

for out in self.outputs:
if isinstance(out, OutputFile):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def processCommand(alg, parameters):
for param in paramsToDelete:
alg.parameters.remove(param)

alg.processCommand()
alg.processCommand(parameters, context)

# Bring back the parameters:
for param in paramsToDelete:
Expand Down
13 changes: 7 additions & 6 deletions python/plugins/processing/algs/qgis/Heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

from qgis.core import (QgsFeatureRequest,
QgsMessageLog,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProcessingParameterDefinition)
from qgis.analysis import QgsKernelDensityEstimation

from processing.algs.qgis import QgisAlgorithm
Expand Down Expand Up @@ -88,7 +89,7 @@ def __init__(self):

radius_field_param = ParameterTableField(self.RADIUS_FIELD,
self.tr('Radius from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
radius_field_param.isAdvanced = True
radius_field_param.setFlags(radius_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(radius_field_param)

class ParameterHeatmapPixelSize(ParameterNumber):
Expand All @@ -108,20 +109,20 @@ def __init__(self, name='', description='', parent_layer=None, radius_param=None

weight_field_param = ParameterTableField(self.WEIGHT_FIELD,
self.tr('Weight from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER)
weight_field_param.isAdvanced = True
weight_field_param.setFlags(weight_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(weight_field_param)
kernel_shape_param = ParameterSelection(self.KERNEL,
self.tr('Kernel shape'), self.KERNELS)
kernel_shape_param.isAdvanced = True
kernel_shape_param.setFlags(kernel_shape_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(kernel_shape_param)
decay_ratio = ParameterNumber(self.DECAY,
self.tr('Decay ratio (Triangular kernels only)'),
-100.0, 100.0, 0.0)
decay_ratio.isAdvanced = True
decay_ratio.setFlags(decay_ratio.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(decay_ratio)
output_scaling = ParameterSelection(self.OUTPUT_VALUE,
self.tr('Output value scaling'), self.OUTPUT_VALUES)
output_scaling.isAdvanced = True
output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(output_scaling)
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Heatmap')))
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/algs/qgis/IdwInterpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRectangle,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProcessingParameterDefinition)
from qgis.analysis import (QgsInterpolator,
QgsIDWInterpolator,
QgsGridFileWriter
Expand Down Expand Up @@ -78,13 +79,13 @@ def __init__(self, name='', description=''):

def setValue(self, value):
if value is None:
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False
self.value = None
return True

if value == '':
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False

if isinstance(value, str):
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/Orthogonalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProcessingParameterDefinition)
from processing.algs.qgis import QgisAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector, ParameterNumber
Expand Down Expand Up @@ -66,7 +67,7 @@ def __init__(self):
max_iterations = ParameterNumber(self.MAX_ITERATIONS,
self.tr('Maximum algorithm iterations'),
1, 10000, 1000)
max_iterations.isAdvanced = True
max_iterations.setFlags(max_iterations.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(max_iterations)

self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthogonalized')))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def evaluateForModeler(self, value, model):
param = i.param
if isinstance(param, ParameterRaster):
new = "{}@".format(os.path.basename(param.value))
old = "{}@".format(param.name)
old = "{}@".format(param.name())
value = value.replace(old, new)

for alg in list(model.algs.values()):
Expand Down Expand Up @@ -164,7 +164,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
for i in list(model.inputs.values()):
param = i.param
if isinstance(param, ParameterRaster) and "{}@".format(param.name) in expression:
values.append(ValueFromInput(param.name))
values.append(ValueFromInput(param.name()))

if algorithm.name:
dependent = model.getDependentAlgorithms(algorithm.name)
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/Relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from qgis.PyQt.QtGui import QIcon, QColor

from qgis.analysis import QgsRelief

from qgis.core import QgsProcessingParameterDefinition
from processing.algs.qgis import QgisAlgorithm
from processing.core.parameters import (Parameter,
ParameterRaster,
Expand Down Expand Up @@ -74,13 +74,13 @@ def __init__(self, name='', description='', parent=None, optional=True):

def setValue(self, value):
if value is None:
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False
self.value = None
return True

if value == '':
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False

if isinstance(value, str):
Expand Down
12 changes: 10 additions & 2 deletions python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsWkbTypes, QgsUnitTypes, QgsFeature, QgsGeometry, QgsField, QgsFields, QgsFeatureRequest, QgsProcessingUtils
from qgis.core import (QgsWkbTypes,
QgsUnitTypes,
QgsFeature,
QgsGeometry,
QgsField,
QgsFields,
QgsFeatureRequest,
QgsProcessingUtils,
QgsProcessingParameterDefinition)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
QgsNetworkSpeedStrategy,
Expand Down Expand Up @@ -134,7 +142,7 @@ def __init__(self):
0.0, 99999999.999999, 0.0))

for p in params:
p.isAdvanced = True
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addOutput(OutputVector(self.OUTPUT_POINTS,
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/qgis/ServiceAreaFromPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
QgsPointXY,
QgsField,
QgsFields,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
Expand Down Expand Up @@ -141,7 +142,7 @@ def __init__(self):
0.0, 99999999.999999, 0.0))

for p in params:
p.isAdvanced = True
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addOutput(OutputVector(self.OUTPUT_POINTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
QgsField,
QgsFeatureRequest,
QgsMessageLog,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
Expand Down Expand Up @@ -142,7 +143,7 @@ def __init__(self):
0.0, 99999999.999999, 0.0))

for p in params:
p.isAdvanced = True
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addOutput(OutputVector(self.OUTPUT_LAYER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from qgis.core import (QgsWkbTypes, QgsUnitTypes, QgsFeature, QgsGeometry, QgsPointXY, QgsFields, QgsField, QgsFeatureRequest,
QgsMessageLog,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
Expand Down Expand Up @@ -135,7 +136,7 @@ def __init__(self):
0.0, 99999999.999999, 0.0))

for p in params:
p.isAdvanced = True
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addOutput(OutputVector(self.OUTPUT_LAYER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
QgsPointXY,
QgsFields,
QgsField,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
Expand Down Expand Up @@ -143,7 +144,7 @@ def __init__(self):
0.0, 99999999.999999, 0.0))

for p in params:
p.isAdvanced = True
p.setFlags(p.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(p)

self.addOutput(OutputNumber(self.TRAVEL_COST,
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/algs/qgis/TinInterpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRectangle,
QgsProcessingUtils)
QgsProcessingUtils,
QgsProcessingParameterDefinition)
from qgis.analysis import (QgsInterpolator,
QgsTINInterpolator,
QgsGridFileWriter
Expand Down Expand Up @@ -86,13 +87,13 @@ def __init__(self, name='', description=''):

def setValue(self, value):
if value is None:
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False
self.value = None
return True

if value == '':
if not self.optional:
if not self.flags() & QgsProcessingParameterDefinition.FlagOptional:
return False

if isinstance(value, str):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from qgis.core import (QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProject)
from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_BATCH
from processing.tools import dataobjects
Expand Down Expand Up @@ -242,6 +243,6 @@ def value(self):
else:
options = self._getOptions()
values = [options[i] for i in self.widget.selectedoptions]
if len(values) == 0 and not self.param.optional:
if len(values) == 0 and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
raise InvalidParameterValue()
return values
Loading

0 comments on commit 189f804

Please sign in to comment.