[dbmanager] allow to import GEOMETRY tables

UI is similar to the browser, where generic geometry tables
are display several times, one for each type.
This commit is contained in:
olivierdalang 2019-06-05 17:43:17 +02:00
parent b9d5cde53e
commit 86f8bdb0aa

View File

@ -31,7 +31,8 @@ from qgis.core import (
Qgis, Qgis,
QgsApplication, QgsApplication,
QgsSettings, QgsSettings,
QgsMapLayerType QgsMapLayerType,
QgsWkbTypes
) )
from ..db_plugins import createDbPlugin from ..db_plugins import createDbPlugin
@ -522,8 +523,28 @@ class Database(DbItemObject):
def tables(self, schema=None, sys_tables=False): def tables(self, schema=None, sys_tables=False):
tables = self.connector.getTables(schema.name if schema else None, sys_tables) tables = self.connector.getTables(schema.name if schema else None, sys_tables)
if tables is not None: if tables is not None:
tables = [self.tablesFactory(x, self, schema) for x in tables] ret = []
return tables for t in tables:
table = self.tablesFactory(t, self, schema)
ret.append(table)
# Similarly to what to browser does, if the geom type is generic geometry,
# we additionnly add three copies of the layer to allow importing
if isinstance(table, VectorTable):
if table.geomType == 'GEOMETRY':
point_table = self.tablesFactory(t, self, schema)
point_table.geomType = 'POINT'
ret.append(point_table)
line_table = self.tablesFactory(t, self, schema)
line_table.geomType = 'LINESTRING'
ret.append(line_table)
poly_table = self.tablesFactory(t, self, schema)
poly_table.geomType = 'POLYGON'
ret.append(poly_table)
return ret
def createTable(self, table, fields, schema=None): def createTable(self, table, fields, schema=None):
field_defs = [x.definition() for x in fields] field_defs = [x.definition() for x in fields]
@ -692,6 +713,13 @@ class Table(DbItemObject):
geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else "" geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "") uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
uri.setSrid(str(self.srid))
for f in self.fields():
if f.primaryKey:
uri.setKeyColumn(f.name)
break
uri.setWkbType(QgsWkbTypes.parseType(self.geomType))
return uri return uri
def mimeUri(self): def mimeUri(self):