|
31 | 31 |
|
32 | 32 | from qgis.PyQt import uic |
33 | 33 | from qgis.PyQt.QtCore import QCoreApplication, QDir |
34 | | -from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog |
| 34 | +from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog, QInputDialog |
35 | 35 | from qgis.PyQt.QtGui import QCursor |
36 | 36 | from qgis.gui import QgsEncodingSelectionDialog |
37 | 37 | from qgis.core import (QgsDataSourceUri, |
@@ -125,10 +125,10 @@ def selectOutput(self): |
125 | 125 |
|
126 | 126 | if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \ |
127 | 127 | and self.alg.provider().supportsNonFileBasedOutput(): |
128 | | - actionSaveToSpatialite = QAction( |
129 | | - self.tr('Save to SpatiaLite table...'), self.btnSelect) |
130 | | - actionSaveToSpatialite.triggered.connect(self.saveToSpatialite) |
131 | | - popupMenu.addAction(actionSaveToSpatialite) |
| 128 | + actionSaveToGpkg = QAction( |
| 129 | + self.tr('Save to GeoPackage...'), self.btnSelect) |
| 130 | + actionSaveToGpkg.triggered.connect(self.saveToGeopackage) |
| 131 | + popupMenu.addAction(actionSaveToGpkg) |
132 | 132 | actionSaveToPostGIS = QAction( |
133 | 133 | self.tr('Save to PostGIS table...'), self.btnSelect) |
134 | 134 | actionSaveToPostGIS.triggered.connect(self.saveToPostGIS) |
@@ -177,30 +177,34 @@ def saveToPostGIS(self): |
177 | 177 | QgsCredentials.instance().put(connInfo, user, passwd) |
178 | 178 | self.leText.setText("postgis:" + uri.uri()) |
179 | 179 |
|
180 | | - def saveToSpatialite(self): |
181 | | - file_filter = self.tr('SpatiaLite files (*.sqlite)', 'OutputFile') |
| 180 | + def saveToGeopackage(self): |
| 181 | + file_filter = self.tr('GeoPackage files (*.gpkg);;All files (*.*)', '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 | | - filename, filter = QFileDialog.getSaveFileName(self, self.tr("Save file"), path, |
| 189 | + filename, filter = QFileDialog.getSaveFileName(self, self.tr("Save to GeoPackage"), path, |
190 | 190 | file_filter, options=QFileDialog.DontConfirmOverwrite) |
191 | 191 |
|
192 | | - if filename is not None: |
| 192 | + if filename is None: |
| 193 | + return |
| 194 | + |
| 195 | + layer_name, ok = QInputDialog.getText(self, self.tr('Save to GeoPackage'), self.tr('Layer name'), text=self.parameter.name().lower()) |
| 196 | + if ok: |
193 | 197 | self.use_temporary = False |
194 | | - if not filename.lower().endswith('.sqlite'): |
195 | | - filename += '.sqlite' |
| 198 | + if not filename.lower().endswith('.gpkg'): |
| 199 | + filename += '.gpkg' |
196 | 200 | settings.setValue('/Processing/LastOutputPath', |
197 | 201 | os.path.dirname(filename)) |
198 | 202 |
|
199 | 203 | uri = QgsDataSourceUri() |
200 | 204 | uri.setDatabase(filename) |
201 | | - uri.setDataSource('', self.parameter.name().lower(), |
202 | | - 'the_geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None) |
203 | | - self.leText.setText("spatialite:" + uri.uri()) |
| 205 | + uri.setDataSource('', layer_name, |
| 206 | + 'geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None) |
| 207 | + self.leText.setText("ogr:" + uri.uri()) |
204 | 208 |
|
205 | 209 | def selectFile(self): |
206 | 210 | file_filter = getFileFilter(self.parameter) |
|
0 commit comments