Skip to content

Commit

Permalink
Merge pull request #6255 from slarosa/fix_16476
Browse files Browse the repository at this point in the history
[dbmanager] porting of dae921c to 3: fixes #16476
  • Loading branch information
luipir committed Feb 3, 2018
2 parents 639d310 + 68b7bf6 commit 6f09f17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions python/plugins/db_manager/db_plugins/vlayers/connector.py
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/db_manager/layer_preview.py
Expand Up @@ -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()
Expand Down

0 comments on commit 6f09f17

Please sign in to comment.