I adapted the following code from a QGIS 2.18 plugin to a QGIS 3.2 plugin:
def showFeatures(self):
layer = self.iface.activeLayer()
features = layer.selectedFeatures()
#Anzeigen der ausgewählten Features
self.dockwidget.features_list.clear()
for i in range (0,len(features)):
self.dockwidget.features_list.addItem(str(i))
layer.selectionChanged.connect(self.showFeatures)
def showAttributes(self):
if not self.dockwidget.features_list.selectedIndexes():
return
item = self.dockwidget.features_list.selectedItems()[0]
feature = self.selectedFeatures[int(item.text())]
#Zoom
box = feature.geometry().boundingBox()
self.iface.mapCanvas().setExtent(box)
self.iface.mapCanvas().refresh()
#Anzeigen der Feature Attribute
self.dockwidget.attributes_list.clear()
for attribute in feature.attributes():
self.dockwidget.attributes_list.addItem(str(attribute))
The plugin I adapted the code from writes the code in the file plugin_dockwidget.py, I write it in the plugin.py. The plugin refers to two list widgets. The first function shows the currently selected features in the first list widget. What the second function should do, is to show a list of attributes of the feature I selected in the first list widget and to zoom on the feature.
My problem is, that the plugin shows the features as expected, but it neither shows the attributes nor does it zoom onto the selected feature.
features_list displays the feautres attributes_list should display the attributes