def testGetAsScriptCode(self):
        parameter = ParameterTableMultipleField(
            'myName', 'myDesc', self.parent_name, optional=False)

        self.assertEqual(
            parameter.getAsScriptCode(),
            '##myName=multiple field test_parent_layer')

        # test optional
        parameter.optional = True
        self.assertEqual(
            parameter.getAsScriptCode(),
            '##myName=optional multiple field test_parent_layer')
Example #2
0
    def testGetAsScriptCode(self):
        parameter = ParameterTableMultipleField('myName',
                                                'myDesc',
                                                self.parent_name,
                                                optional=False)

        self.assertEqual(parameter.getAsScriptCode(),
                         '##myName=multiple field test_parent_layer')

        # test optional
        parameter.optional = True
        self.assertEqual(parameter.getAsScriptCode(),
                         '##myName=optional multiple field test_parent_layer')
Example #3
0
    def testSetValue(self):
        parameter = ParameterTableMultipleField(
            'myName', 'myDesc', self.parent_name, optional=False)

        parameter.setValue(['my', 'super', 'widget', '77'])
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue([])
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue(None)
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue(['my', 'widget', '77'])
        self.assertEqual(parameter.value, 'my;widget;77')
    def testSetValue(self):
        parameter = ParameterTableMultipleField(
            'myName', 'myDesc', self.parent_name, optional=False)

        parameter.setValue(['my', 'super', 'widget', '77'])
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue([])
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue(None)
        self.assertEqual(parameter.value, 'my;super;widget;77')

        parameter.setValue(['my', 'widget', '77'])
        self.assertEqual(parameter.value, 'my;widget;77')
Example #5
0
 def defineCharacteristics(self):
     self.name = 'Dissolve'
     self.group = 'Vector geometry tools'
     self.addParameter(ParameterVector(Dissolve.INPUT,
                                       self.tr('Input layer'),
                                       [ParameterVector.VECTOR_TYPE_POLYGON, ParameterVector.VECTOR_TYPE_LINE]))
     self.addParameter(ParameterBoolean(Dissolve.DISSOLVE_ALL,
                                        self.tr('Dissolve all (do not use fields)'), True))
     self.addParameter(ParameterTableMultipleField(Dissolve.FIELD,
                                                   self.tr('Unique ID fields'), Dissolve.INPUT, optional=True))
     self.addOutput(OutputVector(Dissolve.OUTPUT, self.tr('Dissolved')))
Example #6
0
    def processInputParameterToken(self, token, name):
        param = None

        desc = self.createDescriptiveName(name)

        if token.lower().strip().startswith('raster'):
            param = ParameterRaster(name, desc, False)
        elif token.lower().strip() == 'vector':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif token.lower().strip() == 'vector point':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif token.lower().strip() == 'vector line':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif token.lower().strip() == 'vector polygon':
            param = ParameterVector(name, desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif token.lower().strip() == 'table':
            param = ParameterTable(name, desc, False)
        elif token.lower().strip().startswith('multiple raster'):
            param = ParameterMultipleInput(name, desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif token.lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(name, desc,
                                           ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif token.lower().strip().startswith('selection'):
            options = token.strip()[len('selection'):].split(';')
            param = ParameterSelection(name, desc, options)
        elif token.lower().strip().startswith('boolean'):
            default = token.strip()[len('boolean') + 1:]
            if default:
                param = ParameterBoolean(name, desc, default)
            else:
                param = ParameterBoolean(name, desc)
        elif token.lower().strip().startswith('number'):
            default = token.strip()[len('number') + 1:]
            if default:
                param = ParameterNumber(name, desc, default=default)
            else:
                param = ParameterNumber(name, desc)
        elif token.lower().strip().startswith('field'):
            field = token.strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(name, desc, field)
        elif token.lower().strip().startswith('multiple field'):
            field = token.strip()[len('multiple field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableMultipleField(name, desc, field)
        elif token.lower().strip() == 'extent':
            param = ParameterExtent(name, desc)
        elif token.lower().strip() == 'point':
            param = ParameterPoint(name, desc)
        elif token.lower().strip() == 'file':
            param = ParameterFile(name, desc, False)
        elif token.lower().strip() == 'folder':
            param = ParameterFile(name, desc, True)
        elif token.lower().strip().startswith('string'):
            default = token.strip()[len('string') + 1:]
            if default:
                param = ParameterString(name, desc, default)
            else:
                param = ParameterString(name, desc)
        elif token.lower().strip().startswith('longstring'):
            default = token.strip()[len('longstring') + 1:]
            if default:
                param = ParameterString(name, desc, default, multiline=True)
            else:
                param = ParameterString(name, desc, multiline=True)
        elif token.lower().strip() == 'crs':
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, desc, default)
            else:
                param = ParameterCrs(name, desc)

        return param
Example #7
0
    def okPressed(self):
        description = unicode(self.nameTextBox.text())
        if description.strip() == '':
            QMessageBox.warning(self, self.tr('Unable to define parameter'),
                                self.tr('Invalid parameter name'))
            return
        if self.param is None:
            validChars = \
                'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
            safeName = ''.join(c for c in description if c in validChars)
            name = safeName.lower()
            i = 2
            while name in self.alg.inputs:
                name = safeName.lower() + str(i)
        else:
            name = self.param.name
        if self.paramType \
                == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN \
                or isinstance(self.param, ParameterBoolean):
            self.param = ParameterBoolean(name, description,
                                          self.state.isChecked())
        elif self.paramType in (
                ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD,
                ModelerParameterDefinitionDialog.PARAMETER_TABLE_MULTIPLE_FIELD)\
            or isinstance(self.param, (ParameterTableField,
                                       ParameterTableMultipleField)):
            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.itemData(self.parentCombo.currentIndex())
            datatype = self.datatypeCombo.itemData(
                self.datatypeCombo.currentIndex())

            if (self.paramType ==
                    ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or
                    isinstance(self.param, ParameterTableField)):
                self.param = ParameterTableField(
                    name, description, parent, datatype)
            else:
                self.param = ParameterTableMultipleField(
                    name, description, parent, datatype)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or \
                isinstance(self.param, ParameterRaster):
            self.param = ParameterRaster(
                name, description,
                self.yesNoCombo.currentIndex() == 1)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE or \
                isinstance(self.param, ParameterTable):
            self.param = ParameterTable(
                name, description,
                self.yesNoCombo.currentIndex() == 1)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or \
                isinstance(self.param, ParameterVector):
            self.param = ParameterVector(
                name, description,
                [self.shapetypeCombo.currentIndex() - 1],
                self.yesNoCombo.currentIndex() == 1)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or \
                isinstance(self.param, ParameterMultipleInput):
            self.param = ParameterMultipleInput(
                name, description,
                self.datatypeCombo.currentIndex() - 1,
                self.yesNoCombo.currentIndex() == 1)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or \
                isinstance(self.param, ParameterNumber):
            try:
                vmin = unicode(self.minTextBox.text()).strip()
                if vmin == '':
                    vmin = None
                else:
                    vmin = float(vmin)
                vmax = unicode(self.maxTextBox.text()).strip()
                if vmax == '':
                    vmax = None
                else:
                    vmax = float(vmax)
                self.param = ParameterNumber(name, description, vmin, vmax,
                                             unicode(self.defaultTextBox.text()))
            except:
                QMessageBox.warning(self, self.tr('Unable to define parameter'),
                                    self.tr('Wrong or missing parameter values'))
                return
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or \
                isinstance(self.param, ParameterString):
            self.param = ParameterString(name, description,
                                         unicode(self.defaultTextBox.text()))
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_EXTENT or \
                isinstance(self.param, ParameterExtent):
            self.param = ParameterExtent(name, description)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or \
                isinstance(self.param, ParameterFile):
            isFolder = self.fileFolderCombo.currentIndex() == 1
            self.param = ParameterFile(name, description, isFolder=isFolder)
        elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
                isinstance(self.param, ParameterPoint):
            self.param = ParameterPoint(name, description,
                                        unicode(self.defaultTextBox.text()))
        self.param.optional = self.yesNoCombo.currentIndex() == 1
        self.close()
Example #8
0
    def processInputParameterToken(self, token, name):
        param = None

        descName = self.createDescriptiveName(name)

        if token.lower().strip() == 'raster':
            param = ParameterRaster(name, descName, False)
        elif token.lower().strip() == 'vector':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_ANY])
        elif token.lower().strip() == 'vector point':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_POINT])
        elif token.lower().strip() == 'vector line':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_LINE])
        elif token.lower().strip() == 'vector polygon':
            param = ParameterVector(name, descName,
                                    [dataobjects.TYPE_VECTOR_POLYGON])
        elif token.lower().strip() == 'table':
            param = ParameterTable(name, descName, False)
        elif token.lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(name, descName,
                                           dataobjects.TYPE_RASTER)
            param.optional = False
        elif token.lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(name, descName,
                                           dataobjects.TYPE_VECTOR_ANY)
            param.optional = False
        elif token.lower().strip().startswith('selectionfromfile'):
            options = token.strip()[len('selectionfromfile '):].split(';')
            param = ParameterSelection(name, descName, options, isSource=True)
        elif token.lower().strip().startswith('selection'):
            options = token.strip()[len('selection '):].split(';')
            param = ParameterSelection(name, descName, options)
        elif token.lower().strip().startswith('boolean'):
            default = token.strip()[len('boolean') + 1:]
            if default:
                param = ParameterBoolean(name, descName, default)
            else:
                param = ParameterBoolean(name, descName)
        elif token.lower().strip() == 'extent':
            param = ParameterExtent(name, descName)
        elif token.lower().strip() == 'point':
            param = ParameterPoint(name, descName)
        elif token.lower().strip() == 'file':
            param = ParameterFile(name, descName, False)
        elif token.lower().strip() == 'folder':
            param = ParameterFile(name, descName, True)
        elif token.lower().strip().startswith('number'):
            default = token.strip()[len('number') + 1:]
            if default:
                param = ParameterNumber(name, descName, default=default)
            else:
                param = ParameterNumber(name, descName)
        elif token.lower().strip().startswith('field'):
            if token.lower().strip().startswith('field number'):
                field = token.strip()[len('field number') + 1:]
                datatype = ParameterTableField.DATA_TYPE_NUMBER
            elif token.lower().strip().startswith('field string'):
                field = token.strip()[len('field string') + 1:]
                datatype = ParameterTableField.DATA_TYPE_STRING
            else:
                field = token.strip()[len('field') + 1:]
                datatype = ParameterTableField.DATA_TYPE_ANY
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(name=name,
                                            description=descName,
                                            parent=field,
                                            datatype=datatype)
        elif token.lower().strip().startswith('multiple field'):
            if token.lower().strip().startswith('multiple field number'):
                field = token.strip()[len('multiple field number') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_NUMBER
            elif token.lower().strip().startswith('multiple field string'):
                field = token.strip()[len('multiple field string') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_STRING
            else:
                field = token.strip()[len('multiple field') + 1:]
                datatype = ParameterTableMultipleField.DATA_TYPE_ANY
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableMultipleField(name=name,
                                                    description=descName,
                                                    parent=field,
                                                    datatype=datatype)
        elif token.lower().strip().startswith('string'):
            default = token.strip()[len('string') + 1:]
            if default:
                param = ParameterString(name, descName, default)
            else:
                param = ParameterString(name, descName)
        elif token.lower().strip().startswith('longstring'):
            default = token.strip()[len('longstring') + 1:]
            if default:
                param = ParameterString(name,
                                        descName,
                                        default,
                                        multiline=True)
            else:
                param = ParameterString(name, descName, multiline=True)
        elif token.lower().strip().startswith('crs'):
            default = token.strip()[len('crs') + 1:]
            if default:
                param = ParameterCrs(name, descName, default)
            else:
                param = ParameterCrs(name, descName)

        return param