def createComposition(self): ''' Create a print Layout ''' c = QgsPrintLayout(self.mProject) c.initializeDefaults() c.setUnits(QgsUnitTypes.LayoutMillimeters) g=QgsLayoutGridSettings(c) g.setOffset( QgsLayoutPoint(3.5, 0, QgsUnitTypes.LayoutMillimeters) ) g.setResolution( QgsLayoutMeasurement(2.5) ) # Set page number self.getPageNumberNeeded() # Set main properties for i in range(1, self.numPages): p=QgsLayoutItemPage(c) #page.setPageSize('A6') p.setPageSize( QgsLayoutSize(self.pageWidth, self.pageHeight, QgsUnitTypes.LayoutMillimeters) ) c.pageCollection().addPage(p) # Set the global currentComposition self.currentComposition = c
def testReadWriteXml(self): p = QgsProject() l = QgsLayout(p) s = QgsLayoutGridSettings(l) s.setResolution(QgsLayoutMeasurement(5, QgsUnitTypes.LayoutPoints)) s.setOffset(QgsLayoutPoint(6, 7, QgsUnitTypes.LayoutPixels)) doc = QDomDocument("testdoc") elem = doc.createElement("test") self.assertTrue(s.writeXml(elem, doc, QgsReadWriteContext())) s2 = QgsLayoutGridSettings(l) self.assertTrue(s2.readXml(elem.firstChildElement(), doc, QgsReadWriteContext())) self.assertEqual(s2.resolution().length(), 5.0) self.assertEqual(s2.resolution().units(), QgsUnitTypes.LayoutPoints) self.assertEqual(s2.offset().x(), 6.0) self.assertEqual(s2.offset().y(), 7.0) self.assertEqual(s2.offset().units(), QgsUnitTypes.LayoutPixels)
def testGettersSetters(self): p = QgsProject() l = QgsLayout(p) s = QgsLayoutGridSettings(l) s.setResolution(QgsLayoutMeasurement(5, QgsUnitTypes.LayoutPoints)) self.assertEqual(s.resolution().length(), 5.0) self.assertEqual(s.resolution().units(), QgsUnitTypes.LayoutPoints) s.setOffset(QgsLayoutPoint(6, 7, QgsUnitTypes.LayoutPixels)) self.assertEqual(s.offset().x(), 6.0) self.assertEqual(s.offset().y(), 7.0) self.assertEqual(s.offset().units(), QgsUnitTypes.LayoutPixels) s.setPen(QPen(QColor(255, 0, 255))) self.assertEqual(s.pen().color().name(), QColor(255, 0, 255).name()) s.setStyle(QgsLayoutGridSettings.StyleDots) self.assertEqual(s.style(), QgsLayoutGridSettings.StyleDots)
def testReadWriteXml(self): p = QgsProject() l = QgsLayout(p) s = QgsLayoutGridSettings(l) s.setResolution(QgsLayoutMeasurement(5, QgsUnitTypes.LayoutPoints)) s.setOffset(QgsLayoutPoint(6, 7, QgsUnitTypes.LayoutPixels)) doc = QDomDocument("testdoc") elem = doc.createElement("test") self.assertTrue(s.writeXml(elem, doc, QgsReadWriteContext())) s2 = QgsLayoutGridSettings(l) self.assertTrue( s2.readXml(elem.firstChildElement(), doc, QgsReadWriteContext())) self.assertEqual(s2.resolution().length(), 5.0) self.assertEqual(s2.resolution().units(), QgsUnitTypes.LayoutPoints) self.assertEqual(s2.offset().x(), 6.0) self.assertEqual(s2.offset().y(), 7.0) self.assertEqual(s2.offset().units(), QgsUnitTypes.LayoutPixels)