本文整理汇总了Python中processing.modeler.ProjectProvider.ProjectProvider类的典型用法代码示例。如果您正苦于以下问题:Python ProjectProvider类的具体用法?Python ProjectProvider怎么用?Python ProjectProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectProvider类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDialog
def testDialog(self):
"""
Test saving model to project from dialog
"""
p = QgsProject().instance()
provider = ProjectProvider()
QgsApplication.processingRegistry().addProvider(provider)
# make an algorithm
alg = QgsProcessingModelAlgorithm('test name', 'test group')
dialog = ModelerDialog(alg)
dialog.saveInProject()
self.assertEqual(len(provider.model_definitions), 1)
self.assertEqual(len(provider.algorithms()), 1)
self.assertEqual(provider.algorithms()[0].name(), 'test name')
self.assertEqual(provider.algorithms()[0].group(), 'test group')
示例2: testDelete
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')
# overwrite model
alg2b = QgsProcessingModelAlgorithm('test name2', 'test group2')
alg2b.setHelpContent({'test': 'test'})
provider.add_model(alg2b)
self.assertEqual(len(provider.algorithms()), 1)
self.assertEqual(provider.algorithms()[0].helpContent(), {'test': 'test'})
provider.remove_model(alg2)
self.assertEqual(len(provider.algorithms()), 0)
示例3: testSaveRestoreFromProject
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())