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

Update Function editor section (with Project functions functionality) #9293

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions docs/user_manual/expressions/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,24 @@ particular needs that would not be covered by the predefined functions.
To create a new function:

#. Press the |symbologyAdd| :sup:`New File` button.
#. Enter a name to use in the form that pops up and press :guilabel:`OK`.
#. Select where to store the new function. You can choose to save it either in a
Function file or in the current QGIS project file.
Copy link
Collaborator

@DelazJ DelazJ Oct 5, 2024

Choose a reason for hiding this comment

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

Suggested change
Function file or in the current QGIS project file.
:guilabel:`Function file` or in :guilabel:`Project functions`.

And should it be in Project function**s** or as Project function? IOW one or more functions at a time, hence edit the option in combobox?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you want to store your functions in the project file, there'll be only one item in the left panel for all of them, that's why the option is in plural.


.. _figure_expression_function_add_function_file:

.. figure:: img/function_editor_add_function_file.png
:align: center

The Add Function File dialog
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved

If you select Function file, you need to enter a name for the Python :file:`.py`
file, which is based on a QGIS template file and is stored in the :file:`/python/expressions`
folder under the active :ref:`user profile <user_profiles>` directory.

If you select Project functions, the new function is stored in the project file.
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved

A new item is added in the left panel of the :guilabel:`Function Editor` tab.

A new item of the name you provide is added in the left panel of the
:guilabel:`Function Editor` tab; this is a Python :file:`.py` file based on
QGIS template file and stored in the :file:`/python/expressions` folder
under the active :ref:`user profile <user_profiles>` directory.
#. The right panel displays the content of the file: a python script template.
Update the code and its help according to your needs.
#. Press the |start| :guilabel:`Save and Load Functions` button.
Expand All @@ -352,20 +364,29 @@ To create a new function:
Functions` button to make them available in the file, hence in any expression
tab.

Custom Python functions are stored under the user profile directory, meaning that at
each QGIS startup, it will auto load all the functions defined with the current user
profile. Be aware that new functions are only saved in the :file:`/python/expressions`
folder and not in the project file.
Custom Python functions stored as Function files are stored under the user profile
directory, meaning that at each QGIS startup, it will auto load all the functions
defined with the current user profile. Be aware that new functions are only saved in
the :file:`/python/expressions` folder and not in the project file.
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved
If you share a project that uses one of your custom functions you will need to also
share the :file:`.py` file in the :file:`/python/expressions` folder.

On the other hand, custom Python functions stored as Project functions can be easily
shared by sharing the project file where they were saved. When opening a project
with project functions, QGIS loads them, ignores them, or asks the user before
loading them, depending on the :ref:`General settings <general_options>`.
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved

To delete a custom function:

#. Enable the :guilabel:`Function Editor` tab
#. Select the function in the list
#. Press the |symbologyRemove| :sup:`Remove selected function`. The function is
removed from the list and the corresponding ``.py`` file deleted from
the user profile folder.
removed from the list and, depending on the storage, the corresponding ``.py``
file is deleted from the user profile folder, or the Python functions are removed
from the project file.

When a project file with Project functions is closed, the corresponding Project
functions are unloaded and are no longer available in the QGIS session.

**Example**

Expand Down
Binary file modified docs/user_manual/expressions/img/function_editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions docs/user_manual/introduction/qgis_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ displayed at the bottom of the frame.
version of QGIS`. You can always open projects created with older version of
QGIS but once the project is saved, trying to open with older release may fail
because of features not available in that version.
* :guilabel:`Enable macros` |selectString|. This option was created to handle
macros that are written to perform an action on project events. You can
* :guilabel:`Enable project's embedded Python code` |selectString|. This option
was created to handle macros that are written to perform an action on project
gacarrillor marked this conversation as resolved.
Show resolved Hide resolved
events, as well as custom Python functions to be used as expressions. You can
choose between 'Never', 'Ask', 'For this session only' and
'Always (not recommended)'.
* :guilabel:`Default paths`: defines whether paths to files and layers used
Expand Down
Loading