本文整理匯總了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)