Merge pull request #6255 from slarosa/fix_16476

[dbmanager] porting of dae921c to 3: fixes #16476
This commit is contained in:
Luigi Pirelli 2018-02-03 13:18:15 +01:00 committed by GitHub
commit 6f09f1745a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -96,6 +96,9 @@ class VLayerRegistry(object):
lid = self.layers.get(l)
if lid is None:
return lid
if lid not in QgsProject.instance().mapLayers().keys():
self.layers.pop(l)
return None
return QgsProject.instance().mapLayer(lid)
@ -249,12 +252,16 @@ class VLayerConnector(DBConnector):
def getTableRowCount(self, table):
t = table[1]
l = VLayerRegistry.instance().getLayer(t)
if not l or not l.isValid():
return None
return l.featureCount()
def getTableFields(self, table):
""" return list of columns in table """
t = table[1]
l = VLayerRegistry.instance().getLayer(t)
if not l or not l.isValid():
return []
# id, name, type, nonnull, default, pk
n = l.dataProvider().fields().size()
f = [(i, f.name(), f.typeName(), False, None, False)
@ -280,6 +287,8 @@ class VLayerConnector(DBConnector):
l = QgsProject.instance().mapLayer(t)
else:
l = VLayerRegistry.instance().getLayer(t)
if not l or not l.isValid():
return None
e = l.extent()
r = (e.xMinimum(), e.yMinimum(), e.xMaximum(), e.yMaximum())
return r

View File

@ -113,15 +113,16 @@ class LayerPreview(QgsMapCanvas):
else:
vl = table.toMapLayer()
if not vl.isValid():
if vl and not vl.isValid():
vl.deleteLater()
vl = None
# remove old layer (if any) and set new
if self.currentLayer:
if not QgsProject.instance().layerTreeRoot().findLayer(self.currentLayer.id()):
QgsProject.instance().removeMapLayers([self.currentLayer.id()])
if vl:
if vl and vl.isValid():
self.setLayers([vl])
QgsProject.instance().addMapLayers([vl], False)
self.zoomToFullExtent()