135 Commits

Author SHA1 Message Date
Nyall Dawson
6bd91f8381 [processing][api] Add API for an algorithm to auto-set parameter values
Adds an API which an algorithm can implement to support auto-setting
parameter values. This is designed to handle the case
of eg an algorithm which does a file format translation, where
it's desirable to default the output parameter value to an input
parameter value with a different extension.

This can now be done by implementing autogenerateParameterValues
in the algorithm, eg:

    def autogenerateParameterValues(self, existingParameters, changedParameter, mode):
        if changedParameter == self.INPUT:
            input_file = existingParameters.get(self.INPUT)
            if input_file:
                input_path = Path(input_file)
                if input_path.exists():
                    # auto set output parameter to same as input but with 'qgs' extension
                    return {self.OUTPUT: input_path.with_suffix('.qgs').as_posix()}

        return {}

Works for both toolbox and batch modes for algorithms
2025-04-30 13:56:09 +10:00
Jan Caha
ea9ee4088e handle temporary output 2025-03-20 10:12:37 +10:00
Denis Rouzaud
0f032e5f2d run pre-commit on all files 2024-11-29 15:38:02 +01:00
Nyall Dawson
578aa207d0 Show warning when loading batch params for algs with security risk
If the algorithm has the security risk flag, warn the user before
they can open stored batch parameter files
2024-10-02 10:36:00 +10:00
Nyall Dawson
6c1de7f70a [processing] Replace format for saving batch processing parameters
The older approach of storing parameters was insecure, and required
eval()ing the unchecked contents of the batch parameter file. This
is a security risk, as a malicious file could leak user information
or damage the system.

So,

- Switch to a newer ".batch" format which uses safe JSON objects
only for serializing parameter values.
- Allow loading the older .json files, but first show a warning
that they are a security risk and require to user to explicitly
agree to open the file
2024-10-01 19:35:51 +10:00
Nyall Dawson
95c9bb56b2 Remove unused code 2024-10-01 19:35:51 +10:00
Nyall Dawson
f1d762eba7 Update python/plugins/processing/gui/BatchPanel.py
Co-authored-by: Nicolas Godet <39594821+nicogodet@users.noreply.github.com>
2024-02-21 08:11:58 +10:00
Nyall Dawson
ece5d30a0b Ensure correct context is used when determining parameters for row
Fixes #56132
2024-02-21 08:11:58 +10:00
Nyall Dawson
496fd18e55 Add typehints 2024-02-21 08:11:58 +10:00
Nyall Dawson
def984cd4f Cleanup code, only run checks when warnOnInvalid is True
Refs #56132
2024-02-21 08:11:58 +10:00
Nyall Dawson
e42abf7dc5 Update python files 2024-01-22 05:46:15 +10:00
Nyall Dawson
c16a1e2b3d Update enums 2024-01-19 19:44:48 +10:00
Julien Cabieces
9d12ae8e6d [PyQt6] Add scope for enums and get rid of PyQt5.XXX import
this has been done automatically with the following comand line

./scripts/3to4/3to4.py --only-qgis3-compatible-changes ./python/plugins/
./scripts/3to4/3to4.py --only-qgis3-compatible-changes ./tests/src/python/
2024-01-10 21:15:27 +10:00
Blottiere Paul
9df62b90f3 Raise error in case if invalid parameter in batch mode 2023-10-17 15:32:54 +02:00
nicogodet
aadf6dcae9 Add PointCloud layers to "Select from Open Layers…" 2023-08-29 09:22:28 +10:00
Etienne Trimaille
3cab3c43a2
Python - Run pyupgrade on the processing plugin 2023-04-24 10:03:57 +02:00
Nyall Dawson
a4d6fd3ed5 Use QgsProcessingHistoryDialog for Processing history dialog
And remove old class
2023-04-24 13:09:46 +10:00
Nyall Dawson
f453d2cc0d [processing] Fix exception when setting output files in batch
processing after removing rows

Fixes #51664
2023-02-23 19:38:11 +10:00
Alexander Bruy
0434469dd0 fill in inputs in the Processing batch dialog starting from the first
empty row (fix #43869)
2022-05-19 14:48:13 +10:00
nicogodet
908e38a20a typo 2021-06-24 04:36:26 +10:00
Nyall Dawson
b740bf201a [processing] Fix exception when calling "Select from Files" in batch mode
on a file parameter

Fixes #40705
2021-01-05 08:32:10 +10:00
Alexander Bruy
220cb56421 fix row number calculation when reporting errors in the Processing batch
mode (fix #39326)
2020-11-26 11:27:48 +02:00
nirvn
f36701c4f8 [processing] Fix add (single) row tool button broken 2020-11-02 07:47:39 +10:00
Mathieu Pellerin
931136879c
[processing] Make batch process faster (#38989) 2020-09-24 12:34:59 +07:00
Nyall Dawson
e19f27d289 [processing] Fix hidden column names show in batch processing dialog,
throwing the table contents out of sync with the headers

Also make code a bit more robust

Fixes #38054
2020-07-31 16:03:28 +10:00
Nyall Dawson
6e2d1023f2 [processing] Fix loading batch settings with date/time values
Fixes #37838
2020-07-27 14:19:49 +10:00
Nyall Dawson
457a526916 [processing] Fix batch panel uses layer ids when auto populating
output names based on a layer parameter

Fixes #37554
2020-07-05 07:08:37 +10:00
Nyall Dawson
e386573c0c [FEATURE][processing] Port multi-layer input parameter widget to new API
Allows
- expression based inputs
- rearrangement of inputs for multi-layer parameters in models, to set
specific layer orders
2020-03-31 01:06:48 +10:00
Nyall Dawson
d327ddd668 Trick autopep 2020-03-29 05:56:23 +10:00
Nyall Dawson
ef4344b674 Default to current layer when appropriate 2020-03-29 05:56:23 +10:00
Nyall Dawson
2856e7d2a9 Somedays Travis is just calling out to be punched in the face... 2020-03-28 12:04:43 +10:00
Nyall Dawson
c92b6fba86 Indentation 2020-03-28 12:04:43 +10:00
Nyall Dawson
3d30471731 [processing] When running in a batch mode, move the layer adding
actions to the "Autofill" menu

This adds more UI consistency, as currently there's a disconnect
from the autofill options available via the Autofill buttons
vs some options which need to be done from the first rows "..."
button
2020-03-28 12:04:43 +10:00
Nyall Dawson
ffda225796 Travis fixes 2020-03-25 09:42:17 +10:00
Nyall Dawson
08e850db38 [processing] In batch mode, don't try to run rows with invalid parameter values
Previously we would show a warning about these, but then go ahead and try
to run the row anyway (using an empty set of parameters), resulting in
the log being filled with confusing error messages.

Instead, keep the existing warning advising about which values are
invalid, but skip the affected row and don't try to run it at all.
2020-03-19 15:42:13 +10:00
Nyall Dawson
70ee385f4a [processing] Add message bar to widget context 2020-01-05 08:59:38 +10:00
Nyall Dawson
f32d6fdcf2 [processing] Highlight row_number variable in batch expression editor 2019-09-26 20:46:38 +10:00
Luigi Pirelli
25ffc9f1c7 Hey! the var is dynamic! 2019-09-04 01:51:53 +10:00
Luigi Pirelli
7eaccc9049 changed to row_number to be consistent with other expression variables 2019-09-04 01:51:53 +10:00
Luigi Pirelli
a4b9ef73fd Added batch_number variable in algorithm scope to allow use it in the expression editor in Processing batch context 2019-09-04 01:51:53 +10:00
Nyall Dawson
ec246e3ddb [processing] Fix batch mode 'fill with parameter values' option for outputs
Fixes #30543
2019-07-09 07:20:20 +10:00
Alexander Bruy
1d1d2ca703 Revert "[processing] populate batch interface with rows when multiple layers"
This reverts commits f8890d8f047cd2bb934eaad83e1057814927adb5,
f085f5527658c0a81b9a065a6fcee4d654d16bb6 and 5844a0fc906c744327139e137642f0ec97ae240a
2019-05-30 12:05:52 +03:00
Bas Couwenberg
2628c480c5 Don't include revision in sources.
Prevent changes to files that weren't changed between releases.
This eases review of the changes between releases significantly.
2019-05-17 16:47:47 +02:00
Alexander Bruy
f8890d8f04 [processing] populate batch interface with rows when multiple layers
selected (fix #21859)
2019-05-09 08:14:12 +10:00
Nyall Dawson
af6d3d773d [processing] Fix exception when running batch alg after loading parameters 2019-05-08 20:13:07 +10:00
Nyall Dawson
070de69e30 [processing] Fix incorrect columns hidden when toggling advanced params in batch mode 2019-04-30 14:43:58 +10:00
Nyall Dawson
1d80fe8a19 Review comments 2019-04-30 14:43:58 +10:00
Nyall Dawson
c12fd877ed [processing] Remove selected rows from batch table, not always last row 2019-04-30 14:43:58 +10:00
Nyall Dawson
9f43f2f608 [FEATURE][processing] New "Add values by expression" option for
populating batch processing dialog

This option adds news rows using the values from an expression
which returns an array. (As opposed to "Calculate by Expression",
which works only on existing rows).

The intended use case is to allow populating the batch dialog
using complex numeric series, e.g. those created by the "generate_series"
expression function.

For example, adding rows for a batch buffer using the expression

    generate_series(100, 1000, 50)

(results in new rows with values 100, 150, 200, .... 1000)
2019-04-30 14:43:58 +10:00
Nyall Dawson
ee7daa8db7 [FEATURE][processing] Add option to calculate parameter values by expression in batch dialog
This new option is available under the Autofill menu for a column. Selecting it allows users
to create a new QGIS expression to use to update the value inside that column. Existing
parameter values (including those from other columns) are available for use inside
the expression via @variables.

E.g. this allows setting output file names to complex expressions like
'/home/me/stuff/buffer_' || left(@input, 30) || '_' || @distance || '.shp'
2019-04-30 14:43:58 +10:00