Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Allow users to save expression functions in QGIS project file #43

Merged
merged 11 commits into from
Sep 18, 2024

Conversation

gacarrillor
Copy link
Owner

@gacarrillor gacarrillor commented May 30, 2024

In the expression builder dialog, Python functions can only be saved in the user profile directory. If a user wants to share expression functions with colleagues, he/she needs to share his/her expressions directory or individual .py files, which is inconvenient (without mentioning the installation of those shared files won't be trivial either).

This PR allows users to also store expression functions into the current QGIS project file, making it easier to share functions with other interested parties.

Some details about the implementation:

  • At most, one [Project Functions] item will be listed in the left-hand side list widget (Function Editor tab).
  • Users will be able to add and remove the aforementioned item.
  • If a [Project Functions] item already exists in the list, the corresponding option in the Add Function File dialog will be disabled.
  • Project functions will be loaded when opening the QGIS project.
  • Project gets dirty when expression functions are added to the project or when they are edited.
  • Note: Project functions are not unloaded for the ongoing QGIS session when a project is closed. This is the same behavior compared to expression functions saved in the user profile (i.e., when a function file is removed, expression functions are not unloaded for the ongoing QGIS session).

image

image

Labels: [Needs Documentation] [Feature] [Expressions]

Funded by the QGIS user group Switzerland.

Copy link

github-actions bot commented May 30, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit c5286e4)

Copy link

@nirvn nirvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loving this function, I actually had to avoid using these exactly because they weren't portable / embedded into shared projects. A few comments here and there.

src/gui/qgsexpressionaddfunctionfiledialog.h Show resolved Hide resolved
src/gui/qgsexpressionaddfunctionfiledialog.cpp Outdated Show resolved Hide resolved
src/gui/qgsexpressionaddfunctionfiledialog.cpp Outdated Show resolved Hide resolved
src/gui/qgsexpressionaddfunctionfiledialog.cpp Outdated Show resolved Hide resolved
src/gui/qgsexpressionaddfunctionfiledialog.h Outdated Show resolved Hide resolved
src/gui/qgsexpressionaddfunctionfiledialog.h Outdated Show resolved Hide resolved
src/gui/qgsexpressionbuilderwidget.cpp Outdated Show resolved Hide resolved
@gacarrillor
Copy link
Owner Author

Loving this function, I actually had to avoid using these exactly because they weren't portable / embedded into shared projects. A few comments here and there.

Thanks a lot for your review, all changes were applied in e9f736e
I'll create a PR to QGIS repo when tests are green.

@gacarrillor gacarrillor force-pushed the save_functions_in_project branch 4 times, most recently from 889fbfc to 0b73ff2 Compare August 19, 2024 16:05
@gacarrillor gacarrillor force-pushed the save_functions_in_project branch 2 times, most recently from 14ce964 to 154adac Compare September 6, 2024 03:15
…ways at the top of the list in the 'Function editor' tab) and never stored in a user profile file
…e whether to store functions in a .py file (current behavior) or in the QGIS project
… users allow it, just like we do with macros
…se and reload user expressions (from profile) to avoid any potential overwrite from unloaded project functions
… project close) and reloading user ones, specifically to restore overwritten user functions when opening a project with expressions inside
…nsFromProject to QgsProject::read and ::clear, respectively. Introduce function pythonEmbeddedInProjectAllowed to ask for permissions to load both macros and expression functions, with a parameter enum and rename existing enum for macros. Sort includes. Drop not needed file. Add python/expressions/ to gitignore, to get rid of files produced by the introduced Python test.
@gacarrillor gacarrillor merged commit 2817262 into master Sep 18, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants