本文整理汇总了Python中qgis.gui.QgsLayoutView.hasItemsInClipboard方法的典型用法代码示例。如果您正苦于以下问题:Python QgsLayoutView.hasItemsInClipboard方法的具体用法?Python QgsLayoutView.hasItemsInClipboard怎么用?Python QgsLayoutView.hasItemsInClipboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.gui.QgsLayoutView
的用法示例。
在下文中一共展示了QgsLayoutView.hasItemsInClipboard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCopyPaste
# 需要导入模块: from qgis.gui import QgsLayoutView [as 别名]
# 或者: from qgis.gui.QgsLayoutView import hasItemsInClipboard [as 别名]
def testCopyPaste(self):
p = QgsProject()
l = QgsLayout(p)
# clear clipboard
mime_data = QMimeData()
mime_data.setData("text/xml", QByteArray())
clipboard = QApplication.clipboard()
clipboard.setMimeData(mime_data)
# add an item
item1 = QgsLayoutItemLabel(l)
item1.setText('label 1')
l.addLayoutItem(item1)
item1.setSelected(True)
item2 = QgsLayoutItemLabel(l)
item2.setText('label 2')
l.addLayoutItem(item2)
item2.setSelected(True)
view = QgsLayoutView()
view.setCurrentLayout(l)
self.assertFalse(view.hasItemsInClipboard())
view.copySelectedItems(QgsLayoutView.ClipboardCopy)
self.assertTrue(view.hasItemsInClipboard())
pasted = view.pasteItems(QgsLayoutView.PasteModeCursor)
self.assertEqual(len(pasted), 2)
self.assertIn(pasted[0], l.items())
self.assertIn(pasted[1], l.items())
self.assertIn(sip.cast(pasted[0], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))
self.assertIn(sip.cast(pasted[1], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))
# copy specific item
view.copyItems([item2], QgsLayoutView.ClipboardCopy)
l2 = QgsLayout(p)
view2 = QgsLayoutView()
view2.setCurrentLayout(l2)
pasted = view2.pasteItems(QgsLayoutView.PasteModeCursor)
self.assertEqual(len(pasted), 1)
self.assertIn(pasted[0], l2.items())
self.assertEqual(sip.cast(pasted[0], QgsLayoutItemLabel).text(), 'label 2')
示例2: testCopyPaste
# 需要导入模块: from qgis.gui import QgsLayoutView [as 别名]
# 或者: from qgis.gui.QgsLayoutView import hasItemsInClipboard [as 别名]
def testCopyPaste(self):
p = QgsProject()
l = QgsLayout(p)
# clear clipboard
mime_data = QMimeData()
mime_data.setData("text/xml", QByteArray())
clipboard = QApplication.clipboard()
clipboard.setMimeData(mime_data)
# add an item
item1 = QgsLayoutItemLabel(l)
item1.setText('label 1')
l.addLayoutItem(item1)
item1.setSelected(True)
item2 = QgsLayoutItemLabel(l)
item2.setText('label 2')
l.addLayoutItem(item2)
item2.setSelected(True)
# multiframes
multiframe1 = QgsLayoutItemHtml(l)
multiframe1.setHtml('mf1')
l.addMultiFrame(multiframe1)
frame1 = QgsLayoutFrame(l, multiframe1)
frame1.setId('frame1a')
multiframe1.addFrame(frame1)
frame1b = QgsLayoutFrame(l, multiframe1)
frame1b.setId('frame1b')
multiframe1.addFrame(frame1b) # not selected
frame1c = QgsLayoutFrame(l, multiframe1)
frame1c.setId('frame1b')
multiframe1.addFrame(frame1c) # not selected
multiframe2 = QgsLayoutItemHtml(l)
multiframe2.setHtml('mf2')
l.addMultiFrame(multiframe2)
frame2 = QgsLayoutFrame(l, multiframe2)
frame2.setId('frame2')
multiframe2.addFrame(frame2)
frame1.setSelected(True)
frame2.setSelected(True)
view = QgsLayoutView()
view.setCurrentLayout(l)
self.assertFalse(view.hasItemsInClipboard())
view.copySelectedItems(QgsLayoutView.ClipboardCopy)
self.assertTrue(view.hasItemsInClipboard())
pasted = view.pasteItems(QgsLayoutView.PasteModeCursor)
self.assertEqual(len(pasted), 4)
new_multiframes = [m for m in l.multiFrames() if m not in [multiframe1, multiframe2]]
self.assertEqual(len(new_multiframes), 2)
self.assertIn(pasted[0], l.items())
self.assertIn(pasted[1], l.items())
labels = [p for p in pasted if p.type() == QgsLayoutItemRegistry.LayoutLabel]
self.assertIn(sip.cast(labels[0], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))
self.assertIn(sip.cast(labels[1], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))
frames = [p for p in pasted if p.type() == QgsLayoutItemRegistry.LayoutFrame]
pasted_frame1 = sip.cast(frames[0], QgsLayoutFrame)
pasted_frame2 = sip.cast(frames[1], QgsLayoutFrame)
self.assertIn(pasted_frame1.multiFrame(), new_multiframes)
self.assertIn(new_multiframes[0].frames()[0].uuid(), (pasted_frame1.uuid(), pasted_frame2.uuid()))
self.assertIn(pasted_frame2.multiFrame(), new_multiframes)
self.assertIn(new_multiframes[1].frames()[0].uuid(), (pasted_frame1.uuid(), pasted_frame2.uuid()))
self.assertEqual(frame1.multiFrame(), multiframe1)
self.assertCountEqual(multiframe1.frames(), [frame1, frame1b, frame1c])
self.assertEqual(frame1b.multiFrame(), multiframe1)
self.assertEqual(frame1c.multiFrame(), multiframe1)
self.assertEqual(frame2.multiFrame(), multiframe2)
self.assertCountEqual(multiframe2.frames(), [frame2])
# copy specific item
view.copyItems([item2], QgsLayoutView.ClipboardCopy)
l2 = QgsLayout(p)
view2 = QgsLayoutView()
view2.setCurrentLayout(l2)
pasted = view2.pasteItems(QgsLayoutView.PasteModeCursor)
self.assertEqual(len(pasted), 1)
self.assertIn(pasted[0], l2.items())
self.assertEqual(sip.cast(pasted[0], QgsLayoutItemLabel).text(), 'label 2')