Skip to content
Permalink
Browse files

Use native file picker for spatialite export option also

  • Loading branch information
nyalldawson committed Nov 21, 2017
1 parent 31086d3 commit b97c6a8d88bd070a493d88b1472a3ae1a52bc932
Showing with 14 additions and 25 deletions.
  1. +14 −25 python/plugins/processing/gui/DestinationSelectionPanel.py
@@ -33,7 +33,7 @@
from qgis.PyQt.QtCore import QCoreApplication, QDir
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog
from qgis.PyQt.QtGui import QCursor
from qgis.gui import QgsEncodingFileDialog, QgsEncodingSelectionDialog
from qgis.gui import QgsEncodingSelectionDialog
from qgis.core import (QgsDataSourceUri,
QgsCredentials,
QgsExpression,
@@ -123,11 +123,6 @@ def selectOutput(self):
actionSaveToFile.triggered.connect(self.selectFile)
popupMenu.addAction(actionSaveToFile)

actionSetEncoding = QAction(
self.tr('Change file encoding ({})...').format(self.encoding), self.btnSelect)
actionSetEncoding.triggered.connect(self.selectEncoding)
popupMenu.addAction(actionSetEncoding)

if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
and self.alg.provider().supportsNonFileBasedOutput():
actionSaveToSpatialite = QAction(
@@ -144,6 +139,11 @@ def selectOutput(self):
actionSaveToPostGIS.setEnabled(bool(names))
popupMenu.addAction(actionSaveToPostGIS)

actionSetEncoding = QAction(
self.tr('Change file encoding ({})...').format(self.encoding), self.btnSelect)
actionSetEncoding.triggered.connect(self.selectEncoding)
popupMenu.addAction(actionSetEncoding)

popupMenu.exec_(QCursor.pos())

def saveToTemporary(self):
@@ -178,37 +178,26 @@ def saveToPostGIS(self):
self.leText.setText("postgis:" + uri.uri())

def saveToSpatialite(self):
fileFilter = self.tr('SpatiaLite files (*.sqlite)', 'OutputFile')
file_filter = self.tr('SpatiaLite files (*.sqlite)', 'OutputFile')

settings = QgsSettings()
if settings.contains('/Processing/LastOutputPath'):
path = settings.value('/Processing/LastOutputPath')
else:
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)

fileDialog = QgsEncodingFileDialog(
self, self.tr('Save SpatiaLite'), path, fileFilter, self.encoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setOption(QFileDialog.DontConfirmOverwrite, True)
filename, filter = QFileDialog.getSaveFileName(self, self.tr("Save file"), path,
file_filter, options=QFileDialog.DontConfirmOverwrite)

if fileDialog.exec_() == QDialog.Accepted:
if filename is not None:
self.use_temporary = False
files = fileDialog.selectedFiles()
self.encoding = str(fileDialog.encoding())
fileName = str(files[0])
selectedFileFilter = str(fileDialog.selectedNameFilter())
if not fileName.lower().endswith(
tuple(re.findall("\\*(\\.[a-z]{1,10})", fileFilter))):
ext = re.search("\\*(\\.[a-z]{1,10})", selectedFileFilter)
if ext:
fileName += ext.group(1)
if not filename.lower().endswith('.sqlite'):
filename += '.sqlite'
settings.setValue('/Processing/LastOutputPath',
os.path.dirname(fileName))
settings.setValue('/Processing/encoding', self.encoding)
os.path.dirname(filename))

uri = QgsDataSourceUri()
uri.setDatabase(fileName)
uri.setDatabase(filename)
uri.setDataSource('', self.parameter.name().lower(),
'the_geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)
self.leText.setText("spatialite:" + uri.uri())

0 comments on commit b97c6a8

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