本文整理汇总了Python中qgis.PyQt.QtWidgets.QGraphicsLineItem.isVisible方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.isVisible方法的具体用法?Python QGraphicsLineItem.isVisible怎么用?Python QGraphicsLineItem.isVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtWidgets.QGraphicsLineItem
的用法示例。
在下文中一共展示了QGraphicsLineItem.isVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSnapPointsToItems
# 需要导入模块: from qgis.PyQt.QtWidgets import QGraphicsLineItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QGraphicsLineItem import isVisible [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)