Skip to content
Permalink
Browse files

Merge pull request #6255 from slarosa/fix_16476

[dbmanager] porting of dae921c to 3: fixes #16476
  • Loading branch information
luipir committed Feb 3, 2018
2 parents 639d310 + 68b7bf6 commit 6f09f1745a8ca9cd67be0fd40ca2a3d733f4d17c
@@ -96,6 +96,9 @@ def getLayer(self, l):
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 @@ def getRasterTables(self, schema=None):
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 @@ def getTableExtent(self, table, geom):
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 @@ def _loadTablePreview(self, table, limit=False):
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()

0 comments on commit 6f09f17

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