|
27 | 27 | from qgis.PyQt.QtGui import QKeySequence, QIcon
|
28 | 28 |
|
29 | 29 | from qgis.gui import QgsMessageBar
|
30 |
| -from qgis.core import Qgis, QgsApplication, QgsSettings |
| 30 | +from qgis.core import ( |
| 31 | + Qgis, |
| 32 | + QgsApplication, |
| 33 | + QgsSettings, |
| 34 | + QgsWkbTypes |
| 35 | +) |
31 | 36 | from ..db_plugins import createDbPlugin
|
32 | 37 |
|
33 | 38 |
|
@@ -517,8 +522,28 @@ def rasterTablesFactory(self, row, db, schema=None):
|
517 | 522 | def tables(self, schema=None, sys_tables=False):
|
518 | 523 | tables = self.connector.getTables(schema.name if schema else None, sys_tables)
|
519 | 524 | if tables is not None:
|
520 |
| - tables = [self.tablesFactory(x, self, schema) for x in tables] |
521 |
| - return tables |
| 525 | + ret = [] |
| 526 | + for t in tables: |
| 527 | + table = self.tablesFactory(t, self, schema) |
| 528 | + ret.append(table) |
| 529 | + |
| 530 | + # Similarly to what to browser does, if the geom type is generic geometry, |
| 531 | + # we additionnly add three copies of the layer to allow importing |
| 532 | + if isinstance(table, VectorTable): |
| 533 | + if table.geomType == 'GEOMETRY': |
| 534 | + point_table = self.tablesFactory(t, self, schema) |
| 535 | + point_table.geomType = 'POINT' |
| 536 | + ret.append(point_table) |
| 537 | + |
| 538 | + line_table = self.tablesFactory(t, self, schema) |
| 539 | + line_table.geomType = 'LINESTRING' |
| 540 | + ret.append(line_table) |
| 541 | + |
| 542 | + poly_table = self.tablesFactory(t, self, schema) |
| 543 | + poly_table.geomType = 'POLYGON' |
| 544 | + ret.append(poly_table) |
| 545 | + |
| 546 | + return ret |
522 | 547 |
|
523 | 548 | def createTable(self, table, fields, schema=None):
|
524 | 549 | field_defs = [x.definition() for x in fields]
|
@@ -683,6 +708,13 @@ def uri(self):
|
683 | 708 | geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
|
684 | 709 | uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
|
685 | 710 | uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
|
| 711 | + uri.setSrid(str(self.srid)) |
| 712 | + for f in self.fields(): |
| 713 | + if f.primaryKey: |
| 714 | + uri.setKeyColumn(f.name) |
| 715 | + break |
| 716 | + uri.setWkbType(QgsWkbTypes.parseType(self.geomType)) |
| 717 | + |
686 | 718 | return uri
|
687 | 719 |
|
688 | 720 | def mimeUri(self):
|
|
0 commit comments