I'm developing plugin where I want to be able to edit non-spatial table inside the attribute table dialogue. As it seems that the only way to do so is to add this table to the TOC first, I do so. But it is pointless to keep this table inside the TOC after the editing is done and the attribute table is closed. I would like to remove table from TOC right after the attribute window is closed. Is there a way to catch the signal from the
showAttributeTable() when it is destroyed? Or is there a way not to add table to TOC in the first place?
Here is the code that I use:
def qgisOpenTable(self, layer_name, schema, table, geom_column=None, subset=None): ''' Opens table in QGIS attribute table window ''' uri = QgsDataSourceURI() uri.setConnection(self.server, self.port, self.db_name, self.login, self.password) uri.setDataSource(schema, table, geom_column, subset) vlayer = QgsVectorLayer(uri.uri(), layer_name, "postgres") QgsMapLayerRegistry.instance().addMapLayer(vlayer) layer_id = vlayer.id() i = iface.showAttributeTable(vlayer) # I would like to have something like this: i.destroyed.connect(QgsMapLayerRegistry.instance().removeMapLayer(layer_id))
The only workaround that came to my mind is to remove table after some time, but this is suboptimal.