Skip to content
Permalink
Browse files

Fix saving processing outputs with correct encoding

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 2b0af00 commit 5e92c0dbf43566d4137503e13d9ea1f44166d312
@@ -116,7 +116,9 @@ def getParamValues(self):
if self.mainWidget.checkBoxes[param.name()].isChecked():
dest_project = QgsProject.instance()

parameters[param.name()] = QgsProcessingFeatureSinkDefinition(self.mainWidget.outputWidgets[param.name()].getValue(), dest_project)
value = self.mainWidget.outputWidgets[param.name()].getValue()
value.destinationProject = dest_project
parameters[param.name()] = value

return parameters

@@ -37,7 +37,8 @@
from qgis.core import (QgsDataSourceUri,
QgsCredentials,
QgsSettings,
QgsProcessingOutputVectorLayer)
QgsProcessingOutputVectorLayer,
QgsProcessingFeatureSinkDefinition)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.outputs import OutputVector
from processing.core.outputs import OutputDirectory
@@ -62,6 +63,8 @@ def __init__(self, parameter, alg):

self.parameter = parameter
self.alg = alg
settings = QgsSettings()
self.encoding = settings.value('/Processing/encoding', 'System')

if hasattr(self.leText, 'setPlaceholderText'):
if isinstance(self.parameter, QgsProcessingOutputVectorLayer) \
@@ -159,17 +162,15 @@ def saveToSpatialite(self):
else:
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)

encoding = settings.value('/Processing/encoding', 'System')
fileDialog = QgsEncodingFileDialog(
self, self.tr('Save Spatialite'), path, fileFilter, encoding)
self, self.tr('Save Spatialite'), path, fileFilter, self.encoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setOption(QFileDialog.DontConfirmOverwrite, True)

if fileDialog.exec_() == QDialog.Accepted:
files = fileDialog.selectedFiles()
encoding = str(fileDialog.encoding())
self.parameter.encoding = encoding
self.encoding = str(fileDialog.encoding())
fileName = str(files[0])
selectedFileFilter = str(fileDialog.selectedNameFilter())
if not fileName.lower().endswith(
@@ -179,7 +180,7 @@ def saveToSpatialite(self):
fileName += ext.group(1)
settings.setValue('/Processing/LastOutputPath',
os.path.dirname(fileName))
settings.setValue('/Processing/encoding', encoding)
settings.setValue('/Processing/encoding', self.encoding)

uri = QgsDataSourceUri()
uri.setDatabase(fileName)
@@ -196,17 +197,15 @@ def selectFile(self):
else:
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)

encoding = settings.value('/Processing/encoding', 'System')
fileDialog = QgsEncodingFileDialog(
self, self.tr('Save file'), path, fileFilter, encoding)
self, self.tr('Save file'), path, fileFilter, self.encoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setOption(QFileDialog.DontConfirmOverwrite, False)

if fileDialog.exec_() == QDialog.Accepted:
files = fileDialog.selectedFiles()
encoding = str(fileDialog.encoding())
self.parameter.encoding = encoding
self.encoding = str(fileDialog.encoding())
fileName = str(files[0])
selectedFileFilter = str(fileDialog.selectedNameFilter())
if not fileName.lower().endswith(
@@ -217,7 +216,7 @@ def selectFile(self):
self.leText.setText(fileName)
settings.setValue('/Processing/LastOutputPath',
os.path.dirname(fileName))
settings.setValue('/Processing/encoding', encoding)
settings.setValue('/Processing/encoding', self.encoding)

def selectDirectory(self):
lastDir = ''
@@ -226,6 +225,11 @@ def selectDirectory(self):
self.leText.setText(dirName)

def getValue(self):
key = None
if not self.leText.text():
return 'memory:'
return self.leText.text()
key = 'memory:'
else:
key = self.leText.text()
value = QgsProcessingFeatureSinkDefinition(key)
value.createOptions = {'fileEncoding': self.encoding}
return value

0 comments on commit 5e92c0d

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