本文整理汇总了Python中qgis.core.QgsReportSectionLayout类的典型用法代码示例。如果您正苦于以下问题:Python QgsReportSectionLayout类的具体用法?Python QgsReportSectionLayout怎么用?Python QgsReportSectionLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsReportSectionLayout类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例2: testchildSections
def testchildSections(self):
p = QgsProject()
r = QgsReport(p)
self.assertEqual(r.childCount(), 0)
self.assertEqual(r.childSections(), [])
self.assertIsNone(r.childSection(-1))
self.assertIsNone(r.childSection(1))
self.assertIsNone(r.childSection(0))
# try deleting non-existent childSections
r.removeChildAt(-1)
r.removeChildAt(0)
r.removeChildAt(100)
r.removeChild(None)
# append child
child1 = QgsReportSectionLayout()
self.assertIsNone(child1.project())
r.appendChild(child1)
self.assertEqual(r.childCount(), 1)
self.assertEqual(r.childSections(), [child1])
self.assertEqual(r.childSection(0), child1)
self.assertEqual(child1.parentSection(), r)
self.assertEqual(child1.row(), 0)
self.assertEqual(child1.project(), p)
child2 = QgsReportSectionLayout()
r.appendChild(child2)
self.assertEqual(r.childCount(), 2)
self.assertEqual(r.childSections(), [child1, child2])
self.assertEqual(r.childSection(1), child2)
self.assertEqual(child2.parentSection(), r)
self.assertEqual(child2.row(), 1)
示例3: testInsertChild
def testInsertChild(self):
p = QgsProject()
r = QgsReport(p)
child1 = QgsReportSectionLayout()
r.insertChild(11, child1)
self.assertEqual(r.childCount(), 1)
self.assertEqual(r.childSections(), [child1])
self.assertEqual(child1.parentSection(), r)
self.assertEqual(child1.row(), 0)
child2 = QgsReportSectionLayout()
r.insertChild(-1, child2)
self.assertEqual(r.childCount(), 2)
self.assertEqual(r.childSections(), [child2, child1])
self.assertEqual(child2.parentSection(), r)
self.assertEqual(child2.row(), 0)
self.assertEqual(child1.row(), 1)
示例4: testClone
def testClone(self):
p = QgsProject()
r = QgsReport(p)
child1 = QgsReportSectionLayout()
child1.setHeaderEnabled(True)
r.appendChild(child1)
child2 = QgsReportSectionLayout()
child2.setFooterEnabled(True)
r.appendChild(child2)
cloned = r.clone()
self.assertEqual(cloned.childCount(), 2)
self.assertTrue(cloned.childSection(0).headerEnabled())
self.assertFalse(cloned.childSection(0).footerEnabled())
self.assertEqual(cloned.childSection(0).parentSection(), cloned)
self.assertFalse(cloned.childSection(1).headerEnabled())
self.assertTrue(cloned.childSection(1).footerEnabled())
self.assertEqual(cloned.childSection(1).parentSection(), cloned)
示例5: testIteration
def testIteration(self):
p = QgsProject()
r = QgsReport(p)
# empty report
self.assertTrue(r.beginRender())
self.assertFalse(r.next())
# add a header
r.setHeaderEnabled(True)
report_header = QgsLayout(p)
r.setHeader(report_header)
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_header)
self.assertFalse(r.next())
# add a footer
r.setFooterEnabled(True)
report_footer = QgsLayout(p)
r.setFooter(report_footer)
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_footer)
self.assertFalse(r.next())
# add a child
child1 = QgsReportSectionLayout()
child1_body = QgsLayout(p)
child1.setBody(child1_body)
r.appendChild(child1)
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_body)
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_footer)
self.assertFalse(r.next())
# header and footer on child
child1_header = QgsLayout(p)
child1.setHeader(child1_header)
child1.setHeaderEnabled(True)
child1_footer = QgsLayout(p)
child1.setFooter(child1_footer)
child1.setFooterEnabled(True)
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_body)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_footer)
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_footer)
self.assertFalse(r.next())
# add another child
child2 = QgsReportSectionLayout()
child2_header = QgsLayout(p)
child2.setHeader(child2_header)
child2.setHeaderEnabled(True)
child2_footer = QgsLayout(p)
child2.setFooter(child2_footer)
child2.setFooterEnabled(True)
r.appendChild(child2)
self.assertTrue(r.beginRender())
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_body)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child1_footer)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child2_header)
self.assertTrue(r.next())
self.assertEqual(r.layout(), child2_footer)
self.assertTrue(r.next())
self.assertEqual(r.layout(), report_footer)
self.assertFalse(r.next())
# add a child to child2
child2a = QgsReportSectionLayout()
child2a_header = QgsLayout(p)
child2a.setHeader(child2a_header)
child2a.setHeaderEnabled(True)
child2a_footer = QgsLayout(p)
child2a.setFooter(child2a_footer)
child2a.setFooterEnabled(True)
child2.appendChild(child2a)
self.assertTrue(r.beginRender())
#.........这里部分代码省略.........
示例6: testReportSectionLayout
def testReportSectionLayout(self):
r = QgsReportSectionLayout()
p = QgsProject()
body = QgsLayout(p)
r.setBody(body)
self.assertEqual(r.body(), body)