Skip to content
Permalink
Browse files

[processing] Add metadata setting for file destination parameters

to avoid file overwrite confirmation prompt

Fixes #37011
  • Loading branch information
nyalldawson committed Jun 8, 2020
1 parent 50573d5 commit e81af2c9e10dc2a2e220c815cb9e531f7dba838d
@@ -3142,6 +3142,19 @@ class QgsProcessingParameterFileDestination : QgsProcessingDestinationParameter
A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
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
%End

@@ -2986,7 +2986,21 @@ class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessing
* \ingroup core
* A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
* 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
{
@@ -404,7 +404,9 @@ void QgsProcessingLayerOutputDestinationWidget::selectFile()
else
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() )
{
mUseTemporary = false;

0 comments on commit e81af2c

Please sign in to comment.
You can’t perform that action at this time.