Skip to content

Commit

Permalink
"Loosen" up acceptable parameter for model child inputs
Browse files Browse the repository at this point in the history
Previously we took a harsher approach to filtering which inputs
were acceptable for child algorithm parameters. E.g. a child algorithm
with a vector layer input would only show outputs from other algorithms
which generated a vector layer output.

But this can needlessly restrict what's possible in models. E.g.
an algorithm which outputs a QgsProcessingOutputFile or
QgsProcessingOutputString could potentially be a valid source
to a vector layer. So we should allow these as possible
inputs for vector layer parameters too.

This commit adds many extra acceptable input types for
child parameters. It will probably expose "corner cases" where
algorithms may get unexpected input types, but these will
not affect existing model stability and can be fixed when
identified.

The payoff is a much more flexible modeler.
  • Loading branch information
nyalldawson committed Oct 16, 2017
1 parent a3f7655 commit 5b1afd8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputFile,
QgsProcessingOutputString,
QgsProcessingOutputNumber,
QgsProcessingModelChildParameterSource,
Expand Down Expand Up @@ -319,7 +320,7 @@ def createWidget(self):

widget.setLayout(layout)
self.combo.setEditable(True)
crss = self.dialog.getAvailableValuesOfType(QgsProcessingParameterCrs)
crss = self.dialog.getAvailableValuesOfType((QgsProcessingParameterCrs, QgsProcessingParameterString), QgsProcessingOutputString)
for crs in crss:
self.combo.addItem(self.dialog.resolveValueDescription(crs), crs)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer,
Expand Down Expand Up @@ -386,7 +387,7 @@ def createWidget(self):
else:
widget = QComboBox()
widget.setEditable(True)
extents = self.dialog.getAvailableValuesOfType(QgsProcessingParameterExtent, OutputExtent)
extents = self.dialog.getAvailableValuesOfType(QgsProcessingParameterExtent, (OutputExtent, QgsProcessingOutputString))
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
widget.addItem(self.USE_MIN_COVERING_EXTENT, None)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer,
Expand Down Expand Up @@ -442,7 +443,7 @@ def createWidget(self):
else:
item = QComboBox()
item.setEditable(True)
points = self.dialog.getAvailableValuesOfType(QgsProcessingParameterPoint)
points = self.dialog.getAvailableValuesOfType((QgsProcessingParameterPoint, QgsProcessingParameterString), (QgsProcessingOutputString))
for p in points:
item.addItem(self.dialog.resolveValueDescription(p), p)
item.setEditText(str(self.param.defaultValue()))
Expand Down Expand Up @@ -488,7 +489,7 @@ def createWidget(self):
else:
self.combo = QComboBox()
self.combo.setEditable(True)
files = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile)
files = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, (QgsProcessingOutputFile, QgsProcessingOutputString))
for f in files:
self.combo.addItem(self.dialog.resolveValueDescription(f), f)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
Expand Down Expand Up @@ -763,8 +764,8 @@ def setComboBoxFilters(self, combo):

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer],
[QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer])
[QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer, QgsProcessingParameterString],
[QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer, QgsProcessingOutputString, QgsProcessingOutputFile])

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
Expand Down Expand Up @@ -810,7 +811,8 @@ def validator(v):
class RasterWidgetWrapper(MapLayerWidgetWrapper):

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
return self.dialog.getAvailableValuesOfType((QgsProcessingParameterRasterLayer, QgsProcessingParameterString),
(QgsProcessingOutputRasterLayer, QgsProcessingOutputFile, QgsProcessingOutputString))

def setComboBoxFilters(self, combo):
combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
Expand Down Expand Up @@ -936,7 +938,7 @@ def createWidget(self):
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(
(QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer),
QgsProcessingOutputVectorLayer, self.param.dataTypes())
(QgsProcessingOutputVectorLayer, QgsProcessingOutputString, QgsProcessingOutputFile), self.param.dataTypes())
self.combo.setEditable(True)
for layer in layers:
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
Expand Down Expand Up @@ -1115,7 +1117,7 @@ def createWidget(self):
else:
strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterExpression, QgsProcessingParameterString, QgsProcessingParameterNumber],
QgsProcessingOutputString)
(QgsProcessingOutputString, QgsProcessingOutputNumber))
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
widget = QComboBox()
widget.setEditable(True)
Expand Down Expand Up @@ -1215,8 +1217,8 @@ def createWidget(self):
else:
self.combo = QComboBox()
self.combo.setEditable(True)
tables = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer,
QgsProcessingOutputVectorLayer)
tables = self.dialog.getAvailableValuesOfType((QgsProcessingParameterVectorLayer, QgsProcessingParameterString),
(QgsProcessingOutputVectorLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.addItem(self.NOT_SELECTED, None)
for table in tables:
Expand Down

0 comments on commit 5b1afd8

Please sign in to comment.