I'm writing a plugin and was really hoping to get the featureAdded signal when the user is interacting with a VectorLayer object in the plugin, but I never see that signal. To try and figure out what's going on, I created this standalone code that could run during QGIS startup. When I select a VectorLayer, I see that print, also edit start, edit end, and geom change. But I never see featureAdded or committedFeaturesAdded signals. I've tried the slots with and without @pyqtSlot decorators. I've tried this on 3.16.3 and 3.24.3 on Linux and 3.24.2 on Windows with the same results. What am I missing?
from qgis.core import QgsProject, QgsMapLayer
from qgis.utils import iface
from qgis.PyQt.QtCore import pyqtSlot
projConnect = False
@pyqtSlot(int)
def addedVertex(idx):
print('new vertex id:', idx)
def addedFeatures(layerId, featureList):
print(layerId, featureList)
def geomChange():
print("geomChange")
def editStart():
print("editStart")
alayer = iface.activeLayer()
alayer.featureAdded.connect(addedVertex)
alayer.committedFeaturesAdded.connect(addedFeatures)
alayer.geometryChanged.connect(geomChange)
def editStop():
print("editStop")
alayer = iface.activeLayer()
alayer.featureAdded.disconnect()
alayer.committedFeaturesAdded.disconnect()
alayer.geometryChanged.disconnect()
def layerChanged(layer):
if layer == None:
return
if layer.type() == QgsMapLayer.VectorLayer:
print('layerChanged - is Vector layer')
alayer = iface.activeLayer()
alayer.editingStarted.connect(editStart)
alayer.editingStopped.connect(editStop)
def projLoaded():
global projConnect
if projConnect == False:
projConnect = True
iface.currentLayerChanged.connect(layerChanged)
QgsProject.instance().readProject.connect(projLoaded)