mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Add a processing parameter registry
to manage parameter metadata in a single place.
This commit is contained in:
parent
8b784400f7
commit
eba96fb9cc
@ -45,6 +45,8 @@ from qgis.core import (QgsMessageLog,
|
|||||||
QgsProcessingOutputMapLayer,
|
QgsProcessingOutputMapLayer,
|
||||||
QgsProcessingOutputMultipleLayers)
|
QgsProcessingOutputMultipleLayers)
|
||||||
|
|
||||||
|
from .parameters import initializeParameters
|
||||||
|
|
||||||
import processing
|
import processing
|
||||||
from processing.core.ProcessingConfig import ProcessingConfig
|
from processing.core.ProcessingConfig import ProcessingConfig
|
||||||
from processing.gui.MessageBarProgress import MessageBarProgress
|
from processing.gui.MessageBarProgress import MessageBarProgress
|
||||||
@ -67,6 +69,7 @@ from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
|
|||||||
|
|
||||||
class Processing(object):
|
class Processing(object):
|
||||||
BASIC_PROVIDERS = []
|
BASIC_PROVIDERS = []
|
||||||
|
REGISTERED_PARAMETERS = dict()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def activateProvider(providerOrName, activate=True):
|
def activateProvider(providerOrName, activate=True):
|
||||||
@ -97,6 +100,7 @@ class Processing(object):
|
|||||||
if QgsApplication.processingRegistry().addProvider(p):
|
if QgsApplication.processingRegistry().addProvider(p):
|
||||||
Processing.BASIC_PROVIDERS.append(p)
|
Processing.BASIC_PROVIDERS.append(p)
|
||||||
# And initialize
|
# And initialize
|
||||||
|
initializeParameters()
|
||||||
ProcessingConfig.initialize()
|
ProcessingConfig.initialize()
|
||||||
ProcessingConfig.readSettings()
|
ProcessingConfig.readSettings()
|
||||||
RenderingStyles.loadStyles()
|
RenderingStyles.loadStyles()
|
||||||
@ -107,6 +111,33 @@ class Processing(object):
|
|||||||
QgsApplication.processingRegistry().removeProvider(p)
|
QgsApplication.processingRegistry().removeProvider(p)
|
||||||
|
|
||||||
Processing.BASIC_PROVIDERS = []
|
Processing.BASIC_PROVIDERS = []
|
||||||
|
Processing.REGISTERED_PARAMETERS = dict()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def registerParameter(id, name, parameter, metadata=dict(), description=None):
|
||||||
|
"""Register a new parameter.
|
||||||
|
The ``name`` is a human readable translated string, the ``parameter`` is a class type with the base class ``qgis.core.QgsProcessingParameterDefinition``,
|
||||||
|
the ``metadata`` is a dictionary with additional metadata, mainly used for widget wrappers.
|
||||||
|
"""
|
||||||
|
Processing.REGISTERED_PARAMETERS[id] = {
|
||||||
|
'name': name,
|
||||||
|
'parameter': parameter,
|
||||||
|
'metadata': metadata,
|
||||||
|
'description': description
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unregisterParameter(name):
|
||||||
|
"""Unregister a registered parameter with the given name.
|
||||||
|
"""
|
||||||
|
del Processing.REGISTERED_PARAMETERS[name]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def registeredParameters():
|
||||||
|
"""Returns a set of registered parameters.
|
||||||
|
Each entry is a tuple consisting of a human readable name and the class.
|
||||||
|
"""
|
||||||
|
return Processing.REGISTERED_PARAMETERS
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def runAlgorithm(algOrName, parameters, onFinish=None, feedback=None, context=None):
|
def runAlgorithm(algOrName, parameters, onFinish=None, feedback=None, context=None):
|
||||||
|
@ -41,12 +41,14 @@ from qgis.core import (QgsRasterLayer,
|
|||||||
QgsProcessingParameterDefinition,
|
QgsProcessingParameterDefinition,
|
||||||
QgsProcessingParameterRasterLayer,
|
QgsProcessingParameterRasterLayer,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
|
QgsProcessingParameterBand,
|
||||||
QgsProcessingParameterBoolean,
|
QgsProcessingParameterBoolean,
|
||||||
QgsProcessingParameterCrs,
|
QgsProcessingParameterCrs,
|
||||||
QgsProcessingParameterRange,
|
QgsProcessingParameterRange,
|
||||||
QgsProcessingParameterPoint,
|
QgsProcessingParameterPoint,
|
||||||
QgsProcessingParameterEnum,
|
QgsProcessingParameterEnum,
|
||||||
QgsProcessingParameterExtent,
|
QgsProcessingParameterExtent,
|
||||||
|
QgsProcessingParameterExpression,
|
||||||
QgsProcessingParameterMatrix,
|
QgsProcessingParameterMatrix,
|
||||||
QgsProcessingParameterFile,
|
QgsProcessingParameterFile,
|
||||||
QgsProcessingParameterField,
|
QgsProcessingParameterField,
|
||||||
@ -55,10 +57,36 @@ from qgis.core import (QgsRasterLayer,
|
|||||||
QgsProcessingParameterFolderDestination,
|
QgsProcessingParameterFolderDestination,
|
||||||
QgsProcessingParameterRasterDestination,
|
QgsProcessingParameterRasterDestination,
|
||||||
QgsProcessingParameterString,
|
QgsProcessingParameterString,
|
||||||
|
QgsProcessingParameterMapLayer,
|
||||||
QgsProcessingParameterMultipleLayers,
|
QgsProcessingParameterMultipleLayers,
|
||||||
QgsProcessingParameterFeatureSource,
|
QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterNumber)
|
QgsProcessingParameterNumber)
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QCoreApplication
|
||||||
|
|
||||||
|
PARAMETER_NUMBER = 'Number'
|
||||||
|
PARAMETER_RASTER = 'Raster Layer'
|
||||||
|
PARAMETER_TABLE = 'Vector Layer'
|
||||||
|
PARAMETER_VECTOR = 'Vector Features'
|
||||||
|
PARAMETER_STRING = 'String'
|
||||||
|
PARAMETER_EXPRESSION = 'Expression'
|
||||||
|
PARAMETER_BOOLEAN = 'Boolean'
|
||||||
|
PARAMETER_TABLE_FIELD = 'Vector Field'
|
||||||
|
PARAMETER_EXTENT = 'Extent'
|
||||||
|
PARAMETER_FILE = 'File'
|
||||||
|
PARAMETER_POINT = 'Point'
|
||||||
|
PARAMETER_CRS = 'CRS'
|
||||||
|
PARAMETER_MULTIPLE = 'Multiple Input'
|
||||||
|
PARAMETER_BAND = 'Raster Band'
|
||||||
|
PARAMETER_MAP_LAYER = 'Map Layer'
|
||||||
|
PARAMETER_RANGE = 'Range'
|
||||||
|
PARAMETER_ENUM = 'Enum'
|
||||||
|
PARAMETER_MATRIX = 'Matrix'
|
||||||
|
PARAMETER_VECTOR_DESTINATION = 'Vector Destination'
|
||||||
|
PARAMETER_FILE_DESTINATION = 'File Destination'
|
||||||
|
PARAMETER_FOLDER_DESTINATION = 'Folder Destination'
|
||||||
|
PARAMETER_RASTER_DESTINATION = 'Raster Destination'
|
||||||
|
|
||||||
|
|
||||||
def getParameterFromString(s):
|
def getParameterFromString(s):
|
||||||
# Try the parameter definitions used in description files
|
# Try the parameter definitions used in description files
|
||||||
@ -209,3 +237,53 @@ def getParameterFromString(s):
|
|||||||
param = QgsProcessingParameters.parameterFromScriptCode(s)
|
param = QgsProcessingParameters.parameterFromScriptCode(s)
|
||||||
if param:
|
if param:
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|
||||||
|
def initializeParameters():
|
||||||
|
from processing.core.Processing import Processing
|
||||||
|
|
||||||
|
"""
|
||||||
|
ModelerParameterDefinitionDialog.PARAMETER_TABLE: QCoreApplication.translate('Processing',
|
||||||
|
'A vector layer parameter, e.g. for algorithms which change layer styles, edit layers in place, or other operations which affect an entire layer.'),
|
||||||
|
"""
|
||||||
|
|
||||||
|
Processing.registerParameter(PARAMETER_MAP_LAYER, QCoreApplication.translate('Processing', 'Map Layer'),
|
||||||
|
QgsProcessingParameterMapLayer,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A generic map layer parameter, which accepts either vector or raster layers.'))
|
||||||
|
Processing.registerParameter(PARAMETER_BAND, QCoreApplication.translate('Processing', 'Raster Band'),
|
||||||
|
QgsProcessingParameterBand,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A raster band parameter, for selecting an existing band from a raster source.'))
|
||||||
|
Processing.registerParameter(PARAMETER_EXPRESSION, QCoreApplication.translate('Processing', 'Expression'),
|
||||||
|
QgsProcessingParameterExpression,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A QGIS expression parameter, which presents an expression builder widget to users.'))
|
||||||
|
Processing.registerParameter(PARAMETER_RASTER, QCoreApplication.translate('Processing', 'Raster Layer'), QgsProcessingParameterRasterLayer,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A raster layer parameter.'))
|
||||||
|
Processing.registerParameter(PARAMETER_TABLE, QCoreApplication.translate('Processing', 'Vector Layer'), QgsProcessingParameterVectorLayer,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A vector feature parameter, e.g. for algorithms which operate on the features within a layer.'))
|
||||||
|
Processing.registerParameter(PARAMETER_BOOLEAN, QCoreApplication.translate('Processing', 'Boolean'), QgsProcessingParameterBoolean,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A boolean parameter, for true/false values.'))
|
||||||
|
Processing.registerParameter(PARAMETER_CRS, QCoreApplication.translate('Processing', 'CRS'), QgsProcessingParameterCrs,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A coordinate reference system (CRS) input parameter.'))
|
||||||
|
Processing.registerParameter(PARAMETER_RANGE, QCoreApplication.translate('Processing', 'Range'), QgsProcessingParameterRange)
|
||||||
|
Processing.registerParameter(PARAMETER_POINT, QCoreApplication.translate('Processing', 'Point'), QgsProcessingParameterPoint,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A geographic point parameter.'))
|
||||||
|
Processing.registerParameter(PARAMETER_ENUM, QCoreApplication.translate('Processing', 'Enum'), QgsProcessingParameterEnum)
|
||||||
|
Processing.registerParameter(PARAMETER_EXTENT, QCoreApplication.translate('Processing', 'Extent'), QgsProcessingParameterExtent,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A map extent parameter.'))
|
||||||
|
Processing.registerParameter(PARAMETER_MATRIX, QCoreApplication.translate('Processing', 'Matrix'), QgsProcessingParameterMatrix)
|
||||||
|
Processing.registerParameter(PARAMETER_FILE, QCoreApplication.translate('Processing', 'File'), QgsProcessingParameterFile,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A file parameter, for use with non-map layer file sources.'))
|
||||||
|
Processing.registerParameter(PARAMETER_TABLE_FIELD, QCoreApplication.translate('Processing', 'Field'), QgsProcessingParameterField,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A vector field parameter, for selecting an existing field from a vector source.'))
|
||||||
|
Processing.registerParameter(PARAMETER_VECTOR_DESTINATION, QCoreApplication.translate('Processing', 'Vector Destination'), QgsProcessingParameterVectorDestination)
|
||||||
|
Processing.registerParameter(PARAMETER_FILE_DESTINATION, QCoreApplication.translate('Processing', 'File Destination'), QgsProcessingParameterFileDestination)
|
||||||
|
Processing.registerParameter(PARAMETER_FOLDER_DESTINATION, QCoreApplication.translate('Processing', 'Folder Destination'), QgsProcessingParameterFolderDestination)
|
||||||
|
Processing.registerParameter(PARAMETER_RASTER_DESTINATION, QCoreApplication.translate('Processing', 'Raster Destination'), QgsProcessingParameterRasterDestination)
|
||||||
|
Processing.registerParameter(PARAMETER_STRING, QCoreApplication.translate('Processing', 'String'), QgsProcessingParameterString,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A freeform string parameter.'))
|
||||||
|
Processing.registerParameter(PARAMETER_MULTIPLE, QCoreApplication.translate('Processing', 'Multiple Layers'), QgsProcessingParameterMultipleLayers,
|
||||||
|
description=QCoreApplication.translate('Processing', 'An input allowing selection of multiple sources, including multiple map layers or file sources.'))
|
||||||
|
Processing.registerParameter(PARAMETER_VECTOR, QCoreApplication.translate('Processing', 'Feature Source'), QgsProcessingParameterFeatureSource)
|
||||||
|
Processing.registerParameter(PARAMETER_NUMBER, QCoreApplication.translate('Processing', 'Number'), QgsProcessingParameterNumber,
|
||||||
|
description=QCoreApplication.translate('Processing', 'A numeric parameter, including float or integer values.'))
|
||||||
|
Processing.registeredParameters()
|
||||||
|
@ -154,12 +154,14 @@ class ModelerDialog(BASE, WIDGET):
|
|||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
def _dropEvent(event):
|
def _dropEvent(event):
|
||||||
|
from processing.core.Processing import Processing
|
||||||
|
|
||||||
if event.mimeData().hasText():
|
if event.mimeData().hasText():
|
||||||
text = event.mimeData().text()
|
itemId = event.mimeData().text()
|
||||||
if text in ModelerParameterDefinitionDialog.paramTypes:
|
if itemId in Processing.registeredParameters():
|
||||||
self.addInputOfType(text, event.pos())
|
self.addInputOfType(itemId, event.pos())
|
||||||
else:
|
else:
|
||||||
alg = QgsApplication.processingRegistry().createAlgorithmById(text)
|
alg = QgsApplication.processingRegistry().createAlgorithmById(itemId)
|
||||||
if alg is not None:
|
if alg is not None:
|
||||||
self._addAlgorithm(alg, event.pos())
|
self._addAlgorithm(alg, event.pos())
|
||||||
event.accept()
|
event.accept()
|
||||||
@ -545,25 +547,24 @@ class ModelerDialog(BASE, WIDGET):
|
|||||||
|
|
||||||
def addInput(self):
|
def addInput(self):
|
||||||
item = self.inputsTree.currentItem()
|
item = self.inputsTree.currentItem()
|
||||||
paramType = str(item.text(0))
|
param = item.data(0, Qt.UserRole)
|
||||||
self.addInputOfType(paramType)
|
self.addInputOfType(param)
|
||||||
|
|
||||||
def addInputOfType(self, paramType, pos=None):
|
def addInputOfType(self, paramType, pos=None):
|
||||||
if paramType in ModelerParameterDefinitionDialog.paramTypes:
|
dlg = ModelerParameterDefinitionDialog(self.model, paramType)
|
||||||
dlg = ModelerParameterDefinitionDialog(self.model, paramType)
|
dlg.exec_()
|
||||||
dlg.exec_()
|
if dlg.param is not None:
|
||||||
if dlg.param is not None:
|
if pos is None:
|
||||||
if pos is None:
|
pos = self.getPositionForParameterItem()
|
||||||
pos = self.getPositionForParameterItem()
|
if isinstance(pos, QPoint):
|
||||||
if isinstance(pos, QPoint):
|
pos = QPointF(pos)
|
||||||
pos = QPointF(pos)
|
component = QgsProcessingModelParameter(dlg.param.name())
|
||||||
component = QgsProcessingModelParameter(dlg.param.name())
|
component.setDescription(dlg.param.name())
|
||||||
component.setDescription(dlg.param.name())
|
component.setPosition(pos)
|
||||||
component.setPosition(pos)
|
self.model.addModelParameter(dlg.param, component)
|
||||||
self.model.addModelParameter(dlg.param, component)
|
self.repaintModel()
|
||||||
self.repaintModel()
|
# self.view.ensureVisible(self.scene.getLastParameterItem())
|
||||||
# self.view.ensureVisible(self.scene.getLastParameterItem())
|
self.hasChanged = True
|
||||||
self.hasChanged = True
|
|
||||||
|
|
||||||
def getPositionForParameterItem(self):
|
def getPositionForParameterItem(self):
|
||||||
MARGIN = 20
|
MARGIN = 20
|
||||||
@ -620,15 +621,19 @@ class ModelerDialog(BASE, WIDGET):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def fillInputsTree(self):
|
def fillInputsTree(self):
|
||||||
|
from processing.core.Processing import Processing
|
||||||
|
|
||||||
icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg'))
|
icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg'))
|
||||||
parametersItem = QTreeWidgetItem()
|
parametersItem = QTreeWidgetItem()
|
||||||
parametersItem.setText(0, self.tr('Parameters'))
|
parametersItem.setText(0, self.tr('Parameters'))
|
||||||
for paramType in sorted(ModelerParameterDefinitionDialog.paramTypes):
|
sortedParams = sorted(Processing.registeredParameters().items())
|
||||||
|
for param in sortedParams:
|
||||||
paramItem = QTreeWidgetItem()
|
paramItem = QTreeWidgetItem()
|
||||||
paramItem.setText(0, paramType)
|
paramItem.setText(0, param[0])
|
||||||
|
paramItem.setData(0, Qt.UserRole, param[1]['parameter'])
|
||||||
paramItem.setIcon(0, icon)
|
paramItem.setIcon(0, icon)
|
||||||
paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled)
|
paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled)
|
||||||
paramItem.setToolTip(0, ModelerParameterDefinitionDialog.inputTooltip(paramType))
|
paramItem.setToolTip(0, param[1]['description'])
|
||||||
parametersItem.addChild(paramItem)
|
parametersItem.addChild(paramItem)
|
||||||
self.inputsTree.addTopLevelItem(parametersItem)
|
self.inputsTree.addTopLevelItem(parametersItem)
|
||||||
parametersItem.setExpanded(True)
|
parametersItem.setExpanded(True)
|
||||||
|
@ -62,41 +62,10 @@ from qgis.PyQt.QtWidgets import (QDialog,
|
|||||||
QDialogButtonBox,
|
QDialogButtonBox,
|
||||||
QMessageBox)
|
QMessageBox)
|
||||||
|
|
||||||
|
from processing.core import parameters
|
||||||
|
|
||||||
|
|
||||||
class ModelerParameterDefinitionDialog(QDialog):
|
class ModelerParameterDefinitionDialog(QDialog):
|
||||||
PARAMETER_NUMBER = 'Number'
|
|
||||||
PARAMETER_RASTER = 'Raster Layer'
|
|
||||||
PARAMETER_TABLE = 'Vector Layer'
|
|
||||||
PARAMETER_VECTOR = 'Vector Features'
|
|
||||||
PARAMETER_STRING = 'String'
|
|
||||||
PARAMETER_EXPRESSION = 'Expression'
|
|
||||||
PARAMETER_BOOLEAN = 'Boolean'
|
|
||||||
PARAMETER_TABLE_FIELD = 'Vector Field'
|
|
||||||
PARAMETER_EXTENT = 'Extent'
|
|
||||||
PARAMETER_FILE = 'File'
|
|
||||||
PARAMETER_POINT = 'Point'
|
|
||||||
PARAMETER_CRS = 'CRS'
|
|
||||||
PARAMETER_MULTIPLE = 'Multiple Input'
|
|
||||||
PARAMETER_BAND = 'Raster Band'
|
|
||||||
PARAMETER_MAP_LAYER = 'Map Layer'
|
|
||||||
|
|
||||||
paramTypes = [
|
|
||||||
PARAMETER_BOOLEAN,
|
|
||||||
PARAMETER_EXTENT,
|
|
||||||
PARAMETER_FILE,
|
|
||||||
PARAMETER_NUMBER,
|
|
||||||
PARAMETER_RASTER,
|
|
||||||
PARAMETER_STRING,
|
|
||||||
PARAMETER_EXPRESSION,
|
|
||||||
PARAMETER_MAP_LAYER,
|
|
||||||
PARAMETER_TABLE,
|
|
||||||
PARAMETER_TABLE_FIELD,
|
|
||||||
PARAMETER_VECTOR,
|
|
||||||
PARAMETER_POINT,
|
|
||||||
PARAMETER_CRS,
|
|
||||||
PARAMETER_MULTIPLE,
|
|
||||||
PARAMETER_BAND
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, alg, paramType=None, param=None):
|
def __init__(self, alg, paramType=None, param=None):
|
||||||
self.alg = alg
|
self.alg = alg
|
||||||
@ -128,7 +97,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
if isinstance(self.param, QgsProcessingParameterDefinition):
|
if isinstance(self.param, QgsProcessingParameterDefinition):
|
||||||
self.nameTextBox.setText(self.param.description())
|
self.nameTextBox.setText(self.param.description())
|
||||||
|
|
||||||
if self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN or \
|
if self.paramType == parameters.PARAMETER_BOOLEAN or \
|
||||||
isinstance(self.param, QgsProcessingParameterBoolean):
|
isinstance(self.param, QgsProcessingParameterBoolean):
|
||||||
self.state = QCheckBox()
|
self.state = QCheckBox()
|
||||||
self.state.setText(self.tr('Checked'))
|
self.state.setText(self.tr('Checked'))
|
||||||
@ -136,7 +105,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
if self.param is not None:
|
if self.param is not None:
|
||||||
self.state.setChecked(bool(self.param.defaultValue()))
|
self.state.setChecked(bool(self.param.defaultValue()))
|
||||||
self.verticalLayout.addWidget(self.state)
|
self.verticalLayout.addWidget(self.state)
|
||||||
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or \
|
elif self.paramType == parameters.PARAMETER_TABLE_FIELD or \
|
||||||
isinstance(self.param, QgsProcessingParameterField):
|
isinstance(self.param, QgsProcessingParameterField):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
||||||
self.parentCombo = QComboBox()
|
self.parentCombo = QComboBox()
|
||||||
@ -183,7 +152,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
self.defaultTextBox.setText(str(default))
|
self.defaultTextBox.setText(str(default))
|
||||||
self.verticalLayout.addWidget(self.defaultTextBox)
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
||||||
|
|
||||||
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BAND or \
|
elif self.paramType == parameters.PARAMETER_BAND or \
|
||||||
isinstance(self.param, QgsProcessingParameterBand):
|
isinstance(self.param, QgsProcessingParameterBand):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
||||||
self.parentCombo = QComboBox()
|
self.parentCombo = QComboBox()
|
||||||
@ -198,7 +167,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
idx += 1
|
idx += 1
|
||||||
self.verticalLayout.addWidget(self.parentCombo)
|
self.verticalLayout.addWidget(self.parentCombo)
|
||||||
elif (self.paramType in (
|
elif (self.paramType in (
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_VECTOR, ModelerParameterDefinitionDialog.PARAMETER_TABLE) or
|
parameters.PARAMETER_VECTOR, parameters.PARAMETER_TABLE) or
|
||||||
isinstance(self.param, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer))):
|
isinstance(self.param, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer))):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Geometry type')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Geometry type')))
|
||||||
self.shapetypeCombo = QComboBox()
|
self.shapetypeCombo = QComboBox()
|
||||||
@ -210,7 +179,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
if self.param is not None:
|
if self.param is not None:
|
||||||
self.shapetypeCombo.setCurrentIndex(self.shapetypeCombo.findData(self.param.dataTypes()[0]))
|
self.shapetypeCombo.setCurrentIndex(self.shapetypeCombo.findData(self.param.dataTypes()[0]))
|
||||||
self.verticalLayout.addWidget(self.shapetypeCombo)
|
self.verticalLayout.addWidget(self.shapetypeCombo)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or
|
elif (self.paramType == parameters.PARAMETER_MULTIPLE or
|
||||||
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Data type')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Data type')))
|
||||||
self.datatypeCombo = QComboBox()
|
self.datatypeCombo = QComboBox()
|
||||||
@ -225,7 +194,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
if self.param is not None:
|
if self.param is not None:
|
||||||
self.datatypeCombo.setCurrentIndex(self.datatypeCombo.findData(self.param.layerType()))
|
self.datatypeCombo.setCurrentIndex(self.datatypeCombo.findData(self.param.layerType()))
|
||||||
self.verticalLayout.addWidget(self.datatypeCombo)
|
self.verticalLayout.addWidget(self.datatypeCombo)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or
|
elif (self.paramType == parameters.PARAMETER_NUMBER or
|
||||||
isinstance(self.param, QgsProcessingParameterNumber)):
|
isinstance(self.param, QgsProcessingParameterNumber)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
|
||||||
self.minTextBox = QLineEdit()
|
self.minTextBox = QLineEdit()
|
||||||
@ -246,7 +215,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
if default:
|
if default:
|
||||||
self.defaultTextBox.setText(str(default))
|
self.defaultTextBox.setText(str(default))
|
||||||
self.verticalLayout.addWidget(self.defaultTextBox)
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXPRESSION or
|
elif (self.paramType == parameters.PARAMETER_EXPRESSION or
|
||||||
isinstance(self.param, QgsProcessingParameterExpression)):
|
isinstance(self.param, QgsProcessingParameterExpression)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
||||||
self.defaultEdit = QgsExpressionLineEdit()
|
self.defaultEdit = QgsExpressionLineEdit()
|
||||||
@ -267,14 +236,14 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
self.parentCombo.setCurrentIndex(idx)
|
self.parentCombo.setCurrentIndex(idx)
|
||||||
idx += 1
|
idx += 1
|
||||||
self.verticalLayout.addWidget(self.parentCombo)
|
self.verticalLayout.addWidget(self.parentCombo)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or
|
elif (self.paramType == parameters.PARAMETER_STRING or
|
||||||
isinstance(self.param, QgsProcessingParameterString)):
|
isinstance(self.param, QgsProcessingParameterString)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
||||||
self.defaultTextBox = QLineEdit()
|
self.defaultTextBox = QLineEdit()
|
||||||
if self.param is not None:
|
if self.param is not None:
|
||||||
self.defaultTextBox.setText(self.param.defaultValue())
|
self.defaultTextBox.setText(self.param.defaultValue())
|
||||||
self.verticalLayout.addWidget(self.defaultTextBox)
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or
|
elif (self.paramType == parameters.PARAMETER_FILE or
|
||||||
isinstance(self.param, QgsProcessingParameterFile)):
|
isinstance(self.param, QgsProcessingParameterFile)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Type')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Type')))
|
||||||
self.fileFolderCombo = QComboBox()
|
self.fileFolderCombo = QComboBox()
|
||||||
@ -284,14 +253,14 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
self.fileFolderCombo.setCurrentIndex(
|
self.fileFolderCombo.setCurrentIndex(
|
||||||
1 if self.param.behavior() == QgsProcessingParameterFile.Folder else 0)
|
1 if self.param.behavior() == QgsProcessingParameterFile.Folder else 0)
|
||||||
self.verticalLayout.addWidget(self.fileFolderCombo)
|
self.verticalLayout.addWidget(self.fileFolderCombo)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or
|
elif (self.paramType == parameters.PARAMETER_POINT or
|
||||||
isinstance(self.param, QgsProcessingParameterPoint)):
|
isinstance(self.param, QgsProcessingParameterPoint)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
||||||
self.defaultTextBox = QLineEdit()
|
self.defaultTextBox = QLineEdit()
|
||||||
if self.param is not None:
|
if self.param is not None:
|
||||||
self.defaultTextBox.setText(self.param.defaultValue())
|
self.defaultTextBox.setText(self.param.defaultValue())
|
||||||
self.verticalLayout.addWidget(self.defaultTextBox)
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
|
elif (self.paramType == parameters.PARAMETER_CRS or
|
||||||
isinstance(self.param, QgsProcessingParameterCrs)):
|
isinstance(self.param, QgsProcessingParameterCrs)):
|
||||||
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
||||||
self.selector = QgsProjectionSelectionWidget()
|
self.selector = QgsProjectionSelectionWidget()
|
||||||
@ -339,10 +308,10 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
name = self.param.name()
|
name = self.param.name()
|
||||||
if (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN or
|
if (self.paramType == parameters.PARAMETER_BOOLEAN or
|
||||||
isinstance(self.param, QgsProcessingParameterBoolean)):
|
isinstance(self.param, QgsProcessingParameterBoolean)):
|
||||||
self.param = QgsProcessingParameterBoolean(name, description, self.state.isChecked())
|
self.param = QgsProcessingParameterBoolean(name, description, self.state.isChecked())
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or
|
elif (self.paramType == parameters.PARAMETER_TABLE_FIELD or
|
||||||
isinstance(self.param, QgsProcessingParameterField)):
|
isinstance(self.param, QgsProcessingParameterField)):
|
||||||
if self.parentCombo.currentIndex() < 0:
|
if self.parentCombo.currentIndex() < 0:
|
||||||
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
||||||
@ -356,7 +325,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
self.param = QgsProcessingParameterField(name, description, defaultValue=default,
|
self.param = QgsProcessingParameterField(name, description, defaultValue=default,
|
||||||
parentLayerParameterName=parent, type=datatype,
|
parentLayerParameterName=parent, type=datatype,
|
||||||
allowMultiple=self.multipleCheck.isChecked())
|
allowMultiple=self.multipleCheck.isChecked())
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BAND or
|
elif (self.paramType == parameters.PARAMETER_BAND or
|
||||||
isinstance(self.param, QgsProcessingParameterBand)):
|
isinstance(self.param, QgsProcessingParameterBand)):
|
||||||
if self.parentCombo.currentIndex() < 0:
|
if self.parentCombo.currentIndex() < 0:
|
||||||
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
||||||
@ -364,30 +333,30 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
return
|
return
|
||||||
parent = self.parentCombo.currentData()
|
parent = self.parentCombo.currentData()
|
||||||
self.param = QgsProcessingParameterBand(name, description, None, parent)
|
self.param = QgsProcessingParameterBand(name, description, None, parent)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MAP_LAYER or
|
elif (self.paramType == parameters.PARAMETER_MAP_LAYER or
|
||||||
isinstance(self.param, QgsProcessingParameterMapLayer)):
|
isinstance(self.param, QgsProcessingParameterMapLayer)):
|
||||||
self.param = QgsProcessingParameterMapLayer(
|
self.param = QgsProcessingParameterMapLayer(
|
||||||
name, description)
|
name, description)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or
|
elif (self.paramType == parameters.PARAMETER_RASTER or
|
||||||
isinstance(self.param, QgsProcessingParameterRasterLayer)):
|
isinstance(self.param, QgsProcessingParameterRasterLayer)):
|
||||||
self.param = QgsProcessingParameterRasterLayer(
|
self.param = QgsProcessingParameterRasterLayer(
|
||||||
name, description)
|
name, description)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE or
|
elif (self.paramType == parameters.PARAMETER_TABLE or
|
||||||
isinstance(self.param, QgsProcessingParameterVectorLayer)):
|
isinstance(self.param, QgsProcessingParameterVectorLayer)):
|
||||||
self.param = QgsProcessingParameterVectorLayer(
|
self.param = QgsProcessingParameterVectorLayer(
|
||||||
name, description,
|
name, description,
|
||||||
[self.shapetypeCombo.currentData()])
|
[self.shapetypeCombo.currentData()])
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or
|
elif (self.paramType == parameters.PARAMETER_VECTOR or
|
||||||
isinstance(self.param, QgsProcessingParameterFeatureSource)):
|
isinstance(self.param, QgsProcessingParameterFeatureSource)):
|
||||||
self.param = QgsProcessingParameterFeatureSource(
|
self.param = QgsProcessingParameterFeatureSource(
|
||||||
name, description,
|
name, description,
|
||||||
[self.shapetypeCombo.currentData()])
|
[self.shapetypeCombo.currentData()])
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or
|
elif (self.paramType == parameters.PARAMETER_MULTIPLE or
|
||||||
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
||||||
self.param = QgsProcessingParameterMultipleLayers(
|
self.param = QgsProcessingParameterMultipleLayers(
|
||||||
name, description,
|
name, description,
|
||||||
self.datatypeCombo.currentData())
|
self.datatypeCombo.currentData())
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or
|
elif (self.paramType == parameters.PARAMETER_NUMBER or
|
||||||
isinstance(self.param, QgsProcessingParameterNumber)):
|
isinstance(self.param, QgsProcessingParameterNumber)):
|
||||||
try:
|
try:
|
||||||
self.param = QgsProcessingParameterNumber(name, description, QgsProcessingParameterNumber.Double,
|
self.param = QgsProcessingParameterNumber(name, description, QgsProcessingParameterNumber.Double,
|
||||||
@ -402,31 +371,39 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
||||||
self.tr('Wrong or missing parameter values'))
|
self.tr('Wrong or missing parameter values'))
|
||||||
return
|
return
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXPRESSION or
|
elif (self.paramType == parameters.PARAMETER_EXPRESSION or
|
||||||
isinstance(self.param, QgsProcessingParameterExpression)):
|
isinstance(self.param, QgsProcessingParameterExpression)):
|
||||||
parent = self.parentCombo.currentData()
|
parent = self.parentCombo.currentData()
|
||||||
self.param = QgsProcessingParameterExpression(name, description,
|
self.param = QgsProcessingParameterExpression(name, description,
|
||||||
str(self.defaultEdit.expression()),
|
str(self.defaultEdit.expression()),
|
||||||
parent)
|
parent)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or
|
elif (self.paramType == parameters.PARAMETER_STRING or
|
||||||
isinstance(self.param, QgsProcessingParameterString)):
|
isinstance(self.param, QgsProcessingParameterString)):
|
||||||
self.param = QgsProcessingParameterString(name, description,
|
self.param = QgsProcessingParameterString(name, description,
|
||||||
str(self.defaultTextBox.text()))
|
str(self.defaultTextBox.text()))
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXTENT or
|
elif (self.paramType == parameters.PARAMETER_EXTENT or
|
||||||
isinstance(self.param, QgsProcessingParameterExtent)):
|
isinstance(self.param, QgsProcessingParameterExtent)):
|
||||||
self.param = QgsProcessingParameterExtent(name, description)
|
self.param = QgsProcessingParameterExtent(name, description)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or
|
elif (self.paramType == parameters.PARAMETER_FILE or
|
||||||
isinstance(self.param, QgsProcessingParameterFile)):
|
isinstance(self.param, QgsProcessingParameterFile)):
|
||||||
isFolder = self.fileFolderCombo.currentIndex() == 1
|
isFolder = self.fileFolderCombo.currentIndex() == 1
|
||||||
self.param = QgsProcessingParameterFile(name, description,
|
self.param = QgsProcessingParameterFile(name, description,
|
||||||
QgsProcessingParameterFile.Folder if isFolder else QgsProcessingParameterFile.File)
|
QgsProcessingParameterFile.Folder if isFolder else QgsProcessingParameterFile.File)
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or
|
elif (self.paramType == parameters.PARAMETER_POINT or
|
||||||
isinstance(self.param, QgsProcessingParameterPoint)):
|
isinstance(self.param, QgsProcessingParameterPoint)):
|
||||||
self.param = QgsProcessingParameterPoint(name, description,
|
self.param = QgsProcessingParameterPoint(name, description,
|
||||||
str(self.defaultTextBox.text()))
|
str(self.defaultTextBox.text()))
|
||||||
elif (self.paramType == ModelerParameterDefinitionDialog.PARAMETER_CRS or
|
elif (self.paramType == parameters.PARAMETER_CRS or
|
||||||
isinstance(self.param, QgsProcessingParameterCrs)):
|
isinstance(self.param, QgsProcessingParameterCrs)):
|
||||||
self.param = QgsProcessingParameterCrs(name, description, self.selector.crs().authid())
|
self.param = QgsProcessingParameterCrs(name, description, self.selector.crs().authid())
|
||||||
|
else:
|
||||||
|
from processing.core.Processing import Processing
|
||||||
|
|
||||||
|
param = Processing.registeredParameters()[self.paramType]
|
||||||
|
|
||||||
|
self.param = param['parameter'](name, description, None)
|
||||||
|
self.param.setMetadata(param['metadata'])
|
||||||
|
|
||||||
if not self.requiredCheck.isChecked():
|
if not self.requiredCheck.isChecked():
|
||||||
self.param.setFlags(self.param.flags() | QgsProcessingParameterDefinition.FlagOptional)
|
self.param.setFlags(self.param.flags() | QgsProcessingParameterDefinition.FlagOptional)
|
||||||
|
|
||||||
@ -442,24 +419,3 @@ class ModelerParameterDefinitionDialog(QDialog):
|
|||||||
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
|
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
|
||||||
|
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def inputTooltip(input_type):
|
|
||||||
tooltips = {
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_NUMBER: QCoreApplication.translate('Processing', 'A numeric parameter, including float or integer values.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_RASTER: QCoreApplication.translate('Processing', 'A raster layer parameter.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_TABLE: QCoreApplication.translate('Processing', 'A vector layer parameter, e.g. for algorithms which change layer styles, edit layers in place, or other operations which affect an entire layer.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_VECTOR: QCoreApplication.translate('Processing', 'A vector feature parameter, e.g. for algorithms which operate on the features within a layer.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_STRING: QCoreApplication.translate('Processing', 'A freeform string parameter.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_EXPRESSION: QCoreApplication.translate('Processing', 'A QGIS expression parameter, which presents an expression builder widget to users.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN: QCoreApplication.translate('Processing', 'A boolean parameter, for true/false values.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD: QCoreApplication.translate('Processing', 'A vector field parameter, for selecting an existing field from a vector source.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_EXTENT: QCoreApplication.translate('Processing', 'A map extent parameter.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_FILE: QCoreApplication.translate('Processing', 'A file parameter, for use with non-map layer file sources.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_POINT: QCoreApplication.translate('Processing', 'A geographic point parameter.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_CRS: QCoreApplication.translate('Processing', 'A coordinate reference system (CRS) input parameter.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE: QCoreApplication.translate('Processing', 'An input allowing selection of multiple sources, including multiple map layers or file sources.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_BAND: QCoreApplication.translate('Processing', 'A raster band parameter, for selecting an existing band from a raster source.'),
|
|
||||||
ModelerParameterDefinitionDialog.PARAMETER_MAP_LAYER: QCoreApplication.translate('Processing', 'A generic map layer parameter, which accepts either vector or raster layers.')
|
|
||||||
}
|
|
||||||
return tooltips[input_type]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user