• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python core.QgsLayoutGuide类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testGuideLayoutPosition

    def testGuideLayoutPosition(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults()
        guides = l.guides()

        # add some guides
        g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(1, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        guides.addGuide(g1)

        # set position in layout units (mm)
        guides.setGuideLayoutPosition(g1, 50)

        self.assertEqual(g1.position().length(), 5.0)
        self.assertEqual(g1.position().units(), QgsUnitTypes.LayoutCentimeters)
开发者ID:pblottiere,项目名称:QGIS,代码行数:15,代码来源:test_qgslayoutguides.py


示例2: testSetVisible

    def testSetVisible(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults()
        guides = l.guides()

        # add some guides
        g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5), l.pageCollection().page(0))
        guides.addGuide(g1)
        g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(6), l.pageCollection().page(0))
        guides.addGuide(g2)

        guides.setVisible(False)
        self.assertFalse(g1.item().isVisible())
        self.assertFalse(g2.item().isVisible())
        guides.setVisible(True)
        self.assertTrue(g1.item().isVisible())
        self.assertTrue(g2.item().isVisible())
开发者ID:pblottiere,项目名称:QGIS,代码行数:18,代码来源:test_qgslayoutguides.py


示例3: testUpdateGuide

    def testUpdateGuide(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults() # add a page
        # add a second page
        page2 = QgsLayoutItemPage(l)
        page2.setPageSize('A5')
        l.pageCollection().addPage(page2)

        g = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        g.setLayout(l)
        g.update()

        self.assertTrue(g.item().isVisible())
        self.assertEqual(g.item().line().x1(), 0)
        self.assertEqual(g.item().line().y1(), 50)
        self.assertEqual(g.item().line().x2(), 297)
        self.assertEqual(g.item().line().y2(), 50)
        self.assertEqual(g.layoutPosition(), 50)

        g.setPosition(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutMillimeters))
        g.update()
        self.assertTrue(g.item().isVisible())
        self.assertEqual(g.item().line().x1(), 0)
        self.assertEqual(g.item().line().y1(), 15)
        self.assertEqual(g.item().line().x2(), 297)
        self.assertEqual(g.item().line().y2(), 15)
        self.assertEqual(g.layoutPosition(), 15)

        # guide on page2
        g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(1))
        g1.setLayout(l)
        g1.update()
        g1.setPosition(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutMillimeters))
        g1.update()
        self.assertTrue(g1.item().isVisible())
        self.assertEqual(g1.item().line().x1(), 0)
        self.assertEqual(g1.item().line().y1(), 235)
        self.assertEqual(g1.item().line().x2(), 148)
        self.assertEqual(g1.item().line().y2(), 235)
        self.assertEqual(g1.layoutPosition(), 235)

        # vertical guide
        g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        g2.setLayout(l)
        g2.update()
        self.assertTrue(g2.item().isVisible())
        self.assertEqual(g2.item().line().x1(), 50)
        self.assertEqual(g2.item().line().y1(), 0)
        self.assertEqual(g2.item().line().x2(), 50)
        self.assertEqual(g2.item().line().y2(), 210)
        self.assertEqual(g2.layoutPosition(), 50)

        g.setPage(None)
        g.update()
        self.assertFalse(g.item().isVisible())

        g.setPage(l.pageCollection().page(0))
        g.update()
        self.assertTrue(g.item().isVisible())

        #throw it off the bottom of the page
        g.setPosition(QgsLayoutMeasurement(1115, QgsUnitTypes.LayoutMillimeters))
        g.update()
        self.assertFalse(g.item().isVisible())

        # guide on page2
        g3 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(1))
        g3.setLayout(l)
        g3.update()
        self.assertTrue(g3.item().isVisible())
        self.assertEqual(g3.item().line().x1(), 50)
        self.assertEqual(g3.item().line().y1(), 220)
        self.assertEqual(g3.item().line().x2(), 50)
        self.assertEqual(g3.item().line().y2(), 430)
        self.assertEqual(g3.layoutPosition(), 50)
开发者ID:pblottiere,项目名称:QGIS,代码行数:76,代码来源:test_qgslayoutguides.py


示例4: testGuideGettersSetters

    def testGuideGettersSetters(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults()  # add a page
        g = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), None)
        self.assertEqual(g.orientation(), Qt.Horizontal)
        self.assertEqual(g.position().length(), 5.0)
        self.assertEqual(g.position().units(), QgsUnitTypes.LayoutCentimeters)

        g.setLayout(l)
        self.assertEqual(g.layout(), l)

        position_changed_spy = QSignalSpy(g.positionChanged)
        g.setPosition(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutInches))
        self.assertEqual(g.position().length(), 15.0)
        self.assertEqual(g.position().units(), QgsUnitTypes.LayoutInches)
        self.assertEqual(len(position_changed_spy), 1)

        page = l.pageCollection().page(0)
        g.setPage(page)
        self.assertEqual(g.page(), page)
开发者ID:pblottiere,项目名称:QGIS,代码行数:21,代码来源:test_qgslayoutguides.py


示例5: testResizeToContents

    def testResizeToContents(self):
        p = QgsProject()
        l = QgsLayout(p)

        shape1 = QgsLayoutItemShape(l)
        shape1.attemptResize(QgsLayoutSize(90, 50))
        shape1.attemptMove(QgsLayoutPoint(90, 50))
        shape1.setItemRotation(45, False)
        l.addLayoutItem(shape1)
        shape2 = QgsLayoutItemShape(l)
        shape2.attemptResize(QgsLayoutSize(110, 50))
        shape2.attemptMove(QgsLayoutPoint(100, 150), True, False, 0)
        l.addLayoutItem(shape2)
        shape3 = QgsLayoutItemShape(l)
        l.addLayoutItem(shape3)
        shape3.attemptResize(QgsLayoutSize(50, 100))
        shape3.attemptMove(QgsLayoutPoint(210, 250), True, False, 0)
        shape4 = QgsLayoutItemShape(l)
        l.addLayoutItem(shape4)
        shape4.attemptResize(QgsLayoutSize(50, 30))
        shape4.attemptMove(QgsLayoutPoint(10, 340), True, False, 0)
        shape4.setVisibility(False)

        # resize with no existing pages
        l.pageCollection().resizeToContents(QgsMargins(1, 2, 3, 4), QgsUnitTypes.LayoutCentimeters)
        self.assertEqual(l.pageCollection().pageCount(), 1)

        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().width(), 290.3, 2)
        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().height(), 380.36, 2)
        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().units(), QgsUnitTypes.LayoutMillimeters)

        self.assertAlmostEqual(shape1.positionWithUnits().x(), 90.15, 2)
        self.assertAlmostEqual(shape1.positionWithUnits().y(), 20.21, 2)
        self.assertAlmostEqual(shape2.positionWithUnits().x(), 100.15, 2)
        self.assertAlmostEqual(shape2.positionWithUnits().y(), 120.21, 2)
        self.assertAlmostEqual(shape3.positionWithUnits().x(), 210.15, 2)
        self.assertAlmostEqual(shape3.positionWithUnits().y(), 220.21, 2)
        self.assertAlmostEqual(shape4.positionWithUnits().x(), 10.15, 2)
        self.assertAlmostEqual(shape4.positionWithUnits().y(), 310.21, 2)

        # add a second page
        page2 = QgsLayoutItemPage(l)
        page2.setPageSize("A4", QgsLayoutItemPage.Landscape)
        l.pageCollection().addPage(page2)

        # add some guides
        g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(2.5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        l.guides().addGuide(g1)
        g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(4.5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        l.guides().addGuide(g2)

        # second page should be removed
        l.pageCollection().resizeToContents(QgsMargins(0, 0, 0, 0), QgsUnitTypes.LayoutCentimeters)
        self.assertEqual(l.pageCollection().pageCount(), 1)

        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().width(), 250.3, 2)
        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().height(), 320.36, 2)
        self.assertAlmostEqual(l.pageCollection().page(0).sizeWithUnits().units(), QgsUnitTypes.LayoutMillimeters)

        self.assertAlmostEqual(g1.position().length(), 0.5, 2)
        self.assertAlmostEqual(g2.position().length(), 3.5, 2)
开发者ID:boundlessgeo,项目名称:QGIS,代码行数:61,代码来源:test_qgslayoutpagecollection.py


示例6: testUpdateGuide

    def testUpdateGuide(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults() # add a page
        g = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        g.setLayout(l)
        g.update()

        self.assertTrue(g.item().isVisible())
        self.assertEqual(g.item().line().x1(), 0)
        self.assertEqual(g.item().line().y1(), 50)
        self.assertEqual(g.item().line().x2(), 297)
        self.assertEqual(g.item().line().y2(), 50)
        self.assertEqual(g.layoutPosition(), 50)

        g.setPosition(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutMillimeters))
        g.update()
        self.assertTrue(g.item().isVisible())
        self.assertEqual(g.item().line().x1(), 0)
        self.assertEqual(g.item().line().y1(), 15)
        self.assertEqual(g.item().line().x2(), 297)
        self.assertEqual(g.item().line().y2(), 15)
        self.assertEqual(g.layoutPosition(), 15)

        # vertical guide
        g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        g2.setLayout(l)
        g2.update()
        self.assertTrue(g2.item().isVisible())
        self.assertEqual(g2.item().line().x1(), 50)
        self.assertEqual(g2.item().line().y1(), 0)
        self.assertEqual(g2.item().line().x2(), 50)
        self.assertEqual(g2.item().line().y2(), 210)
        self.assertEqual(g2.layoutPosition(), 50)

        g.setPage(None)
        g.update()
        self.assertFalse(g.item().isVisible())

        g.setPage(l.pageCollection().page(0))
        g.update()
        self.assertTrue(g.item().isVisible())

        #throw it off the bottom of the page
        g.setPosition(QgsLayoutMeasurement(1115, QgsUnitTypes.LayoutMillimeters))
        g.update()
        self.assertFalse(g.item().isVisible())
开发者ID:minorua,项目名称:QGIS,代码行数:47,代码来源:test_qgslayoutguides.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python core.QgsLayoutItemHtml类代码示例发布时间:2022-05-26
下一篇:
Python core.QgsLayoutGridSettings类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap