Skip to content

Commit

Permalink
Merge branch 'processing_parameters_refactoring'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 10, 2016
2 parents 6d2ab9e + 2c9fdae commit 66035b6
Show file tree
Hide file tree
Showing 98 changed files with 2,259 additions and 3,046 deletions.
6 changes: 1 addition & 5 deletions python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(self, alg):

self.alg = alg

self.mainWidget = GdalParametersPanel(self, alg)
self.setMainWidget()
self.setMainWidget(GdalParametersPanel(self, alg))

cornerWidget = QWidget()
layout = QVBoxLayout()
Expand All @@ -56,9 +55,6 @@ def __init__(self, alg):

self.mainWidget.parametersHaveChanged()

QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded)
QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)


class GdalParametersPanel(ParametersPanel):

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def getVectorDriverFromFileName(filename):
return 'ESRI Shapefile'

formats = QgsVectorFileWriter.supportedFiltersAndFormats()
for k, v in formats.items():
for k, v in list(formats.items()):
if ext in k:
return v
return 'ESRI Shapefile'
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def getConsoleCommands(self):

parameters = {self.TITLE: '-t', self.COPYRIGHT: '-c',
self.GOOGLEKEY: '-g', self.BINGKEY: '-b'}
for arg, parameter in parameters.items():
for arg, parameter in list(parameters.items()):
if self.getParameterValue(arg):
arguments.append(parameter)
arguments.append(self.getParameterValue(arg))
Expand Down
13 changes: 6 additions & 7 deletions python/plugins/processing/algs/grass/GrassAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import uuid
import importlib
import re
import traceback

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon
Expand Down Expand Up @@ -145,18 +146,14 @@ def defineCharacteristicsFromFile(self):
line = line.strip('\n').strip()
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Hardcoded|'):])
elif line.startswith('Parameter'):
parameter = getParameterFromString(line)
parameter = getParameterFromString(line)
if parameter is not None:
self.addParameter(parameter)
if isinstance(parameter, ParameterVector):
hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) \
and parameter.datatype < 3:
hasVectorInput = True
elif line.startswith('*Parameter'):
param = getParameterFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
else:
output = getOutputFromString(line)
self.addOutput(output)
Expand All @@ -169,9 +166,11 @@ def defineCharacteristicsFromFile(self):
" (raw output)", "txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:

ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS algorithm: %s.\n%s' % (self.descriptionFile, line)))
traceback.format_exc())
#self.tr('Could not open GRASS algorithm: %s.\n%s' % (self.descriptionFile, line)))
raise e
lines.close()

Expand Down
8 changes: 2 additions & 6 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,14 @@ def defineCharacteristicsFromFile(self):
line = line.strip('\n').strip()
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Hardcoded|'):])
elif line.startswith('Parameter'):
parameter = getParameterFromString(line)
parameter = getParameterFromString(line)
if parameter is not None:
self.addParameter(parameter)
if isinstance(parameter, ParameterVector):
hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) \
and parameter.datatype < 3:
hasVectorInput = True
elif line.startswith('*Parameter'):
param = getParameterFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
else:
output = getOutputFromString(line)
self.addOutput(output)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/i.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def exportInputRasters(alg, rasterDic):
{ 'inputName1': 'outputName1', 'inputName2': 'outputName2'}
"""
# Get inputs and outputs
for inputName, outputName in rasterDic.items():
for inputName, outputName in list(rasterDic.items()):
inputRaster = alg.getParameterValue(inputName)
outputRaster = alg.getOutputFromName(outputName)
command = 'r.out.gdal -c -t -f --overwrite createopt="TFW=YES,COMPRESS=LZW" input={} output=\"{}\"'.format(
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/v_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def variableOutput(alg, params, nocats=True):
"""

# Build the v.out.ogr commands
for outputName, typeList in params.items():
for outputName, typeList in list(params.items()):
if not isinstance(typeList, list):
continue

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def replace(s):
return s.replace("{qgisdocs}", "https://docs.qgis.org/%s/%s/docs" % (version, locale))
else:
return None
h = {k: replace(v) for k, v in h.items()}
h = {k: replace(v) for k, v in list(h.items())}
return h


Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/lidar/fusion/ClipData.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Points')
self.addParameter(ParameterFile(
self.INPUT, self.tr('Input LAS layer')))
self.addParameter(ParameterExtent(self.EXTENT, self.tr('Extent')))
self.addParameter(ParameterExtent(self.EXTENT, self.tr('Extent'), optional=False))
self.addParameter(ParameterSelection(
self.SHAPE, self.tr('Shape'), ['Rectangle', 'Circle']))
self.addOutput(OutputFile(
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/lidar/lastools/lasquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('lasquery')
self.group, self.i18n_group = self.trAlgorithm('LAStools')
self.addParametersVerboseGUI()
self.addParameter(ParameterExtent(self.AOI, self.tr('area of interest')))
self.addParameter(ParameterExtent(self.AOI, self.tr('area of interest'), optional=False))
self.addParametersAdditionalGUI()

def processAlgorithm(self, progress):
Expand All @@ -61,7 +61,7 @@ def processAlgorithm(self, progress):
layers = QgsMapLayerRegistry.instance().mapLayers()

# loop over layers
for name, layer in layers.items():
for name, layer in list(layers.items()):
layerType = layer.type()
if layerType == QgsMapLayer.VectorLayer:
shp_file_name = layer.source()
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/otb/OTBAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* *
***************************************************************************
"""
from builtins import next
from future import standard_library
standard_library.install_aliases()
from builtins import map
Expand Down Expand Up @@ -307,7 +308,7 @@ def processAlgorithm(self, progress):
OTBUtils.executeOtb(helperCommands, progress)

if self.roiRasters:
supportRaster = next(iter(self.roiRasters.values()))
supportRaster = next(iter(list(self.roiRasters.values())))
for roiInput, roiFile in list(self.roiVectors.items()):
helperCommands = [
"otbcli_VectorDataExtractROIApplication",
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/otb/maintenance/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* *
***************************************************************************
"""
from builtins import next
from builtins import str
from builtins import range
__author__ = 'Julien Malik, Oscar Picas'
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/ConcaveHull.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def processAlgorithm(self, progress):
counter = 50. / len(edges)
i = 0
ids = []
for id, max_len in edges.items():
for id, max_len in list(edges.items()):
if max_len > alpha * max_length:
ids.append(id)
progress.setPercentage(50 + i * counter)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/Delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from builtins import next

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down
22 changes: 13 additions & 9 deletions python/plugins/processing/algs/qgis/DeleteColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class DeleteColumn(GeoAlgorithm):

INPUT = 'INPUT'
COLUMN = 'COLUMN'
COLUMNS = 'COLUMN'
OUTPUT = 'OUTPUT'

def defineCharacteristics(self):
Expand All @@ -45,17 +45,20 @@ def defineCharacteristics(self):

self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer')))
self.addParameter(ParameterTableField(self.COLUMN,
self.tr('Field to delete'), self.INPUT))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Deleted column')))
self.addParameter(ParameterTableField(self.COLUMNS,
self.tr('Fields to delete'), self.INPUT, multiple=True))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Output layer')))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))
idx = layer.fields().lookupField(self.getParameterValue(self.COLUMN))
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))

toDelete = self.getParameterValue(self.COLUMNS)
fields = layer.fields()
fields.remove(idx)
idxs = []
for f in toDelete:
idx = layer.fieldNameIndex()
fields.remove(idx)
idxs.append[idx]

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
layer.wkbType(), layer.crs())
Expand All @@ -67,7 +70,8 @@ def processAlgorithm(self, progress):
for current, f in enumerate(features):
feat.setGeometry(f.geometry())
attributes = f.attributes()
del attributes[idx]
for idx in idxs:
del attributes[idx]
feat.setAttributes(attributes)
writer.addFeature(feat)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def processAlgorithm(self, progress):

cleaned = dict(geoms)

for i, g in geoms.items():
for i, g in list(geoms.items()):
for j in list(cleaned.keys()):
if i == j or i not in cleaned:
continue
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/Difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from builtins import next

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableMultipleField
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector
from processing.tools import vector, dataobjects

Expand All @@ -62,8 +62,8 @@ def defineCharacteristics(self):
[dataobjects.TYPE_VECTOR_POLYGON, dataobjects.TYPE_VECTOR_LINE]))
self.addParameter(ParameterBoolean(Dissolve.DISSOLVE_ALL,
self.tr('Dissolve all (do not use fields)'), True))
self.addParameter(ParameterTableMultipleField(Dissolve.FIELD,
self.tr('Unique ID fields'), Dissolve.INPUT, optional=True))
self.addParameter(ParameterTableField(Dissolve.FIELD,
self.tr('Unique ID fields'), Dissolve.INPUT, optional=True, multiple=True))
self.addOutput(OutputVector(Dissolve.OUTPUT, self.tr('Dissolved')))

def processAlgorithm(self, progress):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/ExtractByLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from builtins import next

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/processing/algs/qgis/FieldsCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ def processAlgorithm(self, progress):

output = self.getOutputFromName(self.OUTPUT_LAYER)

if output.value == '':
ext = output.getDefaultFileExtension(self)
output.value = system.getTempFilenameInTempFolder(
output.name + '.' + ext)

fields = layer.fields()
if newField:
fields.append(QgsField(fieldName, fieldType, '', width, precision))
Expand Down
8 changes: 0 additions & 8 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
from processing.tools import dataobjects, vector

from .fieldsmapping import ParameterFieldsMapping
from .ui.FieldsMapperDialogs import (FieldsMapperParametersDialog,
FieldsMapperModelerParametersDialog)


class FieldsMapper(GeoAlgorithm):
Expand Down Expand Up @@ -151,9 +149,3 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException(
self.tr('An error occurred while evaluating the calculation'
' string:\n') + error)

def getCustomParametersDialog(self):
return FieldsMapperParametersDialog(self)

def getCustomModelerParametersDialog(self, modelAlg, algName=None):
return FieldsMapperModelerParametersDialog(self, modelAlg, algName)
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/GridLine.py
Original file line number Diff line number Diff line change