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
2016-11-11 19:46:42 +10:00
from qgis . gui import QgsExpressionLineEdit , QgsProjectionSelectionWidget
2017-07-08 16:05:39 +10:00
from qgis . core import ( 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 ,
QgsProcessingParameterRange ,
QgsProcessingParameterRasterLayer ,
QgsProcessingParameterEnum ,
QgsProcessingParameterString ,
QgsProcessingParameterExpression ,
2017-06-21 22:13:16 +10:00
QgsProcessingParameterVectorLayer ,
QgsProcessingParameterField ,
2017-08-04 10:43:42 +03:00
QgsProcessingParameterFeatureSource ,
QgsProcessingParameterBand )
2017-07-08 16:05:39 +10:00
from qgis . PyQt . QtCore import ( Qt ,
2018-01-15 14:15:11 +10:00
QByteArray ,
QCoreApplication )
2016-08-05 10:24:45 +03:00
from qgis . PyQt . QtWidgets import ( QDialog ,
QVBoxLayout ,
QLabel ,
QLineEdit ,
QComboBox ,
QCheckBox ,
QDialogButtonBox ,
QMessageBox )
2014-09-12 12:33:06 +03: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
PARAMETER_NUMBER = ' Number '
2017-07-08 16:09:38 +10:00
PARAMETER_RASTER = ' Raster Layer '
PARAMETER_TABLE = ' Vector Layer '
2018-01-15 13:58:13 +10:00
PARAMETER_VECTOR = ' Vector Features '
2013-10-01 20:52:22 +03:00
PARAMETER_STRING = ' String '
2016-11-03 16:37:00 +10:00
PARAMETER_EXPRESSION = ' Expression '
2013-10-01 20:52:22 +03:00
PARAMETER_BOOLEAN = ' Boolean '
2018-01-15 13:58:13 +10:00
PARAMETER_TABLE_FIELD = ' Vector Field '
2013-10-01 20:52:22 +03:00
PARAMETER_EXTENT = ' Extent '
PARAMETER_FILE = ' File '
2016-02-23 14:38:54 +02:00
PARAMETER_POINT = ' Point '
2016-08-05 10:24:45 +03:00
PARAMETER_CRS = ' CRS '
2017-07-08 16:09:38 +10:00
PARAMETER_MULTIPLE = ' Multiple Input '
2017-08-19 03:45:51 +10:00
PARAMETER_BAND = ' Raster Band '
PARAMETER_MAP_LAYER = ' Map Layer '
2012-09-15 18:25:25 +03:00
2013-10-01 20:52:22 +03:00
paramTypes = [
PARAMETER_BOOLEAN ,
PARAMETER_EXTENT ,
PARAMETER_FILE ,
PARAMETER_NUMBER ,
PARAMETER_RASTER ,
PARAMETER_STRING ,
2016-11-03 16:37:00 +10:00
PARAMETER_EXPRESSION ,
2017-08-19 03:45:51 +10:00
PARAMETER_MAP_LAYER ,
2013-10-01 20:52:22 +03:00
PARAMETER_TABLE ,
PARAMETER_TABLE_FIELD ,
PARAMETER_VECTOR ,
2016-08-05 10:24:45 +03:00
PARAMETER_POINT ,
2016-08-08 13:40:07 +03:00
PARAMETER_CRS ,
2017-08-04 10:43:42 +03:00
PARAMETER_MULTIPLE ,
PARAMETER_BAND
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
]
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
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
if self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-09 10:48:51 +02:00
elif self . paramType == ModelerParameterDefinitionDialog . 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 )
2017-08-04 10:43:42 +03:00
elif self . paramType == ModelerParameterDefinitionDialog . PARAMETER_BAND or \
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 (
ModelerParameterDefinitionDialog . PARAMETER_VECTOR , ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . PARAMETER_NUMBER or
2017-09-22 10:56:32 +10:00
isinstance ( self . param , QgsProcessingParameterNumber ) ) :
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 )
2016-11-03 16:37:00 +10:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
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 ) :
2016-09-21 18:24:26 +02:00
description = str ( 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 ( )
2017-01-25 03:28:53 +01:00
if ( self . paramType == ModelerParameterDefinitionDialog . PARAMETER_BOOLEAN or
2017-06-13 13:22:19 +10:00
isinstance ( self . param , QgsProcessingParameterBoolean ) ) :
self . param = QgsProcessingParameterBoolean ( name , description , self . state . isChecked ( ) )
2017-01-25 03:28:53 +01:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) )
2017-08-04 10:43:42 +03:00
elif ( self . paramType == ModelerParameterDefinitionDialog . PARAMETER_BAND or
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 )
2017-08-19 03:45:51 +10:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) ] )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) ] )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . PARAMETER_NUMBER or
2017-09-22 10:56:32 +10:00
isinstance ( self . param , QgsProcessingParameterNumber ) ) :
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
2016-11-03 16:37:00 +10:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) ) )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) ) )
2016-09-16 09:13:16 +02:00
elif ( self . paramType == ModelerParameterDefinitionDialog . 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 ( ) )
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 )
2018-01-15 14:15:11 +10:00
@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 ]