def draw_legend(self, top_offset): """Add a legend to the map using our custom legend renderer. .. note:: getLegend generates a pixmap in 150dpi so if you set the map to a higher dpi it will appear undersized. :param top_offset: Vertical offset at which the logo should be drawn. :type top_offset: int """ LOGGER.debug('InaSAFE Map drawLegend called') mapLegendAttributes = self.map_legend_attributes() legendNotes = mapLegendAttributes.get('legend_notes', None) legendUnits = mapLegendAttributes.get('legend_units', None) legendTitle = mapLegendAttributes.get('legend_title', None) LOGGER.debug(mapLegendAttributes) myLegend = MapLegend(self.layer, self.pageDpi, legendTitle, legendNotes, legendUnits) self.legend = myLegend.get_legend() myPicture1 = QgsComposerPicture(self.composition) myLegendFilePath = unique_filename( prefix='legend', suffix='.png', dir='work') self.legend.save(myLegendFilePath, 'PNG') myPicture1.setPictureFile(myLegendFilePath) myLegendHeight = points_to_mm(self.legend.height(), self.pageDpi) myLegendWidth = points_to_mm(self.legend.width(), self.pageDpi) myPicture1.setItemPosition(self.pageMargin, top_offset, myLegendWidth, myLegendHeight) myPicture1.setFrameEnabled(False) self.composition.addItem(myPicture1) os.remove(myLegendFilePath)
def test_windowsDrawingArtifacts(self): """Test that windows rendering does not make artifacts""" # sometimes spurious lines are drawn on the layout myMap = ISMap(IFACE) myMap.setupComposition() myPdfPath = os.path.join(getTempDir(), 'outArtifactsTest.pdf') myMap.setupPrinter(myPdfPath) myPixmap = QtGui.QPixmap(10, 10) myPixmap.fill(QtGui.QColor(250, 250, 250)) myFilename = os.path.join(getTempDir(), 'greyBox') myPixmap.save(myFilename, 'PNG') for i in range(10, 190, 10): myPicture = QgsComposerPicture(myMap.composition) myPicture.setPictureFile(myFilename) myPicture.setFrame(False) myPicture.setItemPosition(i, # x i, # y 10, # width 10) # height myMap.composition.addItem(myPicture) # Same drawing drawn directly as a pixmap myPixmapItem = myMap.composition.addPixmap(myPixmap) myPixmapItem.setOffset(i, i + 20) # Same drawing using our drawPixmap Helper myWidthMM = 1 myMap.drawPixmap(myPixmap, myWidthMM, i, i + 40) myMap.renderPrintout() myUnwantedHash = 'd05e9223d50baf8bb147475aa96d6ba3' myHash = hashForFile(myPdfPath) # when this test no longer matches our broken render hash # we know the issue is fixed myMessage = 'Windows map render still draws with artifacts.' assert myHash != myUnwantedHash, myMessage
def drawLegend(self, theTopOffset): """Add a legend to the map using our custom legend renderer. .. note:: getLegend generates a pixmap in 150dpi so if you set the map to a higher dpi it will appear undersized. Args: theTopOffset - vertical offset at which to begin drawing Returns: None Raises: None """ LOGGER.debug("InaSAFE Map drawLegend called") mapLegendAttributes = self.getMapLegendAtributes() legendNotes = mapLegendAttributes.get("legend_notes", None) legendUnits = mapLegendAttributes.get("legend_units", None) legendTitle = mapLegendAttributes.get("legend_title", None) LOGGER.debug(mapLegendAttributes) myLegend = MapLegend(self.layer, self.pageDpi, legendTitle, legendNotes, legendUnits) self.legend = myLegend.getLegend() myPicture1 = QgsComposerPicture(self.composition) myLegendFilePath = unique_filename(prefix="legend", suffix=".png", dir="work") self.legend.save(myLegendFilePath, "PNG") myPicture1.setPictureFile(myLegendFilePath) myLegendHeight = pointsToMM(self.legend.height(), self.pageDpi) myLegendWidth = pointsToMM(self.legend.width(), self.pageDpi) myPicture1.setItemPosition(self.pageMargin, theTopOffset, myLegendWidth, myLegendHeight) myPicture1.setFrame(False) self.composition.addItem(myPicture1) os.remove(myLegendFilePath)
def drawLegend(self, theTopOffset): """Add a legend to the map using our custom legend renderer. .. note:: getLegend generates a pixmap in 150dpi so if you set the map to a higher dpi it will appear undersized. Args: theTopOffset - vertical offset at which to begin drawing Returns: None Raises: None """ LOGGER.debug('InaSAFE Map drawLegend called') mapLegendAttributes = self.getMapLegendAtributes() legendNotes = mapLegendAttributes.get('legend_notes', None) legendUnits = mapLegendAttributes.get('legend_units', None) legendTitle = mapLegendAttributes.get('legend_title', None) LOGGER.debug(mapLegendAttributes) myLegend = MapLegend(self.layer, self.pageDpi, legendTitle, legendNotes, legendUnits) self.legend = myLegend.getLegend() myPicture1 = QgsComposerPicture(self.composition) myLegendFilePath = unique_filename(prefix='legend', suffix='.png', dir='work') self.legend.save(myLegendFilePath, 'PNG') myPicture1.setPictureFile(myLegendFilePath) myLegendHeight = pointsToMM(self.legend.height(), self.pageDpi) myLegendWidth = pointsToMM(self.legend.width(), self.pageDpi) myPicture1.setItemPosition(self.pageMargin, theTopOffset, myLegendWidth, myLegendHeight) myPicture1.setFrame(False) self.composition.addItem(myPicture1) os.remove(myLegendFilePath)
def drawLegend(self, theTopOffset): """Add a legend to the map using our custom legend renderer. .. note:: getLegend generates a pixmap in 150dpi so if you set the map to a higher dpi it will appear undersized. Args: theTopOffset - vertical offset at which to begin drawing Returns: None Raises: None """ LOGGER.debug('InaSAFE Map drawLegend called') myLegend = MapLegend(self.layer, self.pageDpi) self.legend = myLegend.getLegend() myPicture1 = QgsComposerPicture(self.composition) myLegendFilePath = unique_filename(prefix='legend', suffix='.png', dir='work') self.legend.save(myLegendFilePath, 'PNG') myPicture1.setPictureFile(myLegendFilePath) myLegendHeight = pointsToMM(self.legend.height(), self.pageDpi) myLegendWidth = pointsToMM(self.legend.width(), self.pageDpi) myPicture1.setItemPosition(self.pageMargin, theTopOffset, myLegendWidth, myLegendHeight) myPicture1.setFrame(False) self.composition.addItem(myPicture1) os.remove(myLegendFilePath)
def draw_legend(self, top_offset): """Add a legend to the map using our custom legend renderer. .. note:: getLegend generates a pixmap in 150dpi so if you set the map to a higher dpi it will appear undersized. :param top_offset: Vertical offset at which the logo should be drawn. :type top_offset: int """ LOGGER.debug('InaSAFE Map drawLegend called') legend_attributes = self.map_legend_attributes() legend_notes = legend_attributes.get('legend_notes', None) legend_units = legend_attributes.get('legend_units', None) legend_title = legend_attributes.get('legend_title', None) LOGGER.debug(legend_attributes) legend = MapLegend(self.layer, self.page_dpi, legend_title, legend_notes, legend_units) self.legend = legend.get_legend() picture1 = QgsComposerPicture(self.composition) legend_file_path = unique_filename(prefix='legend', suffix='.png', dir='work') self.legend.save(legend_file_path, 'PNG') picture1.setPictureFile(legend_file_path) legend_height = points_to_mm(self.legend.height(), self.page_dpi) legend_width = points_to_mm(self.legend.width(), self.page_dpi) picture1.setItemPosition(self.page_margin, top_offset, legend_width, legend_height) picture1.setFrameEnabled(False) self.composition.addItem(picture1) os.remove(legend_file_path)
def addPageContent(self, page): ''' Add all needed item for a single page ''' # First get content for parent items for key, item in self.mainTables.items(): self.mainTables[key]['content'] = self.getContentForGivenItem( key, item, page) # Then get content for displayed items for key, item in self.composerTemplates.items(): self.buildComposerLabel(key, item, page) # Add watershed if self.addExperimentalWatershed: w = QgsComposerPicture(self.currentComposition) w.setItemPosition(50, (page - 1) * (self.pageHeight + 10), 150, 100) w.setFrameEnabled(False) pictureFile = os.path.join(self.plugin_dir, "templates/experimental.svg") w.setPictureFile(pictureFile) w.setBackgroundEnabled(False) w.setTransparency(60) self.currentComposition.addItem(w)
def test_windowsDrawingArtifacts(self): """Test that windows rendering does not make artifacts""" # sometimes spurious lines are drawn on the layout myMap = Map(IFACE) myMap.setupComposition() myPdfPath = os.path.join(temp_dir(), 'outArtifactsTest.pdf') myMap.setupPrinter(myPdfPath) myPixmap = QtGui.QPixmap(10, 10) myPixmap.fill(QtGui.QColor(250, 250, 250)) myFilename = os.path.join(temp_dir(), 'greyBox') myPixmap.save(myFilename, 'PNG') for i in range(10, 190, 10): myPicture = QgsComposerPicture(myMap.composition) myPicture.setPictureFile(myFilename) myPicture.setFrame(False) myPicture.setItemPosition(i, # x i, # y 10, # width 10) # height myMap.composition.addItem(myPicture) # Same drawing drawn directly as a pixmap myPixmapItem = myMap.composition.addPixmap(myPixmap) myPixmapItem.setOffset(i, i + 20) # Same drawing using our drawPixmap Helper myWidthMM = 1 myMap.drawPixmap(myPixmap, myWidthMM, i, i + 40) myMap.renderPrintout() myUnwantedHash = 'd05e9223d50baf8bb147475aa96d6ba3' myHash = hashForFile(myPdfPath) # when this test no longer matches our broken render hash # we know the issue is fixed myMessage = 'Windows map render still draws with artifacts.' assert myHash != myUnwantedHash, myMessage
def test_windowsDrawingArtifacts(self): """Test that windows rendering does not make artifacts""" # sometimes spurious lines are drawn on the layout LOGGER.info('Testing windowsDrawingArtifacts') myPath = unique_filename( prefix='artifacts', suffix='.pdf', dir=temp_dir('test')) myMap = Map(IFACE) setup_printer(myPath) myMap.setup_composition() myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32) myImage.setDotsPerMeterX(dpi_to_meters(300)) myImage.setDotsPerMeterY(dpi_to_meters(300)) #myImage.fill(QtGui.QColor(250, 250, 250)) # Look at the output, you will see antialiasing issues around some # of the boxes drawn... # myImage.fill(QtGui.QColor(200, 200, 200)) myImage.fill(200 + 200 * 256 + 200 * 256 * 256) myFilename = os.path.join(temp_dir(), 'greyBox') myImage.save(myFilename, 'PNG') for i in range(10, 190, 10): myPicture = QgsComposerPicture(myMap.composition) myPicture.setPictureFile(myFilename) if qgis_version() >= 10800: # 1.8 or newer myPicture.setFrameEnabled(False) else: myPicture.setFrame(False) myPicture.setItemPosition(i, # x i, # y 10, # width 10) # height myMap.composition.addItem(myPicture) # Same drawing drawn directly as a pixmap # noinspection PyCallByClass,PyTypeChecker,PyArgumentList myPixmapItem = myMap.composition.addPixmap( QtGui.QPixmap.fromImage(myImage)) myPixmapItem.setOffset(i, i + 20) # Same drawing using our drawImage Helper myWidthMM = 1 myMap.draw_image(myImage, myWidthMM, i, i + 40) myImagePath, _, _ = myMap.render() # when this test no longer matches our broken render hash # we know the issue is fixed myTolerance = 0 myFlag, myMessage = check_images( 'windowsArtifacts', myImagePath, myTolerance) myMessage += ('\nWe want these images to match, if they do not ' 'there may be rendering artifacts in windows.\n') assert myFlag, myMessage
def draw_logo(self, top_offset): """Add a picture containing the logo to the map top left corner :param top_offset: Vertical offset at which the logo should be drawn. :type top_offset: int """ myLogo = QgsComposerPicture(self.composition) myLogo.setPictureFile(':/plugins/inasafe/bnpb_logo.png') myLogo.setItemPosition(self.pageMargin, top_offset, 10, 10) myLogo.setFrameEnabled(self.showFramesFlag) myLogo.setZValue(1) # To ensure it overlays graticule markers self.composition.addItem(myLogo)
def draw_logo(self, top_offset): """Add a picture containing the logo to the map top left corner :param top_offset: Vertical offset at which the logo should be drawn. :type top_offset: int """ logo = QgsComposerPicture(self.composition) logo.setPictureFile(':/plugins/inasafe/bnpb_logo.png') logo.setItemPosition(self.page_margin, top_offset, 10, 10) logo.setFrameEnabled(self.show_frames) logo.setZValue(1) # To ensure it overlays graticule markers self.composition.addItem(logo)
def draw_logo(self, top_offset): """Add a picture containing the logo to the map top left corner :param top_offset: Vertical offset at which the logo should be drawn. :type top_offset: int """ myLogo = QgsComposerPicture(self.composition) myLogo.setPictureFile(':/plugins/inasafe/bnpb_logo.png') myLogo.setItemPosition(self.pageMargin, top_offset, 10, 10) if qgis_version() >= 10800: # 1.8 or newer myLogo.setFrameEnabled(self.showFramesFlag) else: myLogo.setFrame(self.showFramesFlag) myLogo.setZValue(1) # To ensure it overlays graticule markers self.composition.addItem(myLogo)
def drawLogo(self, theTopOffset): """Add a picture containing the logo to the map top left corner Args: theTopOffset - vertical offset at which the logo shoudl be drawn Returns: None Raises: None """ myLogo = QgsComposerPicture(self.composition) myLogo.setPictureFile(':/plugins/inasafe/bnpb_logo.png') myLogo.setItemPosition(self.pageMargin, theTopOffset, 10, 10) myLogo.setFrame(self.showFramesFlag) myLogo.setZValue(1) # To ensure it overlays graticule markers self.composition.addItem(myLogo)
def test_windowsDrawingArtifacts(self): """Test that windows rendering does not make artifacts""" # sometimes spurious lines are drawn on the layout LOGGER.info("Testing windowsDrawingArtifacts") myPath = unique_filename(prefix="artifacts", suffix=".pdf", dir=temp_dir("test")) myMap = Map(IFACE) setupPrinter(myPath) myMap.setupComposition() myImage = QtGui.QImage(10, 10, QtGui.QImage.Format_RGB32) myImage.setDotsPerMeterX(dpiToMeters(300)) myImage.setDotsPerMeterY(dpiToMeters(300)) # myImage.fill(QtGui.QColor(250, 250, 250)) # Look at the output, you will see antialiasing issues around some # of the boxes drawn... # myImage.fill(QtGui.QColor(200, 200, 200)) myImage.fill(200 + 200 * 256 + 200 * 256 * 256) myFilename = os.path.join(temp_dir(), "greyBox") myImage.save(myFilename, "PNG") for i in range(10, 190, 10): myPicture = QgsComposerPicture(myMap.composition) myPicture.setPictureFile(myFilename) if qgisVersion() >= 10800: # 1.8 or newer myPicture.setFrameEnabled(False) else: myPicture.setFrame(False) myPicture.setItemPosition(i, i, 10, 10) # x # y # width # height myMap.composition.addItem(myPicture) # Same drawing drawn directly as a pixmap myPixmapItem = myMap.composition.addPixmap(QtGui.QPixmap.fromImage(myImage)) myPixmapItem.setOffset(i, i + 20) # Same drawing using our drawImage Helper myWidthMM = 1 myMap.drawImage(myImage, myWidthMM, i, i + 40) myImagePath, _, _ = myMap.renderComposition() # when this test no longer matches our broken render hash # we know the issue is fixed myControlImages = ["windowsArtifacts.png"] myTolerance = 0 myFlag, myMessage = checkImages(myControlImages, myImagePath, myTolerance) myMessage += "\nWe want these images to match, if they do not " "there may be rendering artifacts in windows.\n" assert myFlag, myMessage
def drawLogo(self, theTopOffset): """Add a picture containing the logo to the map top left corner Args: theTopOffset - vertical offset at which the logo shoudl be drawn Returns: None Raises: None """ myLogo = QgsComposerPicture(self.composition) myLogo.setPictureFile(":/plugins/inasafe/bnpb_logo.png") myLogo.setItemPosition(self.pageMargin, theTopOffset, 10, 10) if qgisVersion() >= 10800: # 1.8 or newer myLogo.setFrameEnabled(self.showFramesFlag) else: myLogo.setFrame(self.showFramesFlag) myLogo.setZValue(1) # To ensure it overlays graticule markers self.composition.addItem(myLogo)