Skip to content
Permalink
Browse files
Allow adding manual layers in modeler multi layer alg parameters
This allows creation of models with child algorithms which do
things like merge a selected layer with a predefined static
layer, or create a vrt with a mix of static and user selected
layers.
  • Loading branch information
nyalldawson committed Aug 16, 2017
1 parent aefd5cc commit 8139786
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
@@ -32,7 +32,8 @@
from qgis.core import (QgsSettings,
QgsProcessing,
QgsVectorFileWriter,
QgsProviderRegistry)
QgsProviderRegistry,
QgsProcessingModelChildParameterSource)
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtCore import QByteArray
@@ -105,8 +106,11 @@ def populateList(self):

# add extra options (e.g. manually added layers)
for t in [o for o in self.selectedoptions if not isinstance(o, int)]:
item = QStandardItem(t)
item.setData(t, Qt.UserRole)
if isinstance(t, QgsProcessingModelChildParameterSource):
item = QStandardItem(t.staticValue())
else:
item = QStandardItem(t)
item.setData(item.text(), Qt.UserRole)
item.setCheckState(Qt.Checked)
item.setCheckable(True)
self.model.appendRow(item)
@@ -69,6 +69,7 @@
QgsProcessingOutputVectorLayer,
QgsProcessingOutputString,
QgsProcessingOutputNumber,
QgsProcessingModelChildParameterSource,
QgsProcessingModelAlgorithm)

from qgis.PyQt.QtWidgets import (
@@ -562,7 +563,7 @@ def createWidget(self):
return widget
else:
options = [self.dialog.resolveValueDescription(opt) for opt in self._getOptions()]
return MultipleInputPanel(options)
return MultipleInputPanel(options, datatype=self.param.layerType())

def refresh(self):
if self.param.layerType() != QgsProcessing.TypeFile:
@@ -582,15 +583,20 @@ def setValue(self, value):
return self.widget.setText(value)
else:
options = self._getOptions()
selected = []
for i, opt in enumerate(options):
try:
if opt in value:
selected.append(i)
except TypeError:
if opt == value:
selected.append(i)
self.widget.setSelectedItems(selected)

if not isinstance(value, (tuple, list)):
value = [value]

selected_options = []
for sel in value:
if sel in options:
selected_options.append(options.index(sel))
elif isinstance(sel, QgsProcessingModelChildParameterSource):
selected_options.append(sel.staticValue())
else:
selected_options.append(sel)

self.widget.setSelectedItems(selected_options)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -608,7 +614,7 @@ def value(self):
return self.widget.getText()
else:
options = self._getOptions()
values = [options[i] for i in self.widget.selectedoptions]
values = [options[i] if isinstance(i, int) else QgsProcessingModelChildParameterSource.fromStaticValue(i) for i in self.widget.selectedoptions]
if len(values) == 0 and not self.param.flags() & QgsProcessing.FlagOptional:
raise InvalidParameterValue()
return values

0 comments on commit 8139786

Please sign in to comment.