Skip to content
Permalink
Browse files

Remove ad-hoc python provider connection parameters and replace

with proper provider connection parameters
  • Loading branch information
nyalldawson committed Mar 10, 2020
1 parent 6997c18 commit f587430d2305c0914394f880bb6f098ca06d6f44
@@ -28,7 +28,8 @@
QgsProcessingParameterCrs,
QgsProcessingParameterField,
QgsProcessingParameterExtent,
QgsProcessingParameterBoolean)
QgsProcessingParameterBoolean,
QgsProcessingParameterProviderConnection)

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
@@ -80,12 +81,9 @@ def __init__(self):

def initAlgorithm(self, config=None):

db_param = QgsProcessingParameterString(
db_param = QgsProcessingParameterProviderConnection(
self.DATABASE,
self.tr('Database (connection name)'))
db_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.tr('Database (connection name)'), 'postgres')
self.addParameter(db_param)
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer'),
@@ -202,7 +200,7 @@ def groupId(self):
return 'vectormiscellaneous'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
connection = self.parameterAsString(parameters, self.DATABASE, context)
connection = self.parameterAsConnectionName(parameters, self.DATABASE, context)
uri = uri_from_name(connection)
if executing:
# to get credentials input when needed
@@ -30,6 +30,7 @@
QgsProcessingParameterString,
QgsProcessingParameterField,
QgsProcessingParameterBoolean,
QgsProcessingParameterProviderConnection,
QgsWkbTypes)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -64,12 +65,10 @@ def initAlgorithm(self, config=None):
self.tr('Layer to import'),
types=[QgsProcessing.TypeVector]))

db_param = QgsProcessingParameterString(
db_param = QgsProcessingParameterProviderConnection(
self.DATABASE,
self.tr('Database (connection name)'))
db_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.tr('Database (connection name)'), 'postgres'
)
self.addParameter(db_param)

schema_param = QgsProcessingParameterString(
@@ -123,7 +122,7 @@ def tags(self):
return self.tr('import,postgis,table,layer,into,copy').split(',')

def processAlgorithm(self, parameters, context, feedback):
connection = self.parameterAsString(parameters, self.DATABASE, context)
connection = self.parameterAsConnectionName(parameters, self.DATABASE, context)
db = postgis.GeoDB.from_name(connection)

schema = self.parameterAsString(parameters, self.SCHEMA, context)
@@ -33,6 +33,7 @@
QgsProcessingException,
QgsProcessingOutputVectorLayer,
QgsProcessingContext,
QgsProcessingParameterProviderConnection,
QgsProcessingFeedback)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import postgis
@@ -56,12 +57,9 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
db_param = QgsProcessingParameterString(
db_param = QgsProcessingParameterProviderConnection(
self.DATABASE,
self.tr('Database (connection name)'))
db_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.tr('Database (connection name)'), 'postgres')
self.addParameter(db_param)
self.addParameter(QgsProcessingParameterString(
self.SQL,
@@ -94,7 +92,7 @@ def tags(self):
return self.tr('postgis,table,database').split(',')

def processAlgorithm(self, parameters, context, feedback):
connection = self.parameterAsString(parameters, self.DATABASE, context)
connection = self.parameterAsConnectionName(parameters, self.DATABASE, context)
id_field = self.parameterAsString(parameters, self.ID_FIELD, context)
geom_field = self.parameterAsString(
parameters, self.GEOMETRY_FIELD, context)
@@ -21,7 +21,11 @@
__date__ = 'October 2012'
__copyright__ = '(C) 2012, Victor Olaya, Carterix Geomatics'

from qgis.core import (QgsProcessingException, QgsProcessingParameterString)
from qgis.core import (
QgsProcessingException,
QgsProcessingParameterString,
QgsProcessingParameterProviderConnection
)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import postgis

@@ -41,12 +45,9 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
db_param = QgsProcessingParameterString(
db_param = QgsProcessingParameterProviderConnection(
self.DATABASE,
self.tr('Database (connection name)'))
db_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'}})
self.tr('Database (connection name)'), 'postgres')
self.addParameter(db_param)
self.addParameter(QgsProcessingParameterString(self.SQL, self.tr('SQL query'), multiLine=True))

@@ -63,7 +64,7 @@ def tags(self):
return self.tr('postgis,database').split(',')

def processAlgorithm(self, parameters, context, feedback):
connection = self.parameterAsString(parameters, self.DATABASE, context)
connection = self.parameterAsConnectionName(parameters, self.DATABASE, context)
db = postgis.GeoDB.from_name(connection)

sql = self.parameterAsString(parameters, self.SQL, context).replace('\n', ' ')
@@ -18,8 +18,7 @@
"""


from qgis.core import (QgsSettings,
QgsProcessingParameterNumber,
from qgis.core import (QgsProcessingParameterNumber,
QgsProcessingParameterFile,
QgsProcessingParameterField,
QgsProcessingParameterExpression,
@@ -35,39 +34,6 @@
from processing.tools.postgis import GeoDB


class ConnectionWidgetWrapper(WidgetWrapper):
"""
WidgetWrapper for ParameterString that create and manage a combobox widget
with existing postgis connections.
"""

def createWidget(self):
self._combo = QComboBox()
for group in self.items():
self._combo.addItem(*group)
self._combo.currentIndexChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return self._combo

def items(self):
settings = QgsSettings()
settings.beginGroup('/PostgreSQL/connections/')
items = [(group, group) for group in settings.childGroups()]

if self.dialogType == DIALOG_MODELER:
strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile,
QgsProcessingParameterField, QgsProcessingParameterExpression], QgsProcessingOutputString)
items = items + [(self.dialog.resolveValueDescription(s), s) for s in strings]

return items

def setValue(self, value):
self.setComboValue(value, self._combo)

def value(self):
return self.comboValue(combobox=self._combo)


class SchemaWidgetWrapper(WidgetWrapper):
"""
WidgetWrapper for ParameterString that create and manage a combobox widget

0 comments on commit f587430

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