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)
4
  • Haven't seen view before. How about if you replace self.iface.showAttributeTable(self.view.currentLayer()) with just self.iface.showAttributeTable(self.currentLayer())?
    – Joseph
    Commented Feb 24, 2017 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á
    Commented Feb 24, 2017 at 12:43
  • What happens if you replace self.view = view with self.iface.mapCanvas() = view?
    – Joseph
    Commented Feb 24, 2017 at 14:21
  • self.iface.mapCanvas() = view not working @Joseph
    – drama
    Commented Oct 6, 2017 at 11:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.