33
33
from qgis .PyQt .QtCore import QCoreApplication , QDir
34
34
from qgis .PyQt .QtWidgets import QDialog , QMenu , QAction , QFileDialog
35
35
from qgis .PyQt .QtGui import QCursor
36
- from qgis .gui import QgsEncodingFileDialog , QgsEncodingSelectionDialog
36
+ from qgis .gui import QgsEncodingSelectionDialog
37
37
from qgis .core import (QgsDataSourceUri ,
38
38
QgsCredentials ,
39
39
QgsExpression ,
@@ -123,11 +123,6 @@ def selectOutput(self):
123
123
actionSaveToFile .triggered .connect (self .selectFile )
124
124
popupMenu .addAction (actionSaveToFile )
125
125
126
- actionSetEncoding = QAction (
127
- self .tr ('Change file encoding ({})...' ).format (self .encoding ), self .btnSelect )
128
- actionSetEncoding .triggered .connect (self .selectEncoding )
129
- popupMenu .addAction (actionSetEncoding )
130
-
131
126
if isinstance (self .parameter , QgsProcessingParameterFeatureSink ) \
132
127
and self .alg .provider ().supportsNonFileBasedOutput ():
133
128
actionSaveToSpatialite = QAction (
@@ -144,6 +139,11 @@ def selectOutput(self):
144
139
actionSaveToPostGIS .setEnabled (bool (names ))
145
140
popupMenu .addAction (actionSaveToPostGIS )
146
141
142
+ actionSetEncoding = QAction (
143
+ self .tr ('Change file encoding ({})...' ).format (self .encoding ), self .btnSelect )
144
+ actionSetEncoding .triggered .connect (self .selectEncoding )
145
+ popupMenu .addAction (actionSetEncoding )
146
+
147
147
popupMenu .exec_ (QCursor .pos ())
148
148
149
149
def saveToTemporary (self ):
@@ -178,37 +178,26 @@ def saveToPostGIS(self):
178
178
self .leText .setText ("postgis:" + uri .uri ())
179
179
180
180
def saveToSpatialite (self ):
181
- fileFilter = self .tr ('SpatiaLite files (*.sqlite)' , 'OutputFile' )
181
+ file_filter = self .tr ('SpatiaLite files (*.sqlite)' , 'OutputFile' )
182
182
183
183
settings = QgsSettings ()
184
184
if settings .contains ('/Processing/LastOutputPath' ):
185
185
path = settings .value ('/Processing/LastOutputPath' )
186
186
else :
187
187
path = ProcessingConfig .getSetting (ProcessingConfig .OUTPUT_FOLDER )
188
188
189
- fileDialog = QgsEncodingFileDialog (
190
- self , self .tr ('Save SpatiaLite' ), path , fileFilter , self .encoding )
191
- fileDialog .setFileMode (QFileDialog .AnyFile )
192
- fileDialog .setAcceptMode (QFileDialog .AcceptSave )
193
- fileDialog .setOption (QFileDialog .DontConfirmOverwrite , True )
189
+ filename , filter = QFileDialog .getSaveFileName (self , self .tr ("Save file" ), path ,
190
+ file_filter , options = QFileDialog .DontConfirmOverwrite )
194
191
195
- if fileDialog . exec_ () == QDialog . Accepted :
192
+ if filename is not None :
196
193
self .use_temporary = False
197
- files = fileDialog .selectedFiles ()
198
- self .encoding = str (fileDialog .encoding ())
199
- fileName = str (files [0 ])
200
- selectedFileFilter = str (fileDialog .selectedNameFilter ())
201
- if not fileName .lower ().endswith (
202
- tuple (re .findall ("\\ *(\\ .[a-z]{1,10})" , fileFilter ))):
203
- ext = re .search ("\\ *(\\ .[a-z]{1,10})" , selectedFileFilter )
204
- if ext :
205
- fileName += ext .group (1 )
194
+ if not filename .lower ().endswith ('.sqlite' ):
195
+ filename += '.sqlite'
206
196
settings .setValue ('/Processing/LastOutputPath' ,
207
- os .path .dirname (fileName ))
208
- settings .setValue ('/Processing/encoding' , self .encoding )
197
+ os .path .dirname (filename ))
209
198
210
199
uri = QgsDataSourceUri ()
211
- uri .setDatabase (fileName )
200
+ uri .setDatabase (filename )
212
201
uri .setDataSource ('' , self .parameter .name ().lower (),
213
202
'the_geom' if isinstance (self .parameter , QgsProcessingParameterFeatureSink ) and self .parameter .hasGeometry () else None )
214
203
self .leText .setText ("spatialite:" + uri .uri ())
0 commit comments