Skip to content

Commit

Permalink
[processing] use background color from the project settings in the ra…
Browse files Browse the repository at this point in the history
…sterize algorithm (fix #19866)

(cherry picked from commit 8919d60)
  • Loading branch information
alexbruy authored and nyalldawson committed Jan 25, 2019
1 parent f8893d7 commit 42c7712
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions python/plugins/processing/algs/qgis/Rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 42c7712

Please sign in to comment.