当前位置: 首页>>代码示例>>Python>>正文


Python ProjectProvider.ProjectProvider类代码示例

本文整理汇总了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')
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:18,代码来源:ProjectProvider.py

示例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)
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:37,代码来源:ProjectProvider.py

示例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())
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:33,代码来源:ProjectProvider.py


注:本文中的processing.modeler.ProjectProvider.ProjectProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。