1

for a vector-layer I would like to produce an action, that shows the changed value in a formular.

E.G. I am editing a vector-point-layer, click on a point, the fomular is opening. I change a value (lets say the formular-field "z" had a value "test" and I change it to "test2").

Then I start my developed action.

I tried for example:


from qgis.PyQt import QtWidgets

QtWidgets.QMessageBox.information(None, "Feature id", "feature id is [
$z ] '%Z%' '%z%' $z [z] $Z [Z] [%z%] [%Z%]")

but I always get the "old" value "test" and not the formular-changed value "test2".

Has anybody an idea what I can do?

  • Did you save your modifications before trigger your action ? – Sociabilis May 27 at 12:30
  • No, I did not. I try to find a solution where I can find the changed values in the form before they are saved. – Kai Behncke May 27 at 12:45
1

I found a solution. Not by an action but by a specific formular:

from qgis.PyQt.QtWidgets import QWidget,QLineEdit,QPushButton,QDialogButtonBox
from PyQt5.QtCore import *
from PyQt5.QtGui import *

def my_form_open(dialog, layer, feature):
    geom = feature.geometry()
    control = dialog.findChild(QLineEdit, "z")
    #layer = qgis.utils.iface.activeLayer()
    global myDialog
    myDialog = dialog
    global myFeature
    myFeature= feature
    buttonBox = dialog.findChild(QDialogButtonBox,"buttonBox")
    #buttonBox.accepted.disconnect(myDialog.accept)
    #Wire up our own signals.
    buttonBox.accepted.connect(validate)
    #buttonBox.rejected.connect(myDialog.reject)
    # Wire up our own signals.
    #pushButton.accepted.connect(validate)

def validate():

    qgis.utils.iface.messageBar().pushMessage("Autosave", u"Validalli : ")
    layer = qgis.utils.iface.activeLayer()
    #qgis.utils.iface.messageBar().pushMessage("Autosave", u"blba : "+z.text())
    z = myDialog.findChild(QLineEdit, "z")
    myFeature['z'] = z.text()
    layer.updateFeature(myFeature)

    layer.commitChanges()
1

If s.o. wants to add a new feature it`s important in ther validate-section: activeLayer.startEditing() activeLayer.addFeature(myFeature)

activeLayer.commitChanges()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.