Skip to content

Commit

Permalink
[Processing] Fix "Set style for raster/vector layer" algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
radosuav committed Jan 16, 2018
1 parent 4b1d98b commit 77a28dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 7 additions & 14 deletions python/plugins/processing/algs/qgis/SetRasterStyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import os

from qgis.PyQt.QtXml import QDomDocument

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterFile
from processing.core.parameters import ParameterRaster
Expand All @@ -54,19 +52,14 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(filename)

style = self.getParameterValue(self.STYLE)

dataobjects.resetLoadedLayers()
layer = dataobjects.getObjectFromUri(filename, False)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
dataobjects.load(filename, os.path.basename(filename), style=style, isRaster=True)
else:
with open(style) as f:
xml = "".join(f.readlines())
d = QDomDocument()
d.setContent(xml)
n = d.firstChild()
layer.readSymbology(n, '')
self.setOutputValue(self.OUTPUT, filename)
iface.mapCanvas().refresh()
layer.loadNamedStyle(style)
layer.triggerRepaint()
iface.legendInterface().refreshLayerSymbology(layer)
self.setOutputValue(self.OUTPUT, filename)
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/qgis/SetVectorStyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)

style = self.getParameterValue(self.STYLE)

dataobjects.resetLoadedLayers()
layer = dataobjects.getObjectFromUri(filename, False)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
else:
layer.loadNamedStyle(style)
iface.mapCanvas().refresh()
iface.legendInterface().refreshLayerSymbology(layer)
layer.triggerRepaint()
iface.legendInterface().refreshLayerSymbology(layer)
self.setOutputValue(self.OUTPUT, filename)

0 comments on commit 77a28dd

Please sign in to comment.