2

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)
  • Haven't seen view before. How about if you replace self.iface.showAttributeTable(self.view.currentLayer()) with just self.iface.showAttributeTable(self.currentLayer())? – Joseph Feb 24 '17 at 11:28
  • Thanks Joseph, but the currentLayer() is a property of 'view' object, correct? This seems a update on libs because on 2.8 it's ok. But I don't found... Thanks again! – Sassá Feb 24 '17 at 12:43
  • What happens if you replace self.view = view with self.iface.mapCanvas() = view? – Joseph Feb 24 '17 at 14:21
  • self.iface.mapCanvas() = view not working @Joseph – drama Oct 6 '17 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.