Skip to content
Permalink
Browse files

[processing] fixes for new parameters architecture

includes better managing of crd and extent parameters in models, not requiring now the use of modeler-only lags
  • Loading branch information
volaya committed Oct 5, 2016
1 parent b298c76 commit efd73a491f7d1161067c33d9e3df0caa9c989f27
Showing with 112 additions and 507 deletions.
  1. +1 −1 python/plugins/processing/algs/lidar/fusion/ClipData.py
  2. +1 −1 python/plugins/processing/algs/lidar/lastools/lasquery.py
  3. +1 −1 python/plugins/processing/algs/qgis/GridLine.py
  4. +1 −1 python/plugins/processing/algs/qgis/GridPolygon.py
  5. +1 −1 python/plugins/processing/algs/qgis/RandomPointsExtent.py
  6. +0 −1 python/plugins/processing/algs/qgis/RandomSelection.py
  7. +0 −1 python/plugins/processing/algs/qgis/RandomSelectionWithinSubsets.py
  8. +1 −1 python/plugins/processing/algs/qgis/RegularPoints.py
  9. +0 −1 python/plugins/processing/algs/qgis/SetVectorStyle.py
  10. +1 −1 python/plugins/processing/algs/qgis/VectorGridPolygons.py
  11. +1 −1 python/plugins/processing/algs/saga/SagaAlgorithm212.py
  12. +1 −4 python/plugins/processing/core/GeoAlgorithm.py
  13. +39 −8 python/plugins/processing/core/parameters.py
  14. +1 −1 python/plugins/processing/gui/BatchInputSelectionPanel.py
  15. +8 −106 python/plugins/processing/gui/BatchPanel.py
  16. +2 −14 python/plugins/processing/gui/ParametersPanel.py
  17. +1 −1 python/plugins/processing/gui/ProcessingToolbox.py
  18. +48 −24 python/plugins/processing/gui/wrappers.py
  19. +1 −1 python/plugins/processing/modeler/ModelerDialog.py
  20. +1 −9 python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py
  21. +1 −78 python/plugins/processing/modeler/ModelerParametersDialog.py
  22. +0 −66 python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py
  23. +0 −51 python/plugins/processing/modeler/RasterLayerCrsAlgorithm.py
  24. +0 −66 python/plugins/processing/modeler/VectorLayerBoundsAlgorithm.py
  25. +0 −51 python/plugins/processing/modeler/VectorLayerCrsAlgorithm.py
  26. +1 −16 python/plugins/processing/script/ScriptAlgorithm.py
@@ -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(
@@ -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):
@@ -57,7 +57,7 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Vector creation tools')

self.addParameter(ParameterExtent(self.EXTENT,
self.tr('Grid extent')))
self.tr('Grid extent'), optional=False))
self.addParameter(ParameterNumber(self.HSPACING,
self.tr('Horizontal spacing'), default=10.0))
self.addParameter(ParameterNumber(self.VSPACING,
@@ -65,7 +65,7 @@ def defineCharacteristics(self):
self.addParameter(ParameterSelection(self.TYPE,
self.tr('Grid type'), self.types))
self.addParameter(ParameterExtent(self.EXTENT,
self.tr('Grid extent')))
self.tr('Grid extent'), optional=False))
self.addParameter(ParameterNumber(self.HSPACING,
self.tr('Horizontal spacing'), default=10.0))
self.addParameter(ParameterNumber(self.VSPACING,
@@ -59,7 +59,7 @@ def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Random points in extent')
self.group, self.i18n_group = self.trAlgorithm('Vector creation tools')
self.addParameter(ParameterExtent(self.EXTENT,
self.tr('Input extent')))
self.tr('Input extent'), optional=False))
self.addParameter(ParameterNumber(self.POINT_NUMBER,
self.tr('Points number'), 1, None, 1))
self.addParameter(ParameterNumber(self.MIN_DISTANCE,
@@ -53,7 +53,6 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'random_selection.png'))

def defineCharacteristics(self):
self.allowOnlyOpenedLayers = True
self.name, self.i18n_name = self.trAlgorithm('Random selection')
self.group, self.i18n_group = self.trAlgorithm('Vector selection tools')

@@ -57,7 +57,6 @@ def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'sub_selection.png'))

def defineCharacteristics(self):
self.allowOnlyOpenedLayers = True
self.name, self.i18n_name = self.trAlgorithm('Random selection within subsets')
self.group, self.i18n_group = self.trAlgorithm('Vector selection tools')

@@ -63,7 +63,7 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Vector creation tools')

self.addParameter(ParameterExtent(self.EXTENT,
self.tr('Input extent')))
self.tr('Input extent'), optional=False))
self.addParameter(ParameterNumber(self.SPACING,
self.tr('Point spacing/count'), 0.0001, 999999999.999999999, 0.0001))
self.addParameter(ParameterNumber(self.INSET,
@@ -41,7 +41,6 @@ class SetVectorStyle(GeoAlgorithm):
OUTPUT = 'OUTPUT'

def defineCharacteristics(self):
# self.allowOnlyOpenedLayers = True
self.name, self.i18n_name = self.trAlgorithm('Set style for vector layer')
self.group, self.i18n_group = self.trAlgorithm('Vector general tools')
self.addParameter(ParameterVector(self.INPUT,
@@ -58,7 +58,7 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Vector creation tools')

self.addParameter(ParameterExtent(self.EXTENT,
self.tr('Grid extent')))
self.tr('Grid extent'), optional=False))
self.addParameter(ParameterNumber(self.STEP_X,
self.tr('X spacing'), 0.0, 1000000000.0, 0.0001))
self.addParameter(ParameterNumber(self.STEP_Y,
@@ -119,7 +119,7 @@ def defineCharacteristicsFromFile(self):
# An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(' ')
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
'Output extent', ''))
'Output extent'))
else:
self.addOutput(getOutputFromString(line))
line = lines.readline().strip('\n').strip()
@@ -72,10 +72,7 @@ def __init__(self):
# appear in the toolbox or modeler
self.showInToolbox = True
self.showInModeler = True
# if true, will show only loaded layers in parameters dialog.
# Also, if True, the algorithm does not run on the modeler
# or batch ptocessing interface
self.allowOnlyOpenedLayers = False


# False if it should not be run a a batch process
self.canRunInBatchMode = True
@@ -35,7 +35,7 @@


from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import QgsRasterLayer, QgsVectorLayer
from qgis.core import QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinateReferenceSystem
from processing.tools.vector import resolveFieldIndex, features
from processing.tools.system import isWindows
from processing.tools import dataobjects
@@ -207,14 +207,29 @@ def __init__(self, name='', description='', default=None, optional=False, metada
Parameter.__init__(self, name, description, default, optional, metadata)

def setValue(self, value):
if value is None or value.strip() == '':
if not bool(value):
if not self.optional:
return False
self.value = None if value is None else value.strip()
self.value = None
return True

if isinstance(value, QgsCoordinateReferenceSystem):
self.value = value.authid()
return True
if isinstance(value, QgsMapLayer):
self.value = value.crs().authid()
return True
try:
layer = dataobjects.getObjectFromUri(value)
if layer is not None:
self.value = layer.crs().authid()
return True
except:
pass


# TODO: check it is a valid authid
self.value = str(value)
self.value = value
return True

def getValueAsCommandLineParameter(self):
@@ -261,22 +276,38 @@ def __init__(self, name='', description='', default=None, optional=True):
Parameter.__init__(self, name, description, default, optional)
# The value is a string in the form "xmin, xmax, ymin, ymax"

def setValue(self, text):
if text is None:
def setValue(self, value):
if value is None:
if not self.optional:
return False
self.value = None
return True

tokens = str(text).split(',')
if isinstance(value, QgsMapLayer):
rect = value.extent()
self.value = '{},{},{},{}'.format(
rect.xMinimum(), rect.xMaximum(), rect.yMinimum(), rect.yMaximum())
return True

try:
layer = dataobjects.getObjectFromUri(value)
if layer is not None:
rect = layer.extent()
self.value = '{},{},{},{}'.format(
rect.xMinimum(), rect.xMaximum(), rect.yMinimum(), rect.yMaximum())
return True
except:
pass

tokens = str(value).split(',')
if len(tokens) != 4:
return False
try:
float(tokens[0])
float(tokens[1])
float(tokens[2])
float(tokens[3])
self.value = text
self.value = value
return True
except:
return False
@@ -67,7 +67,7 @@ def __init__(self, param, row, col, dialog):
self.setLayout(self.horizontalLayout)

def _panel(self):
return self.dialog.mainDialog()
return self.dialog.mainWidget()

def _table(self):
return self._panel().tblParameters
@@ -36,14 +36,6 @@

from qgis.core import QgsApplication

from processing.gui.wrappers import NotYetImplementedWidgetWrapper

from processing.gui.FileSelectionPanel import FileSelectionPanel
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.gui.PointSelectionPanel import PointSelectionPanel
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.GeometryPredicateSelectionPanel import GeometryPredicateSelectionPanel

@@ -143,17 +135,6 @@ def initWidgets(self):
self.tblParameters.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
self.tblParameters.horizontalHeader().setStretchLastSection(True)

def getWidgetWrapperFromParameter(self, param, row, col):
return param.wrapper(self.parent, row, col)


def getWidgetFromParameter(self, param, row, col):
if isinstance(param, ParameterGeometryPredicate):
item = GeometryPredicateSelectionPanel(param.enabledPredicates, rows=1)
width = max(self.tblParameters.columnWidth(col),
item.sizeHint().width())
self.tblParameters.setColumnWidth(col, width)

def load(self):
filename, selected_filter = QFileDialog.getOpenFileName(self,
self.tr('Open batch'), None,
@@ -195,21 +176,6 @@ def load(self):
self.tr('Error'),
self.tr('An error occurred while reading your file.'))

def setValueInWidgetWrapper(self, wrapper, value):
if wrapper.implemented:
return wrapper.setValue(value)
self.setValueInWidget(wrapper.widget, value)

def setValueInWidget(self, widget, value):
if isinstance(widget, (BatchOutputSelectionPanel, GeometryPredicateSelectionPanel)):
widget.setValue(unicode(value))
elif isinstance(widget, ExtentSelectionPanel):
if value is not None:
widget.setExtentFromString(value)
else:
widget.setExtentFromString('')


def save(self):
toSave = []
for row in range(self.tblParameters.rowCount()):
@@ -220,28 +186,13 @@ def save(self):
for param in alg.parameters:
if param.hidden:
continue
if isinstance(param, ParameterExtent):
col += 1
continue
wrapper = self.wrappers[row][col]
if not self.setParamValue(param, wrapper, alg):
self.parent.lblProgress.setText(
self.tr('<b>Missing parameter value: %s (row %d)</b>') % (param.description, row + 1))
return
algParams[param.name] = param.getValueAsCommandLineParameter()
col += 1
col = 0
for param in alg.parameters:
if param.hidden:
continue
if isinstance(param, ParameterExtent):
wrapper = self.wrappers[row][col]
if not self.setParamValue(param, wrapper, alg):
self.parent.lblProgress.setText(
self.tr('<b>Missing parameter value: %s (row %d)</b>') % (param.description, row + 1))
return
algParams[param.name] = unicode(param.value())
col += 1
for out in alg.outputs:
if out.hidden:
continue
@@ -267,25 +218,14 @@ def save(self):
json.dump(toSave, f)

def setParamValue(self, param, wrapper, alg=None):
if wrapper.implemented:
return param.setValue(wrapper.value())

widget = wrapper.widget
if isinstance(param, ParameterExtent):
if alg is not None:
widget.useNewAlg(alg)
return param.setValue(widget.getValue())
elif isinstance(param, ParameterGeometryPredicate):
return param.setValue(widget.value())
else:
return param.setValue(widget.text())
return param.setValue(wrapper.value())

def setCellWrapper(self, row, column, wrapper):
self.wrappers[row][column] = wrapper
self.tblParameters.setCellWidget(row, column, wrapper.widget)

def addRow(self):
self.widget_wrappers.append([None] * self.tblParameters.columnCount())
self.wrappers.append([None] * self.tblParameters.columnCount())
self.tblParameters.setRowCount(self.tblParameters.rowCount() + 1)

row = self.tblParameters.rowCount() - 1
@@ -294,7 +234,7 @@ def addRow(self):
if param.hidden:
continue

wrapper = self.getWidgetWrapperFromParameter(param, row, column)
wrapper = param.wrapper(self.parent, row, column)
self.setCellWrapper(row, column, wrapper)
column += 1

@@ -315,53 +255,15 @@ def addRow(self):
self.tblParameters.setCellWidget(row, column, item)

def removeRows(self):
# ~ self.tblParameters.setUpdatesEnabled(False)
# ~ indexes = self.tblParameters.selectionModel().selectedIndexes()
# ~ indexes.sort()
# ~ for i in reversed(indexes):
# ~ self.tblParameters.model().removeRow(i.row())
# ~ self.tblParameters.setUpdatesEnabled(True)
if self.tblParameters.rowCount() > 2:
self.widget_wrappers.pop()
self.wrappers.pop()
self.tblParameters.setRowCount(self.tblParameters.rowCount() - 1)

def fillParameterValues(self, column):
widget = self.tblParameters.cellWidget(0, column)

if isinstance(widget, QComboBox):
widgetValue = widget.currentIndex()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setCurrentIndex(widgetValue)
elif isinstance(widget, ExtentSelectionPanel):
widgetValue = widget.getValue()
for row in range(1, self.tblParameters.rowCount()):
if widgetValue is not None:
self.tblParameters.cellWidget(row, column).setExtentFromString(widgetValue)
else:
self.tblParameters.cellWidget(row, column).setExtentFromString('')
elif isinstance(widget, CrsSelectionPanel):
widgetValue = widget.getValue()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setAuthId(widgetValue)
elif isinstance(widget, FileSelectionPanel):
widgetValue = widget.getValue()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setText(widgetValue)
elif isinstance(widget, QLineEdit):
widgetValue = widget.text()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setText(widgetValue)
elif isinstance(widget, BatchInputSelectionPanel):
widgetValue = widget.getText()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setText(widgetValue)
elif isinstance(widget, GeometryPredicateSelectionPanel):
widgetValue = widget.value()
for row in range(1, self.tblParameters.rowCount()):
self.tblParameters.cellWidget(row, column).setValue(widgetValue)
else:
pass

wrapper = self.wrappers[0][column]
for row in range(1, self.tblParameters.rowCount()):
self.wrappers[row][column].setValue(wrapper.value())

def toggleAdvancedMode(self, checked):
for column, param in enumerate(self.alg.parameters):
if param.isAdvanced:

0 comments on commit efd73a4

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