qgis / QGIS-Enhancement-Proposals

QEP's (QGIS Enhancement Proposals) are used in the process of creating and discussing new enhancements for QGIS
118 stars 37 forks source link

Drag and drop form actions: expose QgsAttributeForm object to Python #251

Open elpaso opened 2 years ago

elpaso commented 2 years ago

QGIS Enhancement: Drag and drop form actions: expose QgsAttributeForm object to Python

Date 2022/05/02

Author Alessandro Pasotti (@elpaso )

Contact elpaso at itopen dot it

maintainer @elpaso

Version QGIS 3.28

Summary

Since https://github.com/qgis/QGIS/pull/45461 it is possible to add action buttons to the drag and drop forms.

This proposal is to add new "Drag and drop form" scope to Python actions that will automatically expose the current form to the Python code as a form local variable.

This will make it possible to manipulate all elements of the form including the values of the widgets.

Proposed Solution

Implement a new "Drag and drop form" scope for Python actions.

Expose the current form to the Python code as a form variable.

Example(s)

immagine

form-action

Affected Files

qgsattributeform and qgsaction

Performance Implications

None

Backwards Compatibility

None

Votes

(required)

elpaso commented 2 years ago

CC: @andreasneumann : this might be interesting to you too...

esnyder-rve commented 2 years ago

Would there be something to check the scope? Such that:

if scope.IsForm:
    form.blah()
else:
    somethingElse()

So that this one action could be used both inside a feature form, and outside as a right-click context menu item.

As one who uses actions and drag & drop forms a lot, I'd look forward to this.

elpaso commented 2 years ago

Would there be something to check the scope? Such that:

No, that's not planned, but you could check for form being defined or use a try-except.

nyalldawson commented 2 years ago

Sounds fine to me -- but what approach will you use to expose this? (I.e what's the technical details? :) )

elpaso commented 2 years ago

@nyalldawson still a draft: https://github.com/qgis/QGIS/pull/48445