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


Python QGraphicsLineItem.setVisible方法代码示例

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


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

示例1: testSnapPointsToItems

# 需要导入模块: from qgis.PyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QGraphicsLineItem import setVisible [as 别名]
    def testSnapPointsToItems(self):
        p = QgsProject()
        l = QgsLayout(p)
        page = QgsLayoutItemPage(l)
        page.setPageSize('A4')
        #l.pageCollection().addPage(page)
        s = QgsLayoutSnapper(l)
        guides = l.guides()

        s.setSnapToItems(True)
        s.setSnapTolerance(1)

        # no items
        point, snapped = s.snapPointsToItems([0.5], Qt.Horizontal, 1, [])
        self.assertFalse(snapped)

        line = QGraphicsLineItem()
        line.setVisible(True)
        point, snapped = s.snapPointsToItems([0.5], Qt.Horizontal, 1, [], line)
        self.assertFalse(line.isVisible())

        guides.addGuide(QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(1), page))

        # add an item
        item1 = QgsLayoutItemMap(l)
        item1.attemptMove(QgsLayoutPoint(4, 8, QgsUnitTypes.LayoutMillimeters))
        item1.attemptResize(QgsLayoutSize(18, 12, QgsUnitTypes.LayoutMillimeters))
        l.addItem(item1)

        point, snapped = s.snapPointsToItems([3.5], Qt.Horizontal, 1, [], line)
        self.assertTrue(snapped)
        self.assertEqual(point, 0.5)
        self.assertTrue(line.isVisible())
        point, snapped = s.snapPointsToItems([4.5], Qt.Horizontal, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, -0.5)
        point, snapped = s.snapPointsToItems([4.6, 4.5], Qt.Horizontal, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, -0.5)
        point, snapped = s.snapPointsToItems([4.6, 4.5, 3.7], Qt.Horizontal, 1, [])
        self.assertTrue(snapped)
        self.assertAlmostEqual(point, 0.3, 5)

        # ignoring item
        point, snapped = s.snapPointsToItems([4.5], Qt.Horizontal, 1, [item1])
        self.assertFalse(snapped)

        # outside tolerance
        point, snapped = s.snapPointsToItems([5.5], Qt.Horizontal, 1, [], line)
        self.assertFalse(snapped)
        self.assertFalse(line.isVisible())

        # snap to center
        point, snapped = s.snapPointsToItems([12.5], Qt.Horizontal, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, 0.5)

        # snap to right
        point, snapped = s.snapPointsToItems([22.5], Qt.Horizontal, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, -0.5)

        #snap to top
        point, snapped = s.snapPointsToItems([7.5], Qt.Vertical, 1, [], line)
        self.assertTrue(snapped)
        self.assertEqual(point, 0.5)
        self.assertTrue(line.isVisible())
        point, snapped = s.snapPointsToItems([8.5], Qt.Vertical, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, -0.5)

        # outside tolerance
        point, snapped = s.snapPointsToItems([5.5], Qt.Vertical, 1, [], line)
        self.assertFalse(snapped)
        self.assertFalse(line.isVisible())

        # snap to center
        point, snapped = s.snapPointsToItems([13.5], Qt.Vertical, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, 0.5)

        # snap to bottom
        point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 1, [])
        self.assertTrue(snapped)
        self.assertEqual(point, -0.5)

        # snapping off
        s.setSnapToItems(False)
        line.setVisible(True)
        point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 1, [], line)
        self.assertFalse(snapped)
        self.assertFalse(line.isVisible())

        # with different pixel scale
        s.setSnapToItems(True)
        point, snapped = s.snapPointsToItems([20.5], Qt.Vertical, 3, [])
        self.assertFalse(snapped)
开发者ID:elpaso,项目名称:QGIS,代码行数:99,代码来源:test_qgslayoutsnapper.py


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