I have a custom tool to add feature points. The attribute values are provided filling a custom dialog. The code was writted following this topic.
At the end of the procedure, outside the tool, if I select a different layer and I start editing with toggle editing of QGIS (without selecting add point/polygon feature tool), I continue editing with the custom tool as if it didn't end the procedure.
How I can stop the editing session on the custom tool? This is the code:
class casePicker(QgsMapTool):
afterClick = pyqtSignal()
def __init__(self, dlg, psrid, iface, tt, lab, lyr):
QgsMapTool.__init__(self, iface.mapCanvas())
self.iface = iface
self.canvas = self.iface.mapCanvas()
self.dlg = dlg
self.psrid = psrid
self.tt = tt
self.lab = lab
self.lyr = lyr
self.funcs = qvfuncs.VetEpiGISFuncs()
self.canvas.setCursor(mutato)
def canvasPressEvent(self, event):
pass
def canvasMoveEvent(self, event):
pass
def canvasReleaseEvent(self, event):
x = event.pos().x()
y = event.pos().y()
pt = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)
x = pt.x()
y = pt.y()
if self.dlg.exec_() == QDialog.Accepted:
QApplication.setOverrideCursor(Qt.WaitCursor)
x = float(self.dlg.lineEdit.text())
y = float(self.dlg.lineEdit_2.text())
self.addFeat(x, y)
self.tt.setChecked(False)
QApplication.restoreOverrideCursor()
def addFeat(self, x, y):
self.lyr.startEditing()
feat = QgsFeature()
feat = self.funcs.outattrPrep(self.dlg, self.lyr)
pnt = QgsGeometry.fromPointXY(QgsPointXY(x,y))
if self.lyr.geometryType() == QgsWkbTypes.PointGeometry:
feat.setGeometry(pnt)
else:
pass
feat.setValid(True)
self.lyr.addFeature(feat)
self.lyr.commitChanges()
self.lyr.updateExtents()
def activate(self):
pass
def deactivate(self):
pass
def isZoomTool(self):
return False
def isTransient(self):
return False
def isEditTool(self):
return True
self.iface.currentLayerChanged.connect(self.setPanTool)and the methodsetPanTool(self)containsself.iface.actionPan().trigger(). At the end of the methoddef canvasReleaseEvent(self, event):I addedself.iface.actionPan().trigger(). Other solutions are welcome. – PaolaB Nov 22 '19 at 11:21