Skip to content

Commit

Permalink
map layer data type support in modeler
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Mar 14, 2020
1 parent 56971a9 commit 70c5018
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/core/parameters.py
Expand Up @@ -78,7 +78,7 @@
PARAMETER_MULTIPLE = 'multilayer'
PARAMETER_BAND = 'band'
PARAMETER_LAYOUTITEM = 'layoutitem'
PARAMETER_MAP_LAYER = 'Map Layer'
PARAMETER_MAP_LAYER = 'layer'
PARAMETER_RANGE = 'range'
PARAMETER_ENUM = 'enum'
PARAMETER_MATRIX = 'matrix'
Expand Down
Expand Up @@ -91,7 +91,8 @@ def use_legacy_dialog(param=None, paramType=None):
parameters.PARAMETER_POINT,
parameters.PARAMETER_CRS,
parameters.PARAMETER_ENUM,
parameters.PARAMETER_MATRIX):
parameters.PARAMETER_MATRIX,
parameters.PARAMETER_MAP_LAYER):
return True
elif isinstance(param, (QgsProcessingParameterField,
QgsProcessingParameterBand,
Expand All @@ -106,6 +107,7 @@ def use_legacy_dialog(param=None, paramType=None):
QgsProcessingParameterCrs,
QgsProcessingParameterEnum,
QgsProcessingParameterMatrix,
QgsProcessingParameterMapLayer,
QgsProcessingDestinationParameter)):
return True

Expand Down Expand Up @@ -241,6 +243,20 @@ def setupUi(self):
if self.param is not None:
self.datatypeCombo.setCurrentIndex(self.datatypeCombo.findData(self.param.layerType()))
self.verticalLayout.addWidget(self.datatypeCombo)
elif (self.paramType == parameters.PARAMETER_MAP_LAYER or
isinstance(self.param, QgsProcessingParameterMapLayer)):
self.verticalLayout.addWidget(QLabel(self.tr('Data type')))
self.datatypeCombo = QComboBox()
self.datatypeCombo.addItem(self.tr('Any Map Layer'), QgsProcessing.TypeMapLayer)
self.datatypeCombo.addItem(self.tr('Vector (Point)'), QgsProcessing.TypeVectorPoint)
self.datatypeCombo.addItem(self.tr('Vector (Line)'), QgsProcessing.TypeVectorLine)
self.datatypeCombo.addItem(self.tr('Vector (Polygon)'), QgsProcessing.TypeVectorPolygon)
self.datatypeCombo.addItem(self.tr('Vector (Any Geometry Type)'), QgsProcessing.TypeVectorAnyGeometry)
self.datatypeCombo.addItem(self.tr('Raster'), QgsProcessing.TypeRaster)
self.datatypeCombo.addItem(self.tr('Mesh'), QgsProcessing.TypeMesh)
if self.param is not None:
self.datatypeCombo.setCurrentIndex(self.datatypeCombo.findData(self.param.dataTypes()[0]))
self.verticalLayout.addWidget(self.datatypeCombo)
elif (self.paramType in (parameters.PARAMETER_NUMBER, parameters.PARAMETER_DISTANCE, parameters.PARAMETER_SCALE)
or isinstance(self.param, (QgsProcessingParameterNumber, QgsProcessingParameterDistance, QgsProcessingParameterScale))):

Expand Down Expand Up @@ -453,7 +469,7 @@ def accept(self):
elif (self.paramType == parameters.PARAMETER_MAP_LAYER
or isinstance(self.param, QgsProcessingParameterMapLayer)):
self.param = QgsProcessingParameterMapLayer(
name, description)
name, description, types=[self.datatypeCombo.currentData()])
elif (self.paramType == parameters.PARAMETER_RASTER
or isinstance(self.param, QgsProcessingParameterRasterLayer)):
self.param = QgsProcessingParameterRasterLayer(
Expand Down

0 comments on commit 70c5018

Please sign in to comment.