Skip to content
Permalink
Browse files

Implement widget wrapper for QgsProcessingParameterMapLayer

  • Loading branch information
nyalldawson committed Aug 9, 2017
1 parent e0fbe34 commit 7d7c06cd851158b4133e30240d5ee5007b2240c2
Showing with 37 additions and 17 deletions.
  1. +1 −3 python/plugins/processing/algs/qgis/Rasterize.py
  2. +36 −14 python/plugins/processing/gui/wrappers.py
@@ -101,9 +101,7 @@ def initAlgorithm(self, config=None):
self.addParameter(map_theme_param)

self.addParameter(
# TODO use QgsProcessingParameterMapLayer when
# the LayerWidgetWrapper class will be implemented
QgsProcessingParameterRasterLayer(
QgsProcessingParameterMapLayer(
self.LAYER,
description=self.tr(
'Layer to render. Will only be used if the map theme '
@@ -62,6 +62,7 @@
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
QgsProcessingParameterBand,
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
@@ -626,7 +627,7 @@ def value(self):
return self.widget.getValue()


class RasterWidgetWrapper(WidgetWrapper):
class MapLayerWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'

@@ -651,11 +652,10 @@ def createWidget(self):
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
self.combo.setShowCrs(True)

self.combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.combo.setExcludedProviders(['grass'])
self.setComboBoxFilters(self.combo)

try:
if iface.activeLayer().type() == QgsMapLayer.RasterLayer:
self.combo.setLayer(iface.activeLayer())
self.combo.setLayer(iface.activeLayer())
except:
pass

@@ -666,7 +666,7 @@ def createWidget(self):
return BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
else:
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
layers = self.getAvailableLayers()
self.combo.setEditable(True)
for layer in layers:
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
@@ -687,10 +687,16 @@ def createWidget(self):
widget.setLayout(layout)
return widget

def setComboBoxFilters(self, combo):
pass

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

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
@@ -728,6 +734,28 @@ def validator(v):
return self.comboValue(validator, combobox=self.combo)


class RasterWidgetWrapper(MapLayerWidgetWrapper):

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

def setComboBoxFilters(self, combo):
combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
combo.setExcludedProviders(['grass'])

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
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)


class SelectionWidgetWrapper(WidgetWrapper):

def createWidget(self):
@@ -754,12 +782,6 @@ def value(self):
return self.widget.currentData()


class LayerWidgetWrapper(WidgetWrapper):

def __init__(self):
raise NotImplementedError('Layer widget wrapper is not implemented yet')


class VectorWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'
@@ -1395,7 +1417,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
elif param.type() == 'band':
wrapper = BandWidgetWrapper
elif param.type() == 'layer':
wrapper = LayerWidgetWrapper
wrapper = MapLayerWidgetWrapper
else:
assert False, param.type()
return wrapper(param, dialog, row, col)

0 comments on commit 7d7c06c

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