def testRenderMarker(self): item = QgsAnnotationPointTextItem('my text', QgsPointXY(12.3, 13.2)) format = QgsTextFormat.fromQFont(getTestFont('Bold')) format.setColor(QColor(255, 0, 0)) format.setOpacity(150 / 255) format.setSize(20) item.setFormat(format) item.setAngle(30) item.setAlignment(Qt.AlignRight) settings = QgsMapSettings() settings.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326')) settings.setExtent(QgsRectangle(10, 10, 16, 16)) settings.setOutputSize(QSize(300, 300)) settings.setFlag(QgsMapSettings.Antialiasing, False) rc = QgsRenderContext.fromMapSettings(settings) image = QImage(200, 200, QImage.Format_ARGB32) image.setDotsPerMeterX(96 / 25.4 * 1000) image.setDotsPerMeterY(96 / 25.4 * 1000) image.fill(QColor(255, 255, 255)) painter = QPainter(image) rc.setPainter(painter) try: item.render(rc, None) finally: painter.end() self.assertTrue( self.imageCheck('pointtext_item', 'pointtext_item', image))
def testDataDefinedEnabled(self): layout = QgsLayout(QgsProject.instance()) layout.initializeDefaults() map = QgsLayoutItemMap(layout) map.attemptSetSceneRect(QRectF(20, 20, 200, 100)) map.setFrameEnabled(True) map.setBackgroundColor(QColor(150, 100, 100)) layout.addLayoutItem(map) myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125) map.setExtent(myRectangle) map.grid().setEnabled(True) map.grid().setIntervalX(2000) map.grid().setIntervalY(2000) map.grid().setAnnotationEnabled(True) map.grid().setGridLineColor(QColor(0, 255, 0)) map.grid().setGridLineWidth(0.5) format = QgsTextFormat.fromQFont(getTestFont('Bold')) format.setColor(QColor(255, 0, 0)) format.setOpacity(150 / 255) map.grid().setAnnotationTextFormat(format) map.grid().setAnnotationPrecision(0) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Left) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Top) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Bottom) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Bottom) map.grid().setBlendMode(QPainter.CompositionMode_Overlay) map.updateBoundingRect() map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridEnabled, QgsProperty.fromValue(True)) map.grid().refresh() checker = QgsLayoutChecker('composermap_grid', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridEnabled, QgsProperty.fromValue(False)) map.grid().refresh() checker = QgsLayoutChecker('composermap_datadefined_disabled', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage)
def testGrid(self): layout = QgsLayout(QgsProject.instance()) layout.initializeDefaults() map = QgsLayoutItemMap(layout) map.setCrs(QgsCoordinateReferenceSystem('EPSG:32633')) map.attemptSetSceneRect(QRectF(20, 20, 200, 100)) map.setFrameEnabled(True) map.setBackgroundColor(QColor(150, 100, 100)) layout.addLayoutItem(map) self.assertFalse(map.grids().hasEnabledItems()) """Test that we can create a grid for a map.""" myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125) map.setExtent(myRectangle) map.grid().setEnabled(True) self.assertTrue(map.grids().hasEnabledItems()) map.grid().setIntervalX(2000) map.grid().setIntervalY(2000) map.grid().setAnnotationEnabled(True) map.grid().setGridLineColor(QColor(0, 255, 0)) map.grid().setGridLineWidth(0.5) format = QgsTextFormat.fromQFont(getTestFont('Bold')) format.setColor(QColor(255, 0, 0)) format.setOpacity(150 / 255) map.grid().setAnnotationTextFormat(format) map.grid().setAnnotationPrecision(0) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Left) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Top) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Bottom) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Bottom) map.grid().setBlendMode(QPainter.CompositionMode_Overlay) map.updateBoundingRect() checker = QgsLayoutChecker('composermap_grid', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() map.grid().setEnabled(False) map.grid().setAnnotationEnabled(False) assert myTestResult, myMessage
def test_read_write(self): plot = Qgs2DPlot() plot.setSize(QSizeF(600, 500)) sym1 = QgsFillSymbol.createSimple({ 'color': '#fdbf6f', 'outline_style': 'no' }) plot.setChartBackgroundSymbol(sym1) sym2 = QgsFillSymbol.createSimple({ 'outline_color': '#0000ff', 'style': 'no', 'outline_style': 'solid', 'outline_width': 1 }) plot.setChartBorderSymbol(sym2) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#00ffff', 'outline_width': 1 }) plot.xAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff00ff', 'outline_width': 0.5 }) plot.xAxis().setGridMinorSymbol(sym4) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#0066ff', 'outline_width': 1 }) plot.yAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff4433', 'outline_width': 0.5 }) plot.yAxis().setGridMinorSymbol(sym4) font = QgsFontUtils.getStandardTestFont('Bold', 16) x_axis_format = QgsTextFormat.fromQFont(font) x_axis_format.setColor(QColor(255, 0, 0)) plot.xAxis().setTextFormat(x_axis_format) x_axis_number_format = QgsBasicNumericFormat() x_axis_number_format.setNumberDecimalPlaces(1) x_axis_number_format.setShowTrailingZeros(True) plot.xAxis().setNumericFormat(x_axis_number_format) font = QgsFontUtils.getStandardTestFont('Bold', 18) y_axis_format = QgsTextFormat.fromQFont(font) y_axis_format.setColor(QColor(0, 255, 0)) plot.yAxis().setTextFormat(y_axis_format) y_axis_number_format = QgsBasicNumericFormat() y_axis_number_format.setShowPlusSign(True) plot.yAxis().setNumericFormat(y_axis_number_format) plot.setXMinimum(3) plot.setXMaximum(9) plot.setYMinimum(2) plot.setYMaximum(12) plot.xAxis().setGridIntervalMinor(0.5) plot.xAxis().setGridIntervalMajor(1.5) plot.yAxis().setGridIntervalMinor(0.3) plot.yAxis().setGridIntervalMajor(1.3) plot.xAxis().setLabelInterval(32) plot.yAxis().setLabelInterval(23) doc = QDomDocument() elem = doc.createElement('test') plot.writeXml(elem, doc, QgsReadWriteContext()) res = Qgs2DPlot() self.assertTrue(res.readXml(elem, QgsReadWriteContext())) self.assertEqual(res.xMinimum(), 3) self.assertEqual(res.xMaximum(), 9) self.assertEqual(res.yMinimum(), 2) self.assertEqual(res.yMaximum(), 12) self.assertEqual(res.xAxis().gridIntervalMinor(), 0.5) self.assertEqual(res.xAxis().gridIntervalMajor(), 1.5) self.assertEqual(res.yAxis().gridIntervalMinor(), 0.3) self.assertEqual(res.yAxis().gridIntervalMajor(), 1.3) self.assertEqual(res.xAxis().labelInterval(), 32) self.assertEqual(res.yAxis().labelInterval(), 23) self.assertEqual(res.xAxis().numericFormat().numberDecimalPlaces(), 1) self.assertTrue(res.yAxis().numericFormat().showPlusSign()) self.assertEqual(res.xAxis().textFormat().color().name(), '#ff0000') self.assertEqual(res.yAxis().textFormat().color().name(), '#00ff00') self.assertEqual(res.chartBackgroundSymbol().color().name(), '#fdbf6f') self.assertEqual(res.chartBorderSymbol().color().name(), '#0000ff') self.assertEqual(res.xAxis().gridMinorSymbol().color().name(), '#ff00ff') self.assertEqual(res.xAxis().gridMajorSymbol().color().name(), '#00ffff') self.assertEqual(res.yAxis().gridMinorSymbol().color().name(), '#ff4433') self.assertEqual(res.yAxis().gridMajorSymbol().color().name(), '#0066ff')
def testPlot(self): plot = Qgs2DPlot() plot.setSize(QSizeF(600, 500)) sym1 = QgsFillSymbol.createSimple({ 'color': '#fdbf6f', 'outline_style': 'no' }) plot.setChartBackgroundSymbol(sym1) sym2 = QgsFillSymbol.createSimple({ 'outline_color': '#0000ff', 'style': 'no', 'outline_style': 'solid', 'outline_width': 1 }) plot.setChartBorderSymbol(sym2) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#00ffff', 'outline_width': 1 }) plot.xAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff00ff', 'outline_width': 0.5 }) plot.xAxis().setGridMinorSymbol(sym4) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#0066ff', 'outline_width': 1 }) plot.yAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff4433', 'outline_width': 0.5 }) plot.yAxis().setGridMinorSymbol(sym4) font = QgsFontUtils.getStandardTestFont('Bold', 16) x_axis_format = QgsTextFormat.fromQFont(font) x_axis_format.setColor(QColor(255, 0, 0)) plot.xAxis().setTextFormat(x_axis_format) x_axis_number_format = QgsBasicNumericFormat() x_axis_number_format.setNumberDecimalPlaces(1) x_axis_number_format.setShowTrailingZeros(True) plot.xAxis().setNumericFormat(x_axis_number_format) font = QgsFontUtils.getStandardTestFont('Bold', 18) y_axis_format = QgsTextFormat.fromQFont(font) y_axis_format.setColor(QColor(0, 255, 0)) plot.yAxis().setTextFormat(y_axis_format) y_axis_number_format = QgsBasicNumericFormat() y_axis_number_format.setShowPlusSign(True) plot.yAxis().setNumericFormat(y_axis_number_format) plot.setXMinimum(3) plot.setXMaximum(9) plot.setYMinimum(2) plot.setYMaximum(12) im = QImage(600, 500, QImage.Format_ARGB32) im.fill(Qt.white) im.setDotsPerMeterX(int(96 / 25.4 * 1000)) im.setDotsPerMeterY(int(96 / 25.4 * 1000)) painter = QPainter(im) rc = QgsRenderContext.fromQPainter(painter) plot.render(rc) painter.end() assert self.imageCheck('plot_2d_base', 'plot_2d_base', im) plot_rect = plot.interiorPlotArea(rc) self.assertAlmostEqual(plot_rect.left(), 64.8, 0) self.assertAlmostEqual(plot_rect.right(), 592.44, 0) self.assertAlmostEqual(plot_rect.top(), 7.559, 0) self.assertAlmostEqual(plot_rect.bottom(), 465.55, 0)
def testOptimiseIntervals(self): plot = Qgs2DPlot() plot.setSize(QSizeF(600, 500)) font = QgsFontUtils.getStandardTestFont('Bold', 16) x_axis_format = QgsTextFormat.fromQFont(font) plot.xAxis().setTextFormat(x_axis_format) font = QgsFontUtils.getStandardTestFont('Bold', 18) y_axis_format = QgsTextFormat.fromQFont(font) plot.yAxis().setTextFormat(y_axis_format) plot.setXMinimum(3) plot.setXMaximum(13) plot.setYMinimum(2) plot.setYMaximum(12) im = QImage(600, 500, QImage.Format_ARGB32) im.fill(Qt.white) im.setDotsPerMeterX(int(96 / 25.4 * 1000)) im.setDotsPerMeterY(int(96 / 25.4 * 1000)) painter = QPainter(im) rc = QgsRenderContext.fromQPainter(painter) painter.end() plot.calculateOptimisedIntervals(rc) self.assertEqual(plot.xAxis().labelInterval(), 1) self.assertEqual(plot.yAxis().labelInterval(), 2) self.assertEqual(plot.xAxis().gridIntervalMinor(), 1) self.assertEqual(plot.yAxis().gridIntervalMinor(), 1) self.assertEqual(plot.xAxis().gridIntervalMajor(), 5) self.assertEqual(plot.yAxis().gridIntervalMajor(), 4) plot.setXMinimum(3) plot.setXMaximum(113) plot.setYMinimum(2) plot.setYMaximum(112) plot.calculateOptimisedIntervals(rc) self.assertEqual(plot.xAxis().labelInterval(), 20) self.assertEqual(plot.yAxis().labelInterval(), 20) self.assertEqual(plot.xAxis().gridIntervalMinor(), 10) self.assertEqual(plot.yAxis().gridIntervalMinor(), 10) self.assertEqual(plot.xAxis().gridIntervalMajor(), 40) self.assertEqual(plot.yAxis().gridIntervalMajor(), 40) plot.setXMinimum(0.3) plot.setXMaximum(0.5) plot.setYMinimum(1.1) plot.setYMaximum(2) plot.calculateOptimisedIntervals(rc) self.assertEqual(plot.xAxis().labelInterval(), 0.05) self.assertEqual(plot.yAxis().labelInterval(), 0.2) self.assertEqual(plot.xAxis().gridIntervalMinor(), 0.025) self.assertEqual(plot.yAxis().gridIntervalMinor(), 0.1) self.assertEqual(plot.xAxis().gridIntervalMajor(), 0.1) self.assertEqual(plot.yAxis().gridIntervalMajor(), 0.4) plot.setXMinimum(-10) plot.setXMaximum(0) plot.setYMinimum(-10000) plot.setYMaximum(-500) plot.calculateOptimisedIntervals(rc) self.assertEqual(plot.xAxis().labelInterval(), 2) self.assertEqual(plot.yAxis().labelInterval(), 2000) self.assertEqual(plot.xAxis().gridIntervalMinor(), 1) self.assertEqual(plot.yAxis().gridIntervalMinor(), 1000) self.assertEqual(plot.xAxis().gridIntervalMajor(), 4) self.assertEqual(plot.yAxis().gridIntervalMajor(), 4000) plot.setXMinimum(100000) plot.setXMaximum(200000) plot.calculateOptimisedIntervals(rc) self.assertEqual(plot.xAxis().labelInterval(), 100000) self.assertEqual(plot.xAxis().gridIntervalMinor(), 50000) self.assertEqual(plot.xAxis().gridIntervalMajor(), 200000)
def testPlotDataDefinedProperties(self): plot = Qgs2DPlot() plot.setSize(QSizeF(600, 500)) sym1 = QgsFillSymbol.createSimple({ 'color': '#ffffff', 'outline_style': 'no' }) plot.setChartBackgroundSymbol(sym1) sym2 = QgsFillSymbol.createSimple({ 'outline_color': '#000000', 'style': 'no', 'outline_style': 'solid', 'outline_width': 1 }) plot.setChartBorderSymbol(sym2) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#00ffff', 'outline_width': 1, 'capstyle': 'flat' }) sym3[0].setDataDefinedProperty( QgsSymbolLayer.PropertyStrokeWidth, QgsProperty.fromExpression( 'case when @plot_axis_value = 10 then 3 else 1 end')) plot.xAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff00ff', 'outline_width': 0.5, 'capstyle': 'flat' }) sym4[0].setDataDefinedProperty( QgsSymbolLayer.PropertyStrokeWidth, QgsProperty.fromExpression( 'case when @plot_axis_value = 6 then 3 else 0.5 end')) plot.xAxis().setGridMinorSymbol(sym4) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#0066ff', 'outline_width': 1, 'capstyle': 'flat' }) sym3[0].setDataDefinedProperty( QgsSymbolLayer.PropertyStrokeWidth, QgsProperty.fromExpression( 'case when @plot_axis_value = 5 then 3 else 0.5 end')) plot.yAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff4433', 'outline_width': 0.5, 'capstyle': 'flat' }) sym4[0].setDataDefinedProperty( QgsSymbolLayer.PropertyStrokeWidth, QgsProperty.fromExpression( 'case when @plot_axis_value = 9 then 3 else 0.5 end')) plot.yAxis().setGridMinorSymbol(sym4) font = QgsFontUtils.getStandardTestFont('Bold', 16) x_axis_format = QgsTextFormat.fromQFont(font) x_axis_format.dataDefinedProperties().setProperty( QgsPalLayerSettings.Color, QgsProperty.fromExpression( 'case when @plot_axis_value %3 = 0 then \'#ff0000\' else \'#000000\' end' )) plot.xAxis().setTextFormat(x_axis_format) font = QgsFontUtils.getStandardTestFont('Bold', 18) y_axis_format = QgsTextFormat.fromQFont(font) y_axis_format.dataDefinedProperties().setProperty( QgsPalLayerSettings.Color, QgsProperty.fromExpression( 'case when @plot_axis_value %4 = 0 then \'#0000ff\' else \'#000000\' end' )) plot.yAxis().setTextFormat(y_axis_format) plot.setXMinimum(3) plot.setXMaximum(13) plot.setYMinimum(2) plot.setYMaximum(12) im = QImage(600, 500, QImage.Format_ARGB32) im.fill(Qt.white) im.setDotsPerMeterX(int(96 / 25.4 * 1000)) im.setDotsPerMeterY(int(96 / 25.4 * 1000)) painter = QPainter(im) rc = QgsRenderContext.fromQPainter(painter) plot.render(rc) painter.end() assert self.imageCheck('plot_2d_data_defined', 'plot_2d_data_defined', im) plot_rect = plot.interiorPlotArea(rc) self.assertAlmostEqual(plot_rect.left(), 44.71, 0) self.assertAlmostEqual(plot_rect.right(), 592.44, 0) self.assertAlmostEqual(plot_rect.top(), 7.559, 0) self.assertAlmostEqual(plot_rect.bottom(), 465.55, 0)
def testPlotIntervals(self): plot = Qgs2DPlot() plot.setSize(QSizeF(600, 500)) sym1 = QgsFillSymbol.createSimple({ 'color': '#fdbf6f', 'outline_style': 'no' }) plot.setChartBackgroundSymbol(sym1) sym2 = QgsFillSymbol.createSimple({ 'outline_color': '#0000ff', 'style': 'no', 'outline_style': 'solid', 'outline_width': 1 }) plot.setChartBorderSymbol(sym2) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#00ffff', 'outline_width': 1 }) plot.xAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff00ff', 'outline_width': 0.5 }) plot.xAxis().setGridMinorSymbol(sym4) sym3 = QgsLineSymbol.createSimple({ 'outline_color': '#0066ff', 'outline_width': 1 }) plot.yAxis().setGridMajorSymbol(sym3) sym4 = QgsLineSymbol.createSimple({ 'outline_color': '#ff4433', 'outline_width': 0.5 }) plot.yAxis().setGridMinorSymbol(sym4) font = QgsFontUtils.getStandardTestFont('Bold', 16) x_axis_format = QgsTextFormat.fromQFont(font) plot.xAxis().setTextFormat(x_axis_format) font = QgsFontUtils.getStandardTestFont('Bold', 18) y_axis_format = QgsTextFormat.fromQFont(font) plot.yAxis().setTextFormat(y_axis_format) plot.setXMinimum(1) plot.setXMaximum(21) plot.setYMinimum(27) plot.setYMaximum(327) plot.xAxis().setGridIntervalMajor(10) plot.xAxis().setGridIntervalMinor(2) plot.yAxis().setGridIntervalMajor(100) plot.yAxis().setGridIntervalMinor(50) plot.xAxis().setLabelInterval(5) plot.yAxis().setLabelInterval(70) im = QImage(600, 500, QImage.Format_ARGB32) im.fill(Qt.white) im.setDotsPerMeterX(int(96 / 25.4 * 1000)) im.setDotsPerMeterY(int(96 / 25.4 * 1000)) painter = QPainter(im) rc = QgsRenderContext.fromQPainter(painter) plot.render(rc) painter.end() assert self.imageCheck('plot_2d_intervals', 'plot_2d_intervals', im)
def testDynamicInterval(self): layout = QgsLayout(QgsProject.instance()) layout.initializeDefaults() map = QgsLayoutItemMap(layout) map.attemptSetSceneRect(QRectF(20, 20, 200, 100)) map.setFrameEnabled(True) map.setBackgroundColor(QColor(150, 100, 100)) layout.addLayoutItem(map) myRectangle = QgsRectangle(781662.375, 3339523.125, 793062.375, 3345223.125) map.setExtent(myRectangle) map.grid().setEnabled(True) map.grid().setUnits(QgsLayoutItemMapGrid.DynamicPageSizeBased) map.grid().setMinimumIntervalWidth(50) map.grid().setMaximumIntervalWidth(100) map.grid().setAnnotationEnabled(True) map.grid().setGridLineColor(QColor(0, 255, 0)) map.grid().setGridLineWidth(0.5) format = QgsTextFormat.fromQFont(getTestFont('Bold', 20)) format.setColor(QColor(255, 0, 0)) format.setOpacity(150 / 255) map.grid().setAnnotationTextFormat(format) map.grid().setAnnotationPrecision(0) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Left) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDisplay(QgsLayoutItemMapGrid.HideAll, QgsLayoutItemMapGrid.Top) map.grid().setAnnotationPosition(QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.Bottom) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Right) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Bottom) map.grid().setBlendMode(QPainter.CompositionMode_Overlay) map.updateBoundingRect() map.grid().refresh() checker = QgsLayoutChecker('composermap_dynamic_5_10', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage) map.setScale(map.scale() * 1.1) checker = QgsLayoutChecker('composermap_dynamic_5_10_2', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage) map.setScale(map.scale() * 1.8) checker = QgsLayoutChecker('composermap_dynamic_5_10_3', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage) map.grid().setMinimumIntervalWidth(10) map.grid().setMaximumIntervalWidth(40) map.grid().refresh() checker = QgsLayoutChecker('composermap_dynamic_5_10_4', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage)
def testDataDefinedTicksAndAnnotationDisplay(self): layout = QgsLayout(QgsProject.instance()) layout.initializeDefaults() map = QgsLayoutItemMap(layout) map.attemptSetSceneRect(QRectF(40, 20, 200, 100)) map.setFrameEnabled(True) map.setBackgroundColor(QColor(150, 100, 100)) layout.addLayoutItem(map) myRectangle = QgsRectangle(0.5, -5.5, 10.5, 0.5) map.setExtent(myRectangle) map.setMapRotation(45) map.grid().setEnabled(True) map.grid().setIntervalX(1) map.grid().setIntervalY(1) map.grid().setAnnotationEnabled(True) map.grid().setGridLineColor(QColor(0, 255, 0)) map.grid().setGridLineWidth(0.5) map.grid().setFrameStyle(QgsLayoutItemMapGrid.ExteriorTicks) map.grid().setFrameWidth(4) map.grid().setFramePenSize(1) map.grid().setFramePenColor(QColor(0, 0, 255)) map.grid().setAnnotationFrameDistance(5) format = QgsTextFormat.fromQFont(getTestFont('Bold', 20)) format.setColor(QColor(255, 0, 0)) format.setOpacity(150 / 255) map.grid().setAnnotationTextFormat(format) map.grid().setAnnotationPrecision(0) map.grid().setRotatedTicksEnabled(True) map.grid().setRotatedAnnotationsEnabled(True) map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridAnnotationDisplayLeft, QgsProperty.fromValue("x_only")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridAnnotationDisplayRight, QgsProperty.fromValue("Y_ONLY")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridAnnotationDisplayTop, QgsProperty.fromValue("disabled")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridAnnotationDisplayBottom, QgsProperty.fromValue("ALL")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridFrameDivisionsLeft, QgsProperty.fromValue("X_ONLY")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridFrameDivisionsRight, QgsProperty.fromValue("y_only")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridFrameDivisionsTop, QgsProperty.fromValue("DISABLED")) map.grid().dataDefinedProperties().setProperty( QgsLayoutObject.MapGridFrameDivisionsBottom, QgsProperty.fromValue("all")) map.grid().refresh() checker = QgsLayoutChecker( 'composermap_datadefined_ticksandannotationdisplay', layout) checker.setControlPathPrefix("composer_mapgrid") myTestResult, myMessage = checker.testLayout() self.report += checker.report() self.assertTrue(myTestResult, myMessage)