Skip to content
Permalink
Browse files

[processing] Use QgsNewDatabaseTableNameWidget instead of custom

dialog when saving processing output direct to postgis
  • Loading branch information
nyalldawson committed Mar 15, 2020
1 parent 3966d3f commit 66d084f72dfc832f00bf0c188ed8fd918f9bc37b
Showing with 15 additions and 20 deletions.
  1. +15 −20 python/plugins/processing/gui/DestinationSelectionPanel.py
@@ -29,7 +29,10 @@
from qgis.PyQt.QtCore import QCoreApplication, QDir, pyqtSignal, QFileInfo
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog, QInputDialog
from qgis.PyQt.QtGui import QCursor
from qgis.gui import QgsEncodingSelectionDialog
from qgis.gui import (
QgsEncodingSelectionDialog,
QgsNewDatabaseTableNameDialog
)
from qgis.core import (QgsProcessing,
QgsDataSourceUri,
QgsCredentials,
@@ -43,6 +46,7 @@
QgsProcessingParameterVectorDestination)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.PostgisTableSelector import PostgisTableSelector
from qgis.utils import iface

pluginPath = os.path.split(os.path.dirname(__file__))[0]

@@ -169,31 +173,22 @@ def saveToTemporary(self):
self.destinationChanged.emit()

def saveToPostGIS(self):
dlg = PostgisTableSelector(self, self.parameter.name().lower())
dlg.exec_()
if dlg.connection:
dlg = QgsNewDatabaseTableNameDialog(iface.browserModel(), ['postgres'], self)
dlg.setWindowTitle(self.tr('Save to PostGIS Table'))
if dlg.exec_() and dlg.isValid():
self.use_temporary = False
settings = QgsSettings()
mySettings = '/PostgreSQL/connections/' + dlg.connection
dbname = settings.value(mySettings + '/database')
user = settings.value(mySettings + '/username')
host = settings.value(mySettings + '/host')
port = settings.value(mySettings + '/port')
password = settings.value(mySettings + '/password')
uri = QgsDataSourceUri()
uri.setConnection(host, str(port), dbname, user, password)
uri.setDataSource(dlg.schema, dlg.table,
"the_geom" if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)

connInfo = uri.connectionInfo()
(success, user, passwd) = QgsCredentials.instance().get(connInfo, None, None)
if success:
QgsCredentials.instance().put(connInfo, user, passwd)

uri = QgsDataSourceUri(dlg.uri())
uri.setGeometryColumn("geom" if isinstance(self.parameter,
QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)
self.leText.setText("postgis:" + uri.uri())

self.skipOutputChanged.emit(False)
self.destinationChanged.emit()

dlg.deleteLater()
del dlg

def saveToGeopackage(self):
file_filter = self.tr('GeoPackage files (*.gpkg);;All files (*.*)', 'OutputFile')

0 comments on commit 66d084f

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