Skip to content
Permalink
Browse files

[DB Manager] previewing layers in Virtual layers section remove them …

…from the Layers panel: fixies #16476

plus more vlayer db_manager plugin fixes to reduce (but can't avoid) exceptions due to C++/SIP object removes
  • Loading branch information
luipir authored and slarosa committed May 27, 2017
1 parent f3407f8 commit dae921c51f85f2dde2bab9b18a0d7c7c31bc700b
@@ -96,6 +96,10 @@ def getLayer(self, l):
lid = self.layers.get(l)
if lid is None:
return lid
# the instance can refer to a layer in map previe and not in qgis general canvas
if lid not in QgsMapLayerRegistry.instance().mapLayers().keys():
self.layers.pop(l)
return None
return QgsMapLayerRegistry.instance().mapLayer(lid)


@@ -246,12 +250,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)
@@ -277,6 +285,8 @@ def getTableExtent(self, table, geom):
l = QgsMapLayerRegistry.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
@@ -25,7 +25,7 @@
from qgis.PyQt.QtWidgets import QApplication

from qgis.gui import QgsMapCanvas, QgsMapCanvasLayer, QgsMessageBar
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsProject

from .db_plugins.plugin import Table

@@ -113,15 +113,18 @@ 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:
QgsMapLayerRegistry.instance().removeMapLayers([self.currentLayer.id()])
# but not remove it if in layer list panel
# fix https://issues.qgis.org/issues/16476
if not QgsProject.instance().layerTreeRoot().findLayer(self.currentLayer.id()):
QgsMapLayerRegistry.instance().removeMapLayers([self.currentLayer.id()])

if vl:
if vl and vl.isValid():
self.setLayerSet([QgsMapCanvasLayer(vl)])
QgsMapLayerRegistry.instance().addMapLayers([vl], False)
self.zoomToFullExtent()

0 comments on commit dae921c

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