Skip to content
Permalink
Browse files

[processing] Use proper database schema/table name widgets in algorithms

  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent 7b1975b commit 83d2a816fb6ba22ba5da195fbfd2ca50621fe1fa
@@ -29,7 +29,9 @@
QgsProcessingParameterField,
QgsProcessingParameterExtent,
QgsProcessingParameterBoolean,
QgsProcessingParameterProviderConnection)
QgsProcessingParameterProviderConnection,
QgsProcessingParameterDatabaseSchema,
QgsProcessingParameterDatabaseTable)

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
@@ -101,22 +103,15 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterCrs(self.S_SRS,
self.tr('Override source CRS'), defaultValue='', optional=True))

schema_param = QgsProcessingParameterString(
schema_param = QgsProcessingParameterDatabaseSchema(
self.SCHEMA,
self.tr('Schema (schema name)'), 'public', False, True)
schema_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
'connection_param': self.DATABASE}})
self.tr('Schema (schema name)'), defaultValue='public', connectionParameterName=self.DATABASE, optional=True)
self.addParameter(schema_param)

table_param = QgsProcessingParameterString(
table_param = QgsProcessingParameterDatabaseTable(
self.TABLE,
self.tr('Table to import to (leave blank to use layer name)'), '', False, True)
table_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.TableWidgetWrapper',
'schema_param': self.SCHEMA}})
self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE,
schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True)
self.addParameter(table_param)

self.addParameter(QgsProcessingParameterString(self.PK,
@@ -211,8 +206,8 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
ssrs = self.parameterAsCrs(parameters, self.S_SRS, context)
tsrs = self.parameterAsCrs(parameters, self.T_SRS, context)
asrs = self.parameterAsCrs(parameters, self.A_SRS, context)
table = self.parameterAsString(parameters, self.TABLE, context)
schema = self.parameterAsString(parameters, self.SCHEMA, context)
table = self.parameterAsDatabaseTableName(parameters, self.TABLE, context)
schema = self.parameterAsSchema(parameters, self.SCHEMA, context)
pk = self.parameterAsString(parameters, self.PK, context)
pkstring = "-lco FID=" + pk
primary_key = self.parameterAsString(parameters, self.PRIMARY_KEY, context)
@@ -31,6 +31,8 @@
QgsProcessingParameterField,
QgsProcessingParameterBoolean,
QgsProcessingParameterProviderConnection,
QgsProcessingParameterDatabaseSchema,
QgsProcessingParameterDatabaseTable,
QgsWkbTypes)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -71,22 +73,15 @@ def initAlgorithm(self, config=None):
)
self.addParameter(db_param)

schema_param = QgsProcessingParameterString(
schema_param = QgsProcessingParameterDatabaseSchema(
self.SCHEMA,
self.tr('Schema (schema name)'), 'public', False, True)
schema_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.SchemaWidgetWrapper',
'connection_param': self.DATABASE}})
self.tr('Schema (schema name)'), connectionParameterName=self.DATABASE, defaultValue='public', optional=True)
self.addParameter(schema_param)

table_param = QgsProcessingParameterString(
table_param = QgsProcessingParameterDatabaseTable(
self.TABLENAME,
self.tr('Table to import to (leave blank to use layer name)'), '', False, True)
table_param.setMetadata({
'widget_wrapper': {
'class': 'processing.gui.wrappers_postgis.TableWidgetWrapper',
'schema_param': self.SCHEMA}})
self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE,
schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True)
self.addParameter(table_param)

self.addParameter(QgsProcessingParameterField(self.PRIMARY_KEY,
@@ -125,7 +120,7 @@ def processAlgorithm(self, parameters, context, feedback):
connection = self.parameterAsConnectionName(parameters, self.DATABASE, context)
db = postgis.GeoDB.from_name(connection)

schema = self.parameterAsString(parameters, self.SCHEMA, context)
schema = self.parameterAsSchema(parameters, self.SCHEMA, context)
overwrite = self.parameterAsBoolean(parameters, self.OVERWRITE, context)
createIndex = self.parameterAsBoolean(parameters, self.CREATEINDEX, context)
convertLowerCase = self.parameterAsBoolean(parameters, self.LOWERCASE_NAMES, context)
@@ -138,7 +133,7 @@ def processAlgorithm(self, parameters, context, feedback):
if source is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))

table = self.parameterAsString(parameters, self.TABLENAME, context)
table = self.parameterAsDatabaseTableName(parameters, self.TABLENAME, context)
if table:
table.strip()
if not table or table == '':

0 comments on commit 83d2a81

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