Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 May 31, 2021
1 parent 6b728eb commit 531e927
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 56 deletions.
5 changes: 4 additions & 1 deletion python/plugins/processing/core/parameters.py
Expand Up @@ -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:
Expand Down
100 changes: 45 additions & 55 deletions python/plugins/processing/tests/ParametersTest.py
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 531e927

Please sign in to comment.