Skip to content
Permalink
Browse files

Adapt more code to c++ API

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent ef59d0c commit 189f8047145c71228e6d337d35a35fe3017fe084
Showing with 306 additions and 332 deletions.
  1. +3 −1 python/plugins/processing/algs/gdal/gdal2tiles.py
  2. +3 −1 python/plugins/processing/algs/gdal/retile.py
  3. +15 −14 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  4. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_distance.py
  5. +7 −6 python/plugins/processing/algs/qgis/Heatmap.py
  6. +4 −3 python/plugins/processing/algs/qgis/IdwInterpolation.py
  7. +3 −2 python/plugins/processing/algs/qgis/Orthogonalize.py
  8. +2 −2 python/plugins/processing/algs/qgis/RasterCalculator.py
  9. +3 −3 python/plugins/processing/algs/qgis/Relief.py
  10. +10 −2 python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
  11. +2 −1 python/plugins/processing/algs/qgis/ServiceAreaFromPoint.py
  12. +2 −1 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  13. +2 −1 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  14. +2 −1 python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py
  15. +4 −3 python/plugins/processing/algs/qgis/TinInterpolation.py
  16. +2 −1 python/plugins/processing/algs/qgis/ui/RasterCalculatorWidgets.py
  17. +8 −8 python/plugins/processing/algs/saga/SagaAlgorithm.py
  18. +3 −2 python/plugins/processing/core/GeoAlgorithm.py
  19. +1 −1 python/plugins/processing/core/Processing.py
  20. +4 −16 python/plugins/processing/core/outputs.py
  21. +58 −108 python/plugins/processing/core/parameters.py
  22. +2 −2 python/plugins/processing/gui/AlgorithmDialog.py
  23. +2 −2 python/plugins/processing/gui/AutofillDialog.py
  24. +5 −5 python/plugins/processing/gui/BatchAlgorithmDialog.py
  25. +20 −19 python/plugins/processing/gui/BatchPanel.py
  26. +7 −5 python/plugins/processing/gui/EditRenderingStylesDialog.py
  27. +3 −2 python/plugins/processing/gui/ExtentSelectionPanel.py
  28. +5 −5 python/plugins/processing/gui/Help2Html.py
  29. +8 −8 python/plugins/processing/gui/HelpEditionDialog.py
  30. +4 −4 python/plugins/processing/gui/NumberInputPanel.py
  31. +7 −7 python/plugins/processing/gui/Postprocessing.py
  32. +14 −13 python/plugins/processing/gui/TestTools.py
  33. +20 −19 python/plugins/processing/modeler/ModelerAlgorithm.py
  34. +6 −5 python/plugins/processing/modeler/ModelerGraphicItem.py
  35. +16 −14 python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py
  36. +27 −26 python/plugins/processing/modeler/ModelerParametersDialog.py
  37. +3 −2 python/plugins/processing/modeler/ModelerScene.py
  38. +1 −1 python/plugins/processing/tools/dataobjects.py
  39. +2 −2 python/plugins/processing/tools/general.py
  40. +13 −12 python/plugins/processing/tools/help.py
  41. +2 −1 src/core/processing/qgsprocessingalgrunnertask.cpp
@@ -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
@@ -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,
@@ -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
@@ -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,
@@ -37,7 +37,8 @@
QgsApplication,
QgsProcessingUtils,
QgsMessageLog,
QgsProcessingAlgorithm)
QgsProcessingAlgorithm,
QgsProcessingParameterDefinition)
from qgis.utils import iface

from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -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:
@@ -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):
@@ -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):
@@ -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:
@@ -31,7 +31,8 @@

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

from processing.algs.qgis import QgisAlgorithm
@@ -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):
@@ -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')))
@@ -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
@@ -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):
@@ -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
@@ -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')))
@@ -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()):
@@ -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)
@@ -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,
@@ -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):
@@ -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,
@@ -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,
@@ -38,6 +38,7 @@
QgsPointXY,
QgsField,
QgsFields,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
@@ -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,
@@ -40,6 +40,7 @@
QgsField,
QgsFeatureRequest,
QgsMessageLog,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
@@ -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,
@@ -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,
@@ -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,
@@ -38,6 +38,7 @@
QgsPointXY,
QgsFields,
QgsField,
QgsProcessingParameterDefinition,
QgsProcessingUtils)
from qgis.analysis import (QgsVectorLayerDirector,
QgsNetworkDistanceStrategy,
@@ -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,
@@ -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
@@ -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):
@@ -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
@@ -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

0 comments on commit 189f804

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