mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-17 00:09:36 -04:00
[processing] Add metadata setting for file destination parameters
to avoid file overwrite confirmation prompt Fixes #37011
This commit is contained in:
parent
50573d5e1f
commit
e81af2c9e1
@ -3142,6 +3142,19 @@ class QgsProcessingParameterFileDestination : QgsProcessingDestinationParameter
|
|||||||
A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
|
A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
|
||||||
created by the algorithm.
|
created by the algorithm.
|
||||||
|
|
||||||
|
In some circumstances it is desirable to avoid the usual file overwriting confirmation prompt when
|
||||||
|
users select an existing destination file for this parameter type (e.g., for algorithms which
|
||||||
|
append to an existing destination file instead of overwriting them.). This can be done by setting
|
||||||
|
the widget wrapper metadata "dontconfirmoverwrite" option:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
param = QgsProcessingParameterFileDestination( 'OUTPUT', 'Destination file')
|
||||||
|
# don't show the file overwrite warning when users select a destination file:
|
||||||
|
param.setMetadata( {'widget_wrapper':
|
||||||
|
{ 'dontconfirmoverwrite': True }
|
||||||
|
})
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -2986,7 +2986,21 @@ class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessing
|
|||||||
* \ingroup core
|
* \ingroup core
|
||||||
* A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
|
* A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
|
||||||
* created by the algorithm.
|
* created by the algorithm.
|
||||||
* \since QGIS 3.0
|
*
|
||||||
|
* In some circumstances it is desirable to avoid the usual file overwriting confirmation prompt when
|
||||||
|
* users select an existing destination file for this parameter type (e.g., for algorithms which
|
||||||
|
* append to an existing destination file instead of overwriting them.). This can be done by setting
|
||||||
|
* the widget wrapper metadata "dontconfirmoverwrite" option:
|
||||||
|
*
|
||||||
|
* * \code{.py}
|
||||||
|
* param = QgsProcessingParameterFileDestination( 'OUTPUT', 'Destination file')
|
||||||
|
* # don't show the file overwrite warning when users select a destination file:
|
||||||
|
* param.setMetadata( {'widget_wrapper':
|
||||||
|
* { 'dontconfirmoverwrite': True }
|
||||||
|
* })
|
||||||
|
* \endcode
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
*/
|
*/
|
||||||
class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDestinationParameter
|
class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDestinationParameter
|
||||||
{
|
{
|
||||||
|
@ -404,7 +404,9 @@ void QgsProcessingLayerOutputDestinationWidget::selectFile()
|
|||||||
else
|
else
|
||||||
path = settings.value( QStringLiteral( "/Processing/Configuration/OUTPUTS_FOLDER" ) ).toString();
|
path = settings.value( QStringLiteral( "/Processing/Configuration/OUTPUTS_FOLDER" ) ).toString();
|
||||||
|
|
||||||
QString filename = QFileDialog::getSaveFileName( this, tr( "Save file" ), path, fileFilter, &lastFilter );
|
const bool dontConfirmOverwrite = mParameter->metadata().value( QStringLiteral( "widget_wrapper" ) ).toMap().value( QStringLiteral( "dontconfirmoverwrite" ), false ).toBool();
|
||||||
|
|
||||||
|
QString filename = QFileDialog::getSaveFileName( this, tr( "Save file" ), path, fileFilter, &lastFilter, dontConfirmOverwrite ? QFileDialog::Options( QFileDialog::DontConfirmOverwrite ) : nullptr );
|
||||||
if ( !filename.isEmpty() )
|
if ( !filename.isEmpty() )
|
||||||
{
|
{
|
||||||
mUseTemporary = false;
|
mUseTemporary = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user