Skip to content
Permalink
Browse files

[processing] use background color from the project settings in the ra…

…sterize algorithm (fix #19866)

(cherry picked from commit 8919d60)
  • Loading branch information
alexbruy authored and nyalldawson committed Jan 25, 2019
1 parent f8893d7 commit 42c7712b154b3cef28a78e1e4136d3d18843e2bd
Showing with 16 additions and 9 deletions.
  1. +16 −9 python/plugins/processing/algs/qgis/Rasterize.py
@@ -153,7 +153,10 @@ def groupId(self):
def tags(self):
return self.tr('layer,raster,convert,file,map themes,tiles,render').split(',')

# def processAlgorithm(self, progress):
def prepareAlgorithm(self, parameters, context, feedback):
self.mapSettings = qgis.utils.iface.mapCanvas().mapSettings()
return True

def processAlgorithm(self, parameters, context, feedback):
"""Here is where the processing itself takes place."""

@@ -194,9 +197,11 @@ def processAlgorithm(self, parameters, context, feedback):
self.OUTPUT,
context)

project = context.project()

tile_set = TileSet(map_theme, layer, extent, tile_size, mupp,
output_layer, make_trans,
qgis.utils.iface.mapCanvas().mapSettings())
self.mapSettings, project)
tile_set.render(feedback, make_trans)

return {self.OUTPUT: output_layer}
@@ -209,7 +214,7 @@ class TileSet():
"""

def __init__(self, map_theme, layer, extent, tile_size, mupp, output,
make_trans, map_settings):
make_trans, map_settings, project):
"""
:param map_theme:
:param extent:
@@ -260,10 +265,14 @@ def __init__(self, map_theme, layer, extent, tile_size, mupp, output,
self.settings.setFlag(QgsMapSettings.RenderMapTile, True)
self.settings.setFlag(QgsMapSettings.UseAdvancedEffects, True)

r = project.readNumEntry('Gui', '/CanvasColorRedPart', 255)[0]
g = project.readNumEntry('Gui', '/CanvasColorGreenPart', 255)[0]
b = project.readNumEntry('Gui', '/CanvasColorBluePart', 255)[0]
if make_trans:
self.settings.setBackgroundColor(QColor(255, 255, 255, 0))
self.bgColor = QColor(r, g, b, 0)
else:
self.settings.setBackgroundColor(QColor(255, 255, 255))
self.bgColor = QColor(r, g, b)
self.settings.setBackgroundColor(self.bgColor)

if QgsProject.instance().mapThemeCollection().hasMapTheme(map_theme):
self.settings.setLayers(
@@ -300,11 +309,9 @@ def renderTile(self, x, y, feedback, make_trans):
"""

if make_trans:
background_color = QColor(255, 255, 255, 0)
self.image.fill(background_color.rgba())
self.image.fill(self.bgColor.rgba())
else:
background_color = QColor(255, 255, 255)
self.image.fill(background_color.rgb())
self.image.fill(self.bgColor.rgb())

painter = QPainter(self.image)

0 comments on commit 42c7712

Please sign in to comment.
You can’t perform that action at this time.