Skip to content
Permalink
Browse files
[Processing] Fix getParameterFromString to get Vector Layer data type…
…s like Feature Source

In Processing parameter description QgsProcessingParameterVectorLayer multi data types does not work as QgsProcessingParameterFeatureSource.
  • Loading branch information
rldhont authored and nyalldawson committed Jun 21, 2021
1 parent 81a2ec2 commit 328af1df1ec9ffe9e4cd745405c2a615562a7c6c
Showing with 49 additions and 56 deletions.
  1. +4 −1 python/plugins/processing/core/parameters.py
  2. +45 −55 python/plugins/processing/tests/ParametersTest.py
@@ -114,7 +114,10 @@ def getParameterFromString(s, context=''):
params[5] = True if params[5].lower() == 'true' else False
elif clazz == QgsProcessingParameterVectorLayer:
if len(params) > 2:
params[2] = [int(p) for p in params[2].split(';')]
try:
params[2] = [int(p) for p in params[2].split(';')]
except:
params[2] = [getattr(QgsProcessing, p.split(".")[1]) for p in params[2].split(';')]
if len(params) > 4:
params[4] = True if params[4].lower() == 'true' else False
elif clazz == QgsProcessingParameterMapLayer:
@@ -619,17 +619,15 @@ def testParameterVectorLayerDesc(self):
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

# QgsProcessingParameterVectorLayer multi data types does not work
# as QgsProcessingParameterFeatureSource
# desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorPoint'
# param = getParameterFromString(desc)
# self.assertIsNotNone(param)
# self.assertEqual(param.type(), 'vector')
# self.assertEqual(param.name(), 'in_vector')
# self.assertEqual(param.description(), 'Input Vector')
# self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorPoint])
# self.assertIsNone(param.defaultValue())
# self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)
desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorPoint'
param = getParameterFromString(desc)
self.assertIsNotNone(param)
self.assertEqual(param.type(), 'vector')
self.assertEqual(param.name(), 'in_vector')
self.assertEqual(param.description(), 'Input Vector')
self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorPoint])
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|1'
param = getParameterFromString(desc)
@@ -641,17 +639,15 @@ def testParameterVectorLayerDesc(self):
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

# QgsProcessingParameterVectorLayer multi data types does not work
# as QgsProcessingParameterFeatureSource
# desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorLine'
# param = getParameterFromString(desc)
# self.assertIsNotNone(param)
# self.assertEqual(param.type(), 'vector')
# self.assertEqual(param.name(), 'in_vector')
# self.assertEqual(param.description(), 'Input Vector')
# self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorLine])
# self.assertIsNone(param.defaultValue())
# self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)
desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorLine'
param = getParameterFromString(desc)
self.assertIsNotNone(param)
self.assertEqual(param.type(), 'vector')
self.assertEqual(param.name(), 'in_vector')
self.assertEqual(param.description(), 'Input Vector')
self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorLine])
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|2'
param = getParameterFromString(desc)
@@ -663,17 +659,15 @@ def testParameterVectorLayerDesc(self):
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

# QgsProcessingParameterVectorLayer multi data types does not work
# as QgsProcessingParameterFeatureSource
# desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorPolygon'
# param = getParameterFromString(desc)
# self.assertIsNotNone(param)
# self.assertEqual(param.type(), 'vector')
# self.assertEqual(param.name(), 'in_vector')
# self.assertEqual(param.description(), 'Input Vector')
# self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorPolygon])
# self.assertIsNone(param.defaultValue())
# self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)
desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorPolygon'
param = getParameterFromString(desc)
self.assertIsNotNone(param)
self.assertEqual(param.type(), 'vector')
self.assertEqual(param.name(), 'in_vector')
self.assertEqual(param.description(), 'Input Vector')
self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorPolygon])
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|5'
param = getParameterFromString(desc)
@@ -685,17 +679,15 @@ def testParameterVectorLayerDesc(self):
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

# QgsProcessingParameterVectorLayer multi data types does not work
# as QgsProcessingParameterFeatureSource
# desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVector'
# param = getParameterFromString(desc)
# self.assertIsNotNone(param)
# self.assertEqual(param.type(), 'vector')
# self.assertEqual(param.name(), 'in_vector')
# self.assertEqual(param.description(), 'Input Vector')
# self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVector])
# self.assertIsNone(param.defaultValue())
# self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)
desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVector'
param = getParameterFromString(desc)
self.assertIsNotNone(param)
self.assertEqual(param.type(), 'vector')
self.assertEqual(param.name(), 'in_vector')
self.assertEqual(param.description(), 'Input Vector')
self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVector])
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|1;2'
param = getParameterFromString(desc)
@@ -707,17 +699,15 @@ def testParameterVectorLayerDesc(self):
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

# QgsProcessingParameterVectorLayer multi data types does not work
# as QgsProcessingParameterFeatureSource
# desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorLine;QgsProcessing.TypeVectorPolygon'
# param = getParameterFromString(desc)
# self.assertIsNotNone(param)
# self.assertEqual(param.type(), 'vector')
# self.assertEqual(param.name(), 'in_vector')
# self.assertEqual(param.description(), 'Input Vector')
# self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])
# self.assertIsNone(param.defaultValue())
# self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)
desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|QgsProcessing.TypeVectorLine;QgsProcessing.TypeVectorPolygon'
param = getParameterFromString(desc)
self.assertIsNotNone(param)
self.assertEqual(param.type(), 'vector')
self.assertEqual(param.name(), 'in_vector')
self.assertEqual(param.description(), 'Input Vector')
self.assertListEqual(param.dataTypes(), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon])
self.assertIsNone(param.defaultValue())
self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional)

desc = 'QgsProcessingParameterVectorLayer|in_vector|Input Vector|-1|None|True'
param = getParameterFromString(desc)

0 comments on commit 328af1d

Please sign in to comment.