I have a plugin that loads some tables on another dockwidget. On QGIS 2.8 that's all ok, but on QGIS 2.14 the tables is loaded as layer correctly on a new dockwidget but when I request to open the attribute table I get the error message above.
The code is:
class MyMenuProvider(QgsLayerTreeViewMenuProvider):
def __init__(self, view, iface):
QgsLayerTreeViewMenuProvider.__init__(self)
self.view = view
self.iface = iface
def createContextMenu(self):
if not self.view.currentLayer():
return None
m = QMenu()
m.addAction("Abrir tabela", self.abreTab)
return m
def abreTab(self):
self.iface.showAttributeTable(self.view.currentLayer())
Inside the plugin´s main class I have:
lays = []
#---[Conecta tabelas]
for i, t in enumerate(lisBOG_t):
uri_db.setDataSource('', t,'','','')
lay = QgsVectorLayer(uri_db.uri(), lisBOG_l[i], 'spatialite')
lays.append(lay)
#---[Gera painel BOG]
self.bogtg = QgsLayerTreeGroup()
self.model =QgsLayerTreeModel(self.bogtg)
self.model.setFlag(QgsLayerTreeModel.ShowLegend, False)
self.model.setFlag(QgsLayerTreeModel.ShowLegendAsTree, False)
self.model.setFlag(QgsLayerTreeModel.AllowNodeReorder,False)
self.model.setFlag(QgsLayerTreeModel.AllowNodeChangeVisibility, False)
self.model.setFlag(QgsLayerTreeModel.AllowLegendChangeState, False)
self.model.setFlag(QgsLayerTreeModel.AllowNodeRename,False)
self.bogtv = QgsLayerTreeView()
self.bogtv.setModel(self.model)
self.bogDock = QDockWidget( "BOG" )
self.bogDock.setObjectName( "Tab_bog" )
self.bogDock.setAllowedAreas( Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea )
self.bogDock.setWidget( self.bogtv )
self.bogDock.setContentsMargins ( 9, 9, 9, 9 )
self.iface.addDockWidget( Qt.LeftDockWidgetArea, self.bogDock )
#---[Carrega painel]
for l in lays:
QgsMapLayerRegistry.instance().addMapLayer(l, False)
self.no_lay = self.bogtg.addLayer(l)
#---[T_BOG não editável]
l.setReadOnly(True)
#---[Menu da camada]
provmenu = MyMenuProvider(self.bogtv, self.iface)
self.bogtv.setMenuProvider(provmenu)
view
before. How about if you replaceself.iface.showAttributeTable(self.view.currentLayer())
with justself.iface.showAttributeTable(self.currentLayer())
?self.view = view
withself.iface.mapCanvas() = view
?