1

I would like to complete the following map tool application that allows only to add some point features, by other functionalities like prompting the user to fill attribute form while editing for each point and save or rollback changes, together with maintaining the same layer styling.

from qgis.core import *
from qgis.gui import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class AddPointTool(QgsMapTool):
  def __init__(self, mapCanvas, layer):
    QgsMapTool.__init__(self, mapCanvas)
    self.layer=layer
    self.setCursor(Qt.CrossCursor)

  def canvasReleaseEvent(self, event):
    point=self.toLayerCoordinates(self.layer, event.pos())
    fields=self.layer.dataProvider().fields()
    feature=QgsFeature()
    feature.setFields(fields)
    feature.setGeometry(QgsGeometry.fromPointXY(point))

    self.layer.addFeature(feature)
    self.layer.updateExtents()
    self.layer.triggerRepaint()

canvas=iface.mapCanvas()
layer=iface.activeLayer()

layer.startEditing()
layer.triggerRepaint()
tool=AddPointTool(canvas,layer)
canvas.setMapTool(tool)

closed as too broad by BERA, Kadir Şahbaz, user30184, Evil Genius, Mark Ireland Aug 27 '18 at 14:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.