本文整理汇总了Python中qgis.core.QgsReportSectionFieldGroup类的典型用法代码示例。如果您正苦于以下问题:Python QgsReportSectionFieldGroup类的具体用法?Python QgsReportSectionFieldGroup怎么用?Python QgsReportSectionFieldGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsReportSectionFieldGroup类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testReadWriteXml
def testReadWriteXml(self):
p = QgsProject()
ptLayer = QgsVectorLayer("Point?crs=epsg:4326&field=country:string(20)&field=state:string(20)&field=town:string(20)", "points", "memory")
p.addMapLayer(ptLayer)
r = QgsReport(p)
r.setName('my report')
# add a header
r.setHeaderEnabled(True)
report_header = QgsLayout(p)
report_header.setUnits(QgsUnitTypes.LayoutInches)
r.setHeader(report_header)
# add a footer
r.setFooterEnabled(True)
report_footer = QgsLayout(p)
report_footer.setUnits(QgsUnitTypes.LayoutMeters)
r.setFooter(report_footer)
# add some subsections
child1 = QgsReportSectionLayout()
child1_body = QgsLayout(p)
child1_body.setUnits(QgsUnitTypes.LayoutPoints)
child1.setBody(child1_body)
child2 = QgsReportSectionLayout()
child2_body = QgsLayout(p)
child2_body.setUnits(QgsUnitTypes.LayoutPixels)
child2.setBody(child2_body)
child1.appendChild(child2)
child2a = QgsReportSectionFieldGroup()
child2a_body = QgsLayout(p)
child2a_body.setUnits(QgsUnitTypes.LayoutInches)
child2a.setBody(child2a_body)
child2a.setField('my field')
child2a.setLayer(ptLayer)
child1.appendChild(child2a)
r.appendChild(child1)
doc = QDomDocument("testdoc")
elem = r.writeLayoutXml(doc, QgsReadWriteContext())
r2 = QgsReport(p)
self.assertTrue(r2.readLayoutXml(elem, doc, QgsReadWriteContext()))
self.assertEqual(r2.name(), 'my report')
self.assertTrue(r2.headerEnabled())
self.assertEqual(r2.header().units(), QgsUnitTypes.LayoutInches)
self.assertTrue(r2.footerEnabled())
self.assertEqual(r2.footer().units(), QgsUnitTypes.LayoutMeters)
self.assertEqual(r2.childCount(), 1)
self.assertEqual(r2.childSection(0).body().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(r2.childSection(0).childCount(), 2)
self.assertEqual(r2.childSection(0).childSection(0).body().units(), QgsUnitTypes.LayoutPixels)
self.assertEqual(r2.childSection(0).childSection(1).body().units(), QgsUnitTypes.LayoutInches)
self.assertEqual(r2.childSection(0).childSection(1).field(), 'my field')
self.assertEqual(r2.childSection(0).childSection(1).layer(), ptLayer)
开发者ID:mhugo,项目名称:QGIS,代码行数:58,代码来源:test_qgsreport.py
示例2: testFieldGroupMultiLayer
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,代码行数:101,代码来源:test_qgsreport.py
示例3: testFieldGroupSectionVisibility
def testFieldGroupSectionVisibility(self):
states = QgsVectorLayer("Point?crs=epsg:4326&field=country:string(20)&field=state:string(20)", "points", "memory")
p = QgsProject()
r = QgsReport(p)
# add a child
child1 = QgsReportSectionFieldGroup()
child1.setLayer(states)
child1.setField('country')
child1_header = QgsLayout(p)
child1.setHeader(child1_header)
child1.setHeaderEnabled(True)
child1_footer = QgsLayout(p)
child1.setFooter(child1_footer)
child1.setFooterEnabled(True)
r.appendChild(child1)
# check that no header was rendered when no features are found
self.assertTrue(r.beginRender())
self.assertFalse(r.next())
child1.setHeaderVisibility(QgsReportSectionFieldGroup.AlwaysInclude)
child1.setFooterVisibility(QgsReportSectionFieldGroup.AlwaysInclude)
# check that the header is included when no features are found
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_footer)
开发者ID:mhugo,项目名称:QGIS,代码行数:31,代码来源:test_qgsreport.py
注:本文中的qgis.core.QgsReportSectionFieldGroup类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论