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


Python QgsReportSectionFieldGroup.appendChild方法代码示例

本文整理汇总了Python中qgis.core.QgsReportSectionFieldGroup.appendChild方法的典型用法代码示例。如果您正苦于以下问题:Python QgsReportSectionFieldGroup.appendChild方法的具体用法?Python QgsReportSectionFieldGroup.appendChild怎么用?Python QgsReportSectionFieldGroup.appendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsReportSectionFieldGroup的用法示例。


在下文中一共展示了QgsReportSectionFieldGroup.appendChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testFieldGroupMultiLayer

# 需要导入模块: from qgis.core import QgsReportSectionFieldGroup [as 别名]
# 或者: from qgis.core.QgsReportSectionFieldGroup import appendChild [as 别名]
    def testFieldGroupMultiLayer(self):
        # create a layer
        states = QgsVectorLayer("Point?crs=epsg:4326&field=country:string(20)&field=state:string(20)", "points", "memory")

        attributes = [
            ['Australia', 'QLD'],
            ['NZ', 'state1'],
            ['Australia', 'VIC'],
            ['NZ', 'state2'],
            ['PNG', 'state3'],
            ['Australia', 'NSW']
        ]

        pr = states.dataProvider()
        for a in attributes:
            f = QgsFeature()
            f.initAttributes(2)
            f.setAttribute(0, a[0])
            f.setAttribute(1, a[1])
            self.assertTrue(pr.addFeature(f))

        places = QgsVectorLayer("Point?crs=epsg:4326&field=state:string(20)&field=town:string(20)", "points", "memory")

        attributes = [
            ['QLD', 'Brisbane'],
            ['QLD', 'Emerald'],
            ['state1', 'town1'],
            ['VIC', 'Melbourne'],
            ['state1', 'town2'],
            ['QLD', 'Beerburrum'],
            ['VIC', 'Geelong'],
            ['state3', 'town1']
        ]

        pr = places.dataProvider()
        for a in attributes:
            f = QgsFeature()
            f.initAttributes(2)
            f.setAttribute(0, a[0])
            f.setAttribute(1, a[1])
            self.assertTrue(pr.addFeature(f))

        p = QgsProject()
        r = QgsReport(p)

        # add a child
        child1 = QgsReportSectionFieldGroup()
        child1_body = QgsLayout(p)
        child1.setLayer(states)
        child1.setBody(child1_body)
        child1.setBodyEnabled(True)
        child1.setField('country')
        r.appendChild(child1)
        self.assertTrue(r.beginRender())
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'QLD'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'VIC'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'NSW'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['NZ', 'state1'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['NZ', 'state2'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child1_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['PNG', 'state3'])
        self.assertFalse(r.next())

        # another group
        # remove body from child1
        child1.setBodyEnabled(False)

        child2 = QgsReportSectionFieldGroup()
        child2_body = QgsLayout(p)
        child2.setLayer(states)
        child2.setBody(child2_body)
        child2.setBodyEnabled(True)
        child2.setField('state')
        child1.appendChild(child2)
        self.assertTrue(r.beginRender())
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child2_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'NSW'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child2_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'QLD'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child2_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['Australia', 'VIC'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child2_body)
        self.assertEqual(r.layout().reportContext().feature().attributes(), ['NZ', 'state1'])
        self.assertTrue(r.next())
        self.assertEqual(r.layout(), child2_body)
#.........这里部分代码省略.........
开发者ID:mhugo,项目名称:QGIS,代码行数:103,代码来源:test_qgsreport.py


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