mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Merge pull request #6255 from slarosa/fix_16476
[dbmanager] porting of dae921c to 3: fixes #16476
This commit is contained in:
commit
6f09f1745a
@ -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
|
||||
|
@ -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:
|
||||
QgsProject.instance().removeMapLayers([self.currentLayer.id()])
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user