本文整理汇总了Python中processing.modeler.ProjectProvider.ProjectProvider.add_model方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectProvider.add_model方法的具体用法?Python ProjectProvider.add_model怎么用?Python ProjectProvider.add_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.modeler.ProjectProvider.ProjectProvider
的用法示例。
在下文中一共展示了ProjectProvider.add_model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSaveRestoreFromProject
# 需要导入模块: from processing.modeler.ProjectProvider import ProjectProvider [as 别名]
# 或者: from processing.modeler.ProjectProvider.ProjectProvider import add_model [as 别名]
def testSaveRestoreFromProject(self):
p = QgsProject()
provider = ProjectProvider(p)
# add some algorithms
alg = QgsProcessingModelAlgorithm('test name', 'test group')
provider.add_model(alg)
alg2 = QgsProcessingModelAlgorithm('test name2', 'test group2')
provider.add_model(alg2)
self.assertEqual(len(provider.algorithms()), 2)
tmp_file = QTemporaryFile()
tmp_file.open() # fileName is no available until open
temp_path = tmp_file.fileName()
tmp_file.close()
self.assertTrue(p.write(temp_path))
# restore project
p2 = QgsProject()
provider2 = ProjectProvider(p2)
self.assertTrue(p2.read(temp_path))
self.assertEqual(len(provider2.model_definitions), 2)
self.assertEqual(len(provider2.algorithms()), 2)
self.assertEqual(provider2.algorithms()[0].name(), 'test name')
self.assertEqual(provider2.algorithms()[0].group(), 'test group')
self.assertEqual(provider2.algorithms()[1].name(), 'test name2')
self.assertEqual(provider2.algorithms()[1].group(), 'test group2')
# clear project should remove algorithms
p2.clear()
self.assertFalse(provider2.algorithms())
示例2: testDelete
# 需要导入模块: from processing.modeler.ProjectProvider import ProjectProvider [as 别名]
# 或者: from processing.modeler.ProjectProvider.ProjectProvider import add_model [as 别名]
def testDelete(self):
"""
Test deleting a model from the project
"""
p = QgsProject()
provider = ProjectProvider(p)
# add some models
alg = QgsProcessingModelAlgorithm('test name', 'test group')
provider.add_model(alg)
alg2 = QgsProcessingModelAlgorithm('test name2', 'test group2')
provider.add_model(alg2)
self.assertEqual(len(provider.algorithms()), 2)
# try to delete
provider.remove_model(None)
self.assertEqual(len(provider.algorithms()), 2)
# not in provider!
alg3 = QgsProcessingModelAlgorithm('test name3', 'test group')
provider.remove_model(alg3)
self.assertEqual(len(provider.algorithms()), 2)
# delete model actually in project
provider.remove_model(alg)
self.assertEqual(len(provider.algorithms()), 1)
self.assertEqual(provider.algorithms()[0].name(), 'test name2')
provider.remove_model(alg2)
self.assertEqual(len(provider.algorithms()), 0)