2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ModelerParameterDefinitionDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2013-08-20 11:04:32 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-04 19:33:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2014-10-19 19:29:26 +02:00
|
|
|
import math
|
|
|
|
|
2018-05-04 12:00:43 +03:00
|
|
|
from qgis.PyQt.QtCore import (Qt,
|
|
|
|
QByteArray,
|
|
|
|
QCoreApplication)
|
|
|
|
from qgis.PyQt.QtWidgets import (QDialog,
|
|
|
|
QVBoxLayout,
|
|
|
|
QLabel,
|
|
|
|
QLineEdit,
|
|
|
|
QComboBox,
|
|
|
|
QCheckBox,
|
|
|
|
QDialogButtonBox,
|
|
|
|
QMessageBox)
|
|
|
|
|
2016-11-11 19:46:42 +10:00
|
|
|
from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget
|
2018-03-03 11:16:35 -05:00
|
|
|
from qgis.core import (QgsApplication,
|
|
|
|
QgsSettings,
|
2017-08-19 03:36:33 +10:00
|
|
|
QgsProcessing,
|
2017-07-08 16:05:39 +10:00
|
|
|
QgsCoordinateReferenceSystem,
|
2017-06-13 13:22:19 +10:00
|
|
|
QgsProcessingParameterDefinition,
|
|
|
|
QgsProcessingParameterBoolean,
|
|
|
|
QgsProcessingParameterCrs,
|
|
|
|
QgsProcessingParameterMapLayer,
|
|
|
|
QgsProcessingParameterExtent,
|
|
|
|
QgsProcessingParameterPoint,
|
|
|
|
QgsProcessingParameterFile,
|
|
|
|
QgsProcessingParameterMatrix,
|
|
|
|
QgsProcessingParameterMultipleLayers,
|
|
|
|
QgsProcessingParameterNumber,
|
2018-04-19 17:24:13 +10:00
|
|
|
QgsProcessingParameterDistance,
|
2017-06-13 13:22:19 +10:00
|
|
|
QgsProcessingParameterRange,
|
|
|
|
QgsProcessingParameterRasterLayer,
|
|
|
|
QgsProcessingParameterEnum,
|
|
|
|
QgsProcessingParameterString,
|
|
|
|
QgsProcessingParameterExpression,
|
2017-06-21 22:13:16 +10:00
|
|
|
QgsProcessingParameterVectorLayer,
|
|
|
|
QgsProcessingParameterField,
|
2017-08-04 10:43:42 +03:00
|
|
|
QgsProcessingParameterFeatureSource,
|
2018-03-03 11:16:35 -05:00
|
|
|
QgsProcessingParameterBand
|
|
|
|
)
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2018-05-04 12:00:43 +03:00
|
|
|
from processing.gui.enummodelerwidget import EnumModelerWidget
|
2018-02-28 16:48:50 -05:00
|
|
|
from processing.core import parameters
|
2018-05-04 12:00:43 +03:00
|
|
|
from processing.modeler.exceptions import UndefinedParameterException
|
2018-02-28 16:48:50 -05:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
class ModelerParameterDefinitionDialog(QDialog):
|
2013-10-01 20:52:22 +03:00
|
|
|
|
|
|
|
def __init__(self, alg, paramType=None, param=None):
|
|
|
|
self.alg = alg
|
2012-09-15 18:25:25 +03:00
|
|
|
self.paramType = paramType
|
|
|
|
self.param = param
|
2014-09-12 12:33:06 +03:00
|
|
|
QDialog.__init__(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setModal(True)
|
|
|
|
self.setupUi()
|
2017-07-08 16:05:39 +10:00
|
|
|
settings = QgsSettings()
|
|
|
|
self.restoreGeometry(settings.value("/Processing/modelParametersDefinitionDialogGeometry", QByteArray()))
|
|
|
|
|
|
|
|
def closeEvent(self, event):
|
|
|
|
settings = QgsSettings()
|
|
|
|
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
|
|
|
|
super(ModelerParameterDefinitionDialog, self).closeEvent(event)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def setupUi(self):
|
2017-11-18 18:52:45 +01:00
|
|
|
self.setWindowTitle(self.tr('Parameter Definition'))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.setMinimumWidth(300)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
self.verticalLayout = QVBoxLayout(self)
|
2012-09-15 18:25:25 +03:00
|
|
|
self.verticalLayout.setMargin(20)
|
|
|
|
|
2014-10-03 21:56:24 +03:00
|
|
|
self.label = QLabel(self.tr('Parameter name'))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.label)
|
2014-09-12 12:33:06 +03:00
|
|
|
self.nameTextBox = QLineEdit()
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.nameTextBox)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2017-05-16 16:36:00 +10:00
|
|
|
if isinstance(self.param, QgsProcessingParameterDefinition):
|
|
|
|
self.nameTextBox.setText(self.param.description())
|
2012-11-10 00:31:01 +01:00
|
|
|
|
2018-02-28 16:48:50 -05:00
|
|
|
if self.paramType == parameters.PARAMETER_BOOLEAN or \
|
2017-06-13 13:22:19 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterBoolean):
|
2014-09-12 12:33:06 +03:00
|
|
|
self.state = QCheckBox()
|
2014-10-03 21:56:24 +03:00
|
|
|
self.state.setText(self.tr('Checked'))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.state.setChecked(False)
|
2013-01-12 23:36:00 +01:00
|
|
|
if self.param is not None:
|
2017-06-13 13:22:19 +10:00
|
|
|
self.state.setChecked(bool(self.param.defaultValue()))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.state)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif self.paramType == parameters.PARAMETER_TABLE_FIELD or \
|
2017-06-21 22:13:16 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterField):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.parentCombo = QComboBox()
|
2013-10-01 20:52:22 +03:00
|
|
|
idx = 0
|
2017-06-13 16:05:59 +10:00
|
|
|
for param in list(self.alg.parameterComponents().values()):
|
|
|
|
definition = self.alg.parameterDefinition(param.parameterName())
|
2017-06-21 22:13:16 +10:00
|
|
|
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
|
2017-06-13 16:05:59 +10:00
|
|
|
self.parentCombo.addItem(definition.description(), definition.name())
|
2013-01-12 12:40:34 +01:00
|
|
|
if self.param is not None:
|
2017-08-04 12:34:06 +03:00
|
|
|
if self.param.parentLayerParameterName() == definition.name():
|
2013-01-12 12:40:34 +01:00
|
|
|
self.parentCombo.setCurrentIndex(idx)
|
2013-01-12 23:36:00 +01:00
|
|
|
idx += 1
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.parentCombo)
|
2016-06-02 12:14:59 +02:00
|
|
|
|
|
|
|
# add the datatype selector
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Allowed data type')))
|
2016-06-02 12:14:59 +02:00
|
|
|
self.datatypeCombo = QComboBox()
|
|
|
|
self.datatypeCombo.addItem(self.tr('Any'), -1)
|
|
|
|
self.datatypeCombo.addItem(self.tr('Number'), 0)
|
|
|
|
self.datatypeCombo.addItem(self.tr('String'), 1)
|
2016-11-30 15:04:21 +10:00
|
|
|
self.datatypeCombo.addItem(self.tr('Date/time'), 2)
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.datatypeCombo)
|
2016-06-02 12:14:59 +02:00
|
|
|
|
2017-06-13 13:22:19 +10:00
|
|
|
if self.param is not None and self.param.dataType() is not None:
|
2016-06-02 12:14:59 +02:00
|
|
|
# QComboBoxes indexes start at 0,
|
|
|
|
# self.param.datatype start with -1 that is why I need to do +1
|
2017-06-13 13:22:19 +10:00
|
|
|
datatypeIndex = self.param.dataType() + 1
|
2016-09-16 09:13:16 +02:00
|
|
|
self.datatypeCombo.setCurrentIndex(datatypeIndex)
|
2016-06-02 12:14:59 +02:00
|
|
|
|
2016-10-31 11:41:40 +10:00
|
|
|
self.multipleCheck = QCheckBox()
|
|
|
|
self.multipleCheck.setText(self.tr('Accept multiple fields'))
|
|
|
|
self.multipleCheck.setChecked(False)
|
|
|
|
if self.param is not None:
|
2017-06-13 13:22:19 +10:00
|
|
|
self.multipleCheck.setChecked(self.param.allowMultiple())
|
2016-10-31 11:41:40 +10:00
|
|
|
self.verticalLayout.addWidget(self.multipleCheck)
|
2017-09-21 11:04:38 +10:00
|
|
|
|
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
|
|
|
self.defaultTextBox = QLineEdit()
|
2017-09-22 10:56:32 +10:00
|
|
|
self.defaultTextBox.setToolTip(
|
|
|
|
self.tr('Default field name, or ; separated list of field names for multiple field parameters'))
|
2017-09-21 11:04:38 +10:00
|
|
|
if self.param is not None:
|
|
|
|
default = self.param.defaultValue()
|
|
|
|
if default is not None:
|
|
|
|
self.defaultTextBox.setText(str(default))
|
|
|
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
|
|
|
|
2018-02-28 16:48:50 -05:00
|
|
|
elif self.paramType == parameters.PARAMETER_BAND or \
|
2017-08-04 10:43:42 +03:00
|
|
|
isinstance(self.param, QgsProcessingParameterBand):
|
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
|
|
|
self.parentCombo = QComboBox()
|
|
|
|
idx = 0
|
|
|
|
for param in list(self.alg.parameterComponents().values()):
|
|
|
|
definition = self.alg.parameterDefinition(param.parameterName())
|
|
|
|
if isinstance(definition, (QgsProcessingParameterRasterLayer)):
|
|
|
|
self.parentCombo.addItem(definition.description(), definition.name())
|
|
|
|
if self.param is not None:
|
2017-08-04 12:34:06 +03:00
|
|
|
if self.param.parentLayerParameterName() == definition.name():
|
2017-08-04 10:43:42 +03:00
|
|
|
self.parentCombo.setCurrentIndex(idx)
|
|
|
|
idx += 1
|
|
|
|
self.verticalLayout.addWidget(self.parentCombo)
|
2017-09-22 10:56:32 +10:00
|
|
|
elif (self.paramType in (
|
2018-02-28 16:48:50 -05:00
|
|
|
parameters.PARAMETER_VECTOR, parameters.PARAMETER_TABLE) or
|
2017-08-19 03:36:33 +10:00
|
|
|
isinstance(self.param, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer))):
|
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Geometry type')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.shapetypeCombo = QComboBox()
|
2017-08-19 03:36:33 +10:00
|
|
|
self.shapetypeCombo.addItem(self.tr('Geometry Not Required'), QgsProcessing.TypeVector)
|
|
|
|
self.shapetypeCombo.addItem(self.tr('Point'), QgsProcessing.TypeVectorPoint)
|
|
|
|
self.shapetypeCombo.addItem(self.tr('Line'), QgsProcessing.TypeVectorLine)
|
|
|
|
self.shapetypeCombo.addItem(self.tr('Polygon'), QgsProcessing.TypeVectorPolygon)
|
|
|
|
self.shapetypeCombo.addItem(self.tr('Any Geometry Type'), QgsProcessing.TypeVectorAnyGeometry)
|
2013-01-12 23:36:00 +01:00
|
|
|
if self.param is not None:
|
2017-08-19 03:36:33 +10:00
|
|
|
self.shapetypeCombo.setCurrentIndex(self.shapetypeCombo.findData(self.param.dataTypes()[0]))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.shapetypeCombo)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_MULTIPLE or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Data type')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.datatypeCombo = QComboBox()
|
2017-08-19 03:36:33 +10:00
|
|
|
self.datatypeCombo.addItem(self.tr('Any Map Layer'), QgsProcessing.TypeMapLayer)
|
|
|
|
self.datatypeCombo.addItem(self.tr('Vector (No Geometry Required)'), QgsProcessing.TypeVector)
|
|
|
|
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('File'), QgsProcessing.TypeFile)
|
2013-01-12 23:36:00 +01:00
|
|
|
if self.param is not None:
|
2017-08-19 03:36:33 +10:00
|
|
|
self.datatypeCombo.setCurrentIndex(self.datatypeCombo.findData(self.param.layerType()))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.datatypeCombo)
|
2018-04-19 17:24:13 +10:00
|
|
|
elif (self.paramType == parameters.PARAMETER_NUMBER or self.paramType == parameters.PARAMETER_DISTANCE or
|
|
|
|
isinstance(self.param, (QgsProcessingParameterNumber, QgsProcessingParameterDistance))):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Min value')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.minTextBox = QLineEdit()
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.minTextBox)
|
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Max value')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.maxTextBox = QLineEdit()
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.maxTextBox)
|
2014-10-19 19:29:26 +02:00
|
|
|
if self.param is not None:
|
2017-06-13 13:22:19 +10:00
|
|
|
self.minTextBox.setText(str(self.param.minimum()))
|
|
|
|
self.maxTextBox.setText(str(self.param.maximum()))
|
2016-10-31 09:12:39 +10:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.defaultTextBox = QLineEdit()
|
2014-10-03 21:56:24 +03:00
|
|
|
self.defaultTextBox.setText(self.tr('0'))
|
2013-01-12 23:36:00 +01:00
|
|
|
if self.param is not None:
|
2017-06-13 13:22:19 +10:00
|
|
|
default = self.param.defaultValue()
|
|
|
|
if self.param.dataType() == QgsProcessingParameterNumber.Integer:
|
2014-10-19 19:29:26 +02:00
|
|
|
default = int(math.floor(default))
|
2016-09-12 06:17:23 +02:00
|
|
|
if default:
|
2016-09-27 19:51:06 +02:00
|
|
|
self.defaultTextBox.setText(str(default))
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_EXPRESSION or
|
2017-06-13 13:22:19 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterExpression)):
|
2016-11-03 16:37:00 +10:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
|
|
|
self.defaultEdit = QgsExpressionLineEdit()
|
|
|
|
if self.param is not None:
|
2017-05-16 16:36:00 +10:00
|
|
|
self.defaultEdit.setExpression(self.param.defaultValue())
|
2016-11-03 16:37:00 +10:00
|
|
|
self.verticalLayout.addWidget(self.defaultEdit)
|
|
|
|
|
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Parent layer')))
|
|
|
|
self.parentCombo = QComboBox()
|
2016-11-11 12:03:33 +10:00
|
|
|
self.parentCombo.addItem(self.tr("None"), None)
|
|
|
|
idx = 1
|
2017-06-13 16:05:59 +10:00
|
|
|
for param in list(self.alg.parameterComponents().values()):
|
|
|
|
definition = self.alg.parameterDefinition(param.parameterName())
|
2017-06-21 22:13:16 +10:00
|
|
|
if isinstance(definition, (QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer)):
|
2017-06-13 16:05:59 +10:00
|
|
|
self.parentCombo.addItem(definition.description(), definition.name())
|
2016-11-03 16:37:00 +10:00
|
|
|
if self.param is not None:
|
2017-08-04 12:34:06 +03:00
|
|
|
if self.param.parentLayerParameterName() == definition.name():
|
2016-11-03 16:37:00 +10:00
|
|
|
self.parentCombo.setCurrentIndex(idx)
|
|
|
|
idx += 1
|
|
|
|
self.verticalLayout.addWidget(self.parentCombo)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_STRING or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterString)):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.defaultTextBox = QLineEdit()
|
2013-01-12 23:36:00 +01:00
|
|
|
if self.param is not None:
|
2017-05-16 16:36:00 +10:00
|
|
|
self.defaultTextBox.setText(self.param.defaultValue())
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_FILE or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterFile)):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Type')))
|
2014-09-12 12:33:06 +03:00
|
|
|
self.fileFolderCombo = QComboBox()
|
2014-10-03 21:56:24 +03:00
|
|
|
self.fileFolderCombo.addItem(self.tr('File'))
|
|
|
|
self.fileFolderCombo.addItem(self.tr('Folder'))
|
2013-03-10 20:53:24 +01:00
|
|
|
if self.param is not None:
|
2013-10-01 20:52:22 +03:00
|
|
|
self.fileFolderCombo.setCurrentIndex(
|
2017-06-13 13:22:19 +10:00
|
|
|
1 if self.param.behavior() == QgsProcessingParameterFile.Folder else 0)
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.fileFolderCombo)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_POINT or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterPoint)):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
2016-02-23 14:38:54 +02:00
|
|
|
self.defaultTextBox = QLineEdit()
|
|
|
|
if self.param is not None:
|
2017-05-16 16:36:00 +10:00
|
|
|
self.defaultTextBox.setText(self.param.defaultValue())
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.defaultTextBox)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_CRS or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterCrs)):
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
|
2016-11-11 19:46:42 +10:00
|
|
|
self.selector = QgsProjectionSelectionWidget()
|
2016-08-05 10:24:45 +03:00
|
|
|
if self.param is not None:
|
2017-05-16 16:36:00 +10:00
|
|
|
self.selector.setCrs(QgsCoordinateReferenceSystem(self.param.defaultValue()))
|
2016-11-11 19:46:42 +10:00
|
|
|
else:
|
|
|
|
self.selector.setCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
|
|
|
|
self.verticalLayout.addWidget(self.selector)
|
2018-05-04 12:00:43 +03:00
|
|
|
elif self.paramType == parameters.PARAMETER_ENUM or \
|
|
|
|
isinstance(self.param, QgsProcessingParameterEnum):
|
|
|
|
self.widget = EnumModelerWidget(self)
|
|
|
|
if self.param is not None:
|
|
|
|
self.widget.setOptions(self.param.options())
|
|
|
|
self.widget.setDefault(int(self.param.defaultValue()))
|
|
|
|
self.widget.setAllowMultiple(bool(self.param.allowMultiple()))
|
|
|
|
self.verticalLayout.addWidget(self.widget)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addSpacing(20)
|
|
|
|
self.requiredCheck = QCheckBox()
|
|
|
|
self.requiredCheck.setText(self.tr('Mandatory'))
|
|
|
|
self.requiredCheck.setChecked(True)
|
2015-10-23 18:06:43 +02:00
|
|
|
if self.param is not None:
|
2017-05-16 16:36:00 +10:00
|
|
|
self.requiredCheck.setChecked(not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addWidget(self.requiredCheck)
|
2015-11-06 14:02:11 +01:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
self.buttonBox = QDialogButtonBox(self)
|
|
|
|
self.buttonBox.setOrientation(Qt.Horizontal)
|
2017-01-25 03:28:53 +01:00
|
|
|
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel |
|
|
|
|
QDialogButtonBox.Ok)
|
2013-10-01 20:52:22 +03:00
|
|
|
self.buttonBox.setObjectName('buttonBox')
|
2017-08-19 03:24:28 +10:00
|
|
|
self.buttonBox.accepted.connect(self.accept)
|
|
|
|
self.buttonBox.rejected.connect(self.reject)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
2016-09-16 09:13:16 +02:00
|
|
|
self.verticalLayout.addStretch()
|
2012-09-15 18:25:25 +03:00
|
|
|
self.verticalLayout.addWidget(self.buttonBox)
|
2013-05-01 23:45:20 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
self.setLayout(self.verticalLayout)
|
|
|
|
|
2017-08-19 03:24:28 +10:00
|
|
|
def accept(self):
|
2018-04-17 11:08:02 +03:00
|
|
|
description = self.nameTextBox.text()
|
2013-10-01 20:52:22 +03:00
|
|
|
if description.strip() == '':
|
2014-10-03 21:56:24 +03:00
|
|
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
|
|
|
self.tr('Invalid parameter name'))
|
2012-09-15 18:25:25 +03:00
|
|
|
return
|
|
|
|
if self.param is None:
|
2013-10-01 20:52:22 +03:00
|
|
|
validChars = \
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
2013-09-14 14:25:58 +02:00
|
|
|
safeName = ''.join(c for c in description if c in validChars)
|
2015-11-06 14:02:11 +01:00
|
|
|
name = safeName.lower()
|
|
|
|
i = 2
|
2017-06-13 16:05:59 +10:00
|
|
|
while self.alg.parameterDefinition(name):
|
2015-11-06 14:02:11 +01:00
|
|
|
name = safeName.lower() + str(i)
|
2017-06-13 16:05:59 +10:00
|
|
|
i += 1
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2017-05-16 16:36:00 +10:00
|
|
|
name = self.param.name()
|
2018-02-28 16:48:50 -05:00
|
|
|
if (self.paramType == parameters.PARAMETER_BOOLEAN or
|
2017-06-13 13:22:19 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterBoolean)):
|
|
|
|
self.param = QgsProcessingParameterBoolean(name, description, self.state.isChecked())
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_TABLE_FIELD or
|
2017-06-21 22:13:16 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterField)):
|
2012-09-15 18:25:25 +03:00
|
|
|
if self.parentCombo.currentIndex() < 0:
|
2014-10-03 21:56:24 +03:00
|
|
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
|
|
|
self.tr('Wrong or missing parameter values'))
|
2012-09-15 18:25:25 +03:00
|
|
|
return
|
2017-01-25 03:28:53 +01:00
|
|
|
parent = self.parentCombo.currentData()
|
|
|
|
datatype = self.datatypeCombo.currentData()
|
2017-09-21 11:04:38 +10:00
|
|
|
default = self.defaultTextBox.text()
|
|
|
|
if not default:
|
|
|
|
default = None
|
2017-09-22 10:56:32 +10:00
|
|
|
self.param = QgsProcessingParameterField(name, description, defaultValue=default,
|
|
|
|
parentLayerParameterName=parent, type=datatype,
|
|
|
|
allowMultiple=self.multipleCheck.isChecked())
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_BAND or
|
2017-08-04 10:43:42 +03:00
|
|
|
isinstance(self.param, QgsProcessingParameterBand)):
|
|
|
|
if self.parentCombo.currentIndex() < 0:
|
|
|
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
|
|
|
self.tr('Wrong or missing parameter values'))
|
|
|
|
return
|
|
|
|
parent = self.parentCombo.currentData()
|
|
|
|
self.param = QgsProcessingParameterBand(name, description, None, parent)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_MAP_LAYER or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterMapLayer)):
|
2017-08-19 03:45:51 +10:00
|
|
|
self.param = QgsProcessingParameterMapLayer(
|
|
|
|
name, description)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_RASTER or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterRasterLayer)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterRasterLayer(
|
2016-09-16 09:13:16 +02:00
|
|
|
name, description)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_TABLE or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterVectorLayer)):
|
2017-06-21 22:13:16 +10:00
|
|
|
self.param = QgsProcessingParameterVectorLayer(
|
2017-08-19 03:36:33 +10:00
|
|
|
name, description,
|
|
|
|
[self.shapetypeCombo.currentData()])
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_VECTOR or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterFeatureSource)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterFeatureSource(
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
name, description,
|
2017-08-19 03:36:33 +10:00
|
|
|
[self.shapetypeCombo.currentData()])
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_MULTIPLE or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterMultipleLayers)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterMultipleLayers(
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
name, description,
|
2017-08-19 03:36:33 +10:00
|
|
|
self.datatypeCombo.currentData())
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_NUMBER or
|
2018-04-19 17:24:13 +10:00
|
|
|
isinstance(self.param, (QgsProcessingParameterNumber, QgsProcessingParameterDistance))):
|
2012-09-15 18:25:25 +03:00
|
|
|
try:
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterNumber(name, description, QgsProcessingParameterNumber.Double,
|
|
|
|
self.defaultTextBox.text())
|
2016-09-16 09:13:16 +02:00
|
|
|
vmin = self.minTextBox.text().strip()
|
2017-06-13 13:22:19 +10:00
|
|
|
if not vmin == '':
|
|
|
|
self.param.setMinimum(float(vmin))
|
2016-09-16 09:13:16 +02:00
|
|
|
vmax = self.maxTextBox.text().strip()
|
2017-06-13 13:22:19 +10:00
|
|
|
if not vmax == '':
|
|
|
|
self.param.setMaximum(float(vmax))
|
2012-09-15 18:25:25 +03:00
|
|
|
except:
|
2014-10-03 21:56:24 +03:00
|
|
|
QMessageBox.warning(self, self.tr('Unable to define parameter'),
|
|
|
|
self.tr('Wrong or missing parameter values'))
|
2013-03-10 20:53:24 +01:00
|
|
|
return
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_EXPRESSION or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterExpression)):
|
2017-01-25 03:28:53 +01:00
|
|
|
parent = self.parentCombo.currentData()
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterExpression(name, description,
|
|
|
|
str(self.defaultEdit.expression()),
|
|
|
|
parent)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_STRING or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterString)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterString(name, description,
|
|
|
|
str(self.defaultTextBox.text()))
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_EXTENT or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterExtent)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterExtent(name, description)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_FILE or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterFile)):
|
2013-08-03 16:43:43 +01:00
|
|
|
isFolder = self.fileFolderCombo.currentIndex() == 1
|
2017-09-22 10:56:32 +10:00
|
|
|
self.param = QgsProcessingParameterFile(name, description,
|
|
|
|
QgsProcessingParameterFile.Folder if isFolder else QgsProcessingParameterFile.File)
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_POINT or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterPoint)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterPoint(name, description,
|
|
|
|
str(self.defaultTextBox.text()))
|
2018-02-28 16:48:50 -05:00
|
|
|
elif (self.paramType == parameters.PARAMETER_CRS or
|
2017-09-22 10:56:32 +10:00
|
|
|
isinstance(self.param, QgsProcessingParameterCrs)):
|
2017-06-13 13:22:19 +10:00
|
|
|
self.param = QgsProcessingParameterCrs(name, description, self.selector.crs().authid())
|
2018-05-04 12:00:43 +03:00
|
|
|
if (self.paramType == parameters.PARAMETER_ENUM or
|
|
|
|
isinstance(self.param, QgsProcessingParameterEnum)):
|
|
|
|
self.param = QgsProcessingParameterEnum(name, description, self.widget.options(), self.widget.allowMultiple(), self.widget.defaultOption())
|
2018-02-28 16:48:50 -05:00
|
|
|
else:
|
2018-03-05 12:24:56 -05:00
|
|
|
if self.paramType:
|
|
|
|
typeId = self.paramType
|
|
|
|
else:
|
|
|
|
typeId = self.param.type()
|
|
|
|
|
|
|
|
paramTypeDef = QgsApplication.instance().processingRegistry().parameterType(typeId)
|
2018-03-03 12:44:24 -05:00
|
|
|
if not paramTypeDef:
|
2018-03-05 12:24:56 -05:00
|
|
|
msg = self.tr('The parameter `{}` is not registered, are you missing a required plugin?'.format(typeId))
|
2018-03-03 12:44:24 -05:00
|
|
|
raise UndefinedParameterException(msg)
|
|
|
|
self.param = paramTypeDef.create(name)
|
2018-04-17 11:08:02 +03:00
|
|
|
self.param.setDescription(description)
|
2018-03-03 12:44:24 -05:00
|
|
|
self.param.setMetadata(paramTypeDef.metadata())
|
2018-02-28 16:48:50 -05:00
|
|
|
|
2017-05-16 16:36:00 +10:00
|
|
|
if not self.requiredCheck.isChecked():
|
|
|
|
self.param.setFlags(self.param.flags() | QgsProcessingParameterDefinition.FlagOptional)
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2017-08-19 03:24:28 +10:00
|
|
|
settings = QgsSettings()
|
|
|
|
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
|
|
|
|
|
|
|
|
QDialog.accept(self)
|
|
|
|
|
|
|
|
def reject(self):
|
2012-09-15 18:25:25 +03:00
|
|
|
self.param = None
|
2017-08-19 03:24:28 +10:00
|
|
|
|
|
|
|
settings = QgsSettings()
|
|
|
|
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
|
|
|
|
|
|
|
|
QDialog.reject(self)
|