本文整理汇总了Python中qgis.core.QgsLayout.undoStack方法的典型用法代码示例。如果您正苦于以下问题:Python QgsLayout.undoStack方法的具体用法?Python QgsLayout.undoStack怎么用?Python QgsLayout.undoStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsLayout
的用法示例。
在下文中一共展示了QgsLayout.undoStack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testResize
# 需要导入模块: from qgis.core import QgsLayout [as 别名]
# 或者: from qgis.core.QgsLayout import undoStack [as 别名]
def testResize(self):
p = QgsProject()
l = QgsLayout(p)
# add some items
item1 = QgsLayoutItemPicture(l)
item1.attemptMove(QgsLayoutPoint(4, 8, QgsUnitTypes.LayoutMillimeters))
item1.attemptResize(QgsLayoutSize(18, 12, QgsUnitTypes.LayoutMillimeters))
l.addItem(item1)
item2 = QgsLayoutItemPicture(l)
item2.attemptMove(QgsLayoutPoint(7, 10, QgsUnitTypes.LayoutMillimeters))
item2.attemptResize(QgsLayoutSize(10, 9, QgsUnitTypes.LayoutMillimeters))
l.addItem(item2)
# NOTE: item3 has measurement units specified in Centimeters, see below!
item3 = QgsLayoutItemPicture(l)
item3.attemptMove(QgsLayoutPoint(0.8, 1.2, QgsUnitTypes.LayoutCentimeters))
item3.attemptResize(QgsLayoutSize(1.8, 1.6, QgsUnitTypes.LayoutCentimeters))
l.addItem(item3)
QgsLayoutAligner.resizeItems(l, [item1, item2, item3], QgsLayoutAligner.ResizeNarrowest)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(10, 12, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item2.sizeWithUnits(), QgsLayoutSize(10, 9, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item3.sizeWithUnits(), QgsLayoutSize(1.0, 1.6, QgsUnitTypes.LayoutCentimeters))
l.undoStack().stack().undo()
QgsLayoutAligner.resizeItems(l, [item1, item2, item3], QgsLayoutAligner.ResizeWidest)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(18, 12, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item2.sizeWithUnits(), QgsLayoutSize(18, 9, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item3.sizeWithUnits(), QgsLayoutSize(1.8, 1.6, QgsUnitTypes.LayoutCentimeters))
l.undoStack().stack().undo()
QgsLayoutAligner.resizeItems(l, [item1, item2, item3], QgsLayoutAligner.ResizeShortest)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(18, 9, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item2.sizeWithUnits(), QgsLayoutSize(10, 9, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item3.sizeWithUnits(), QgsLayoutSize(1.8, 0.9, QgsUnitTypes.LayoutCentimeters))
l.undoStack().stack().undo()
QgsLayoutAligner.resizeItems(l, [item1, item2, item3], QgsLayoutAligner.ResizeTallest)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(18, 16, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item2.sizeWithUnits(), QgsLayoutSize(10, 16, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item3.sizeWithUnits(), QgsLayoutSize(1.8, 1.6, QgsUnitTypes.LayoutCentimeters))
l.undoStack().stack().undo()
item2.attemptResize(QgsLayoutSize(10, 19, QgsUnitTypes.LayoutMillimeters))
QgsLayoutAligner.resizeItems(l, [item1, item2, item3], QgsLayoutAligner.ResizeToSquare)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(18, 18, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item2.sizeWithUnits(), QgsLayoutSize(19, 19, QgsUnitTypes.LayoutMillimeters))
self.assertEqual(item3.sizeWithUnits(), QgsLayoutSize(1.8, 1.8, QgsUnitTypes.LayoutCentimeters))
l.undoStack().stack().undo()
QgsLayoutAligner.resizeItems(l, [item1], QgsLayoutAligner.ResizeToSquare)
self.assertEqual(item1.sizeWithUnits(), QgsLayoutSize(18, 18, QgsUnitTypes.LayoutMillimeters))
示例2: testUndoRedo
# 需要导入模块: from qgis.core import QgsLayout [as 别名]
# 或者: from qgis.core.QgsLayout import undoStack [as 别名]
def testUndoRedo(self):
p = QgsProject()
l = QgsLayout(p)
g = l.gridSettings()
g.setResolution(QgsLayoutMeasurement(15, QgsUnitTypes.LayoutPoints))
# these two commands should be 'collapsed'
g.setOffset(QgsLayoutPoint(555, 10, QgsUnitTypes.LayoutPoints))
g.setOffset(QgsLayoutPoint(5, 10, QgsUnitTypes.LayoutPoints))
# these two commands should be 'collapsed'
g.setResolution(QgsLayoutMeasurement(45, QgsUnitTypes.LayoutInches))
g.setResolution(QgsLayoutMeasurement(35, QgsUnitTypes.LayoutInches))
self.assertEqual(g.offset().x(), 5.0)
self.assertEqual(g.offset().y(), 10.0)
self.assertEqual(g.offset().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(g.resolution().length(), 35.0)
self.assertEqual(g.resolution().units(), QgsUnitTypes.LayoutInches)
l.undoStack().stack().undo()
self.assertEqual(g.offset().x(), 5.0)
self.assertEqual(g.offset().y(), 10.0)
self.assertEqual(g.offset().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(g.resolution().length(), 15.0)
self.assertEqual(g.resolution().units(), QgsUnitTypes.LayoutPoints)
l.undoStack().stack().undo()
self.assertEqual(g.offset().x(), 0.0)
self.assertEqual(g.offset().y(), 0.0)
self.assertEqual(g.offset().units(), QgsUnitTypes.LayoutMillimeters)
self.assertEqual(g.resolution().length(), 15.0)
self.assertEqual(g.resolution().units(), QgsUnitTypes.LayoutPoints)
l.undoStack().stack().redo()
self.assertEqual(g.offset().x(), 5.0)
self.assertEqual(g.offset().y(), 10.0)
self.assertEqual(g.offset().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(g.resolution().length(), 15.0)
self.assertEqual(g.resolution().units(), QgsUnitTypes.LayoutPoints)
l.undoStack().stack().redo()
self.assertEqual(g.offset().x(), 5.0)
self.assertEqual(g.offset().y(), 10.0)
self.assertEqual(g.offset().units(), QgsUnitTypes.LayoutPoints)
self.assertEqual(g.resolution().length(), 35.0)
self.assertEqual(g.resolution().units(), QgsUnitTypes.LayoutInches)
示例3: testUndoRedo
# 需要导入模块: from qgis.core import QgsLayout [as 别名]
# 或者: from qgis.core.QgsLayout import undoStack [as 别名]
def testUndoRedo(self):
p = QgsProject()
l = QgsLayout(p)
collection = l.pageCollection()
# add a page
page = QgsLayoutItemPage(l)
page.setPageSize('A4')
collection.addPage(page)
self.assertEqual(collection.pageCount(), 1)
l.undoStack().stack().undo()
self.assertEqual(collection.pageCount(), 0)
l.undoStack().stack().redo()
self.assertEqual(collection.pageCount(), 1)
# make sure page is accessible
self.assertEqual(collection.page(0).pageSize().width(), 210)
# add a second page
page2 = QgsLayoutItemPage(l)
page2.setPageSize('A5')
collection.addPage(page2)
# delete page
collection.deletePage(collection.page(0))
self.assertEqual(collection.pageCount(), 1)
l.undoStack().stack().undo()
self.assertEqual(collection.pageCount(), 2)
# make sure pages are accessible
self.assertEqual(collection.page(0).pageSize().width(), 210)
self.assertEqual(collection.page(1).pageSize().width(), 148)
l.undoStack().stack().undo()
self.assertEqual(collection.pageCount(), 1)
l.undoStack().stack().undo()
self.assertEqual(collection.pageCount(), 0)
l.undoStack().stack().redo()
self.assertEqual(collection.pageCount(), 1)
self.assertEqual(collection.page(0).pageSize().width(), 210)
l.undoStack().stack().redo()
self.assertEqual(collection.pageCount(), 2)
self.assertEqual(collection.page(0).pageSize().width(), 210)
self.assertEqual(collection.page(1).pageSize().width(), 148)
l.undoStack().stack().redo()
self.assertEqual(collection.pageCount(), 1)
self.assertEqual(collection.page(0).pageSize().width(), 148)