Skip to content
Permalink
Browse files

add encoding support for output vector

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@350 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
alexander.bruy@gmail.com
alexander.bruy@gmail.com committed Aug 17, 2012
1 parent d67298a commit 76129e7fced76e759bbb32a336878eaf888cd697
Showing with 27 additions and 19 deletions.
  1. +26 −16 src/sextante/gui/OutputSelectionPanel.py
  2. +1 −3 src/sextante/outputs/OutputVector.py
@@ -1,11 +1,13 @@
from PyQt4 import QtGui, QtCore
import os.path

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import os.path
from sextante.core.SextanteConfig import SextanteConfig

from qgis.gui import *

from sextante.core.SextanteConfig import SextanteConfig

class OutputSelectionPanel(QtGui.QWidget):
class OutputSelectionPanel(QWidget):

lastOutputFolder = None
SAVE_TO_TEMP_FILE = "[Save to temporary file]"
@@ -14,34 +16,34 @@ def __init__(self, output, alg):
self.output = output
self.alg = alg
super(OutputSelectionPanel, self).__init__(None)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout = QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.text = QtGui.QLineEdit()
self.text = QLineEdit()
if hasattr(self.text, 'setPlaceholderText'):
self.text.setPlaceholderText(OutputSelectionPanel.SAVE_TO_TEMP_FILE)
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton = QPushButton()
self.pushButton.setText("...")
self.pushButton.clicked.connect(self.buttonPushed)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)

def buttonPushed(self):
popupmenu = QMenu()
saveToTemporaryFileAction = QtGui.QAction("Save to a temporary file", self.pushButton)
saveToTemporaryFileAction = QAction("Save to a temporary file", self.pushButton)
saveToTemporaryFileAction.triggered.connect(self.saveToTemporaryFile)
popupmenu.addAction(saveToTemporaryFileAction )
if (self.alg.provider.supportsNonFileBasedOutput()):
saveToMemoryAction= QtGui.QAction("Save to a memory layer...", self.pushButton)
saveToMemoryAction= QAction("Save to a memory layer...", self.pushButton)
saveToMemoryAction.triggered.connect(self.saveToMemory)
popupmenu.addAction(saveToMemoryAction)
saveToFileAction = QtGui.QAction("Save to file...", self.pushButton)
saveToFileAction = QAction("Save to file...", self.pushButton)
saveToFileAction.triggered.connect(self.saveToFile)
popupmenu.addAction(saveToFileAction)

popupmenu.exec_(QtGui.QCursor.pos())
popupmenu.exec_(QCursor.pos())

def saveToTemporaryFile(self):
self.text.setText("")
@@ -51,15 +53,23 @@ def saveToMemory(self):

def saveToFile(self):
filefilter = self.output.getFileFilter(self.alg)
settings = QtCore.QSettings()
settings = QSettings()
if settings.contains("/SextanteQGIS/LastOutputPath"):
path = str(settings.value( "/SextanteQGIS/LastOutputPath", QtCore.QVariant( "" ) ).toString())
path = str(settings.value( "/SextanteQGIS/LastOutputPath", QVariant( "" ) ).toString())
else:
path = SextanteConfig.getSetting(SextanteConfig.OUTPUT_FOLDER)
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", QtCore.QString(path), filefilter)
if filename:
lastEncoding = settings.value("/SextanteQGIS/encoding", "System").toString()
fileDialog = QgsEncodingFileDialog(self, "Save file", QString(path), filefilter, lastEncoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setConfirmOverwrite(True)
if fileDialog.exec_() == QDialog.Accepted:
filename = fileDialog.selectedFiles().first()
encoding = fileDialog.encoding()
self.output.encoding = encoding
self.text.setText(str(filename))
settings.setValue("/SextanteQGIS/LastOutputPath", os.path.dirname(str(filename)))
settings.setValue("/SextanteQGIS/encoding", encoding)

def getValue(self):
filename = str(self.text.text())
@@ -33,8 +33,6 @@ def getVectorWriter(self, fields, geomType, crs, options=None):
@return writer instance of the vectoe writer class
'''

settings = QSettings()
encoding = settings.value( "/UI/encoding", "System" ).toString()
w = SextanteVectorWriter(self.value, encoding, fields, geomType, crs, options)
w = SextanteVectorWriter(self.value, self.encoding, fields, geomType, crs, options)
self.memoryLayer = w.memLayer
return w

0 comments on commit 76129e7

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