Skip to content
Permalink
Browse files

[processing] Add file picker to vector/raster/table parameters

in modeller

Makes it obvious that users can set an algorithm vector/raster/
table input to a fixed table
  • Loading branch information
nyalldawson committed Nov 16, 2016
1 parent f78f2a0 commit fc65334a609c916f9bcab46138db51512c1995ab
Showing with 84 additions and 35 deletions.
  1. +84 −35 python/plugins/processing/gui/wrappers.py
@@ -115,7 +115,7 @@ def __init__(self, param, dialog, row=0, col=0):
self.setValue(param.default)

def comboValue(self, validator=None, combobox=None):
if not combobox:
if combobox is None:
combobox = self.widget
idx = combobox.findText(combobox.currentText())
if idx < 0:
@@ -132,7 +132,7 @@ def setValue(self, value):
pass

def setComboValue(self, value, combobox=None):
if not combobox:
if combobox is None:
combobox = self.widget
if isinstance(value, list):
value = value[0]
@@ -265,7 +265,6 @@ def createWidget(self):
self.combo.setEditText(self.param.default)
return widget
else:

widget = QgsProjectionSelectionWidget()
if self.param.optional:
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
@@ -584,31 +583,47 @@ def createWidget(self):
elif self.dialogType == DIALOG_BATCH:
return BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
else:
widget = QComboBox()
widget.setEditable(True)
files = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
for f in files:
widget.addItem(self.dialog.resolveValueDescription(f), f)
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
self.combo.setEditable(True)
for layer in layers:
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
if self.param.optional:
widget.setEditText("")
self.combo.setEditText("")

widget = QWidget()
layout = QHBoxLayout()
layout.setMargin(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
widget.setLayout(layout)
return widget

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)

def setValue(self, value):
if self.dialogType == DIALOG_STANDARD:
pass # TODO
elif self.dialogType == DIALOG_BATCH:
self.widget.setText(value)
else:
self.setComboValue(value)
self.setComboValue(value, combobox=self.combo)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -628,7 +643,7 @@ def validator(v):
return self.param.optional
else:
return os.path.exists(v)
return self.comboValue(validator)
return self.comboValue(validator, combobox=self.combo)


class SelectionWidgetWrapper(WidgetWrapper):
@@ -704,31 +719,47 @@ def createWidget(self):
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return widget
else:
widget = QComboBox()
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(ParameterVector, OutputVector)
widget.setEditable(True)
self.combo.setEditable(True)
for layer in layers:
widget.addItem(self.dialog.resolveValueDescription(layer), layer)
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
if self.param.optional:
widget.setEditText("")
self.combo.setEditText("")

widget = QWidget()
layout = QHBoxLayout()
layout.setMargin(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
widget.setLayout(layout)
return widget

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)

def setValue(self, value):
if self.dialogType == DIALOG_STANDARD:
pass # TODO
elif self.dialogType == DIALOG_BATCH:
self.widget.setValue(value)
else:
self.setComboValue(value)
self.setComboValue(value, combobox=self.combo)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -748,7 +779,7 @@ def validator(v):
return self.param.optional
else:
return os.path.exists(v)
return self.comboValue(validator)
return self.comboValue(validator, combobox=self.combo)


class StringWidgetWrapper(WidgetWrapper):
@@ -911,33 +942,51 @@ def createWidget(self):
elif self.dialogType == DIALOG_BATCH:
return BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
else:
widget = QComboBox()
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
self.combo.setEditable(True)
tables = self.dialog.getAvailableValuesOfType(ParameterTable, OutputTable)
layers = self.dialog.getAvailableValuesOfType(ParameterVector, OutputVector)
if self.param.optional:
widget.addItem(self.NOT_SELECTED, None)
self.combo.addItem(self.NOT_SELECTED, None)
for table in tables:
widget.addItem(self.dialog.resolveValueDescription(table), table)
self.combo.addItem(self.dialog.resolveValueDescription(table), table)
for layer in layers:
widget.addItem(self.dialog.resolveValueDescription(layer), layer)
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)

widget = QWidget()
layout = QHBoxLayout()
layout.setMargin(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
widget.setLayout(layout)
return widget

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)

def setValue(self, value):
if self.dialogType == DIALOG_STANDARD:
pass # TODO
elif self.dialogType == DIALOG_BATCH:
return self.widget.setText(value)
else:
self.setComboValue(value)
self.setComboValue(value, combobox=self.combo)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -954,7 +1003,7 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.optional
return self.comboValue(validator)
return self.comboValue(validator, combobox=self.combo)


class TableFieldWidgetWrapper(WidgetWrapper):

0 comments on commit fc65334

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