Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #40223 from nyalldawson/vrt_separate
Don't default to placing each input file in a separate  band in build vrt algorithm
  • Loading branch information
nyalldawson committed Nov 27, 2020
2 parents 37ab5e8 + 347885b commit c0a579c
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 53 deletions.
Expand Up @@ -420,6 +420,10 @@ the parameter's behavior and use in depth.
Returns the default value for the parameter.

.. seealso:: :py:func:`setDefaultValue`

.. seealso:: :py:func:`defaultValueForGui`

.. seealso:: :py:func:`guiDefaultValueOverride`
%End

void setDefaultValue( const QVariant &value );
Expand All @@ -428,6 +432,52 @@ Sets the default ``value`` for the parameter. Caller takes responsibility
to ensure that ``value`` is a valid input for the parameter subclass.

.. seealso:: :py:func:`defaultValue`

.. seealso:: :py:func:`setGuiDefaultValueOverride`
%End

QVariant guiDefaultValueOverride() const;
%Docstring
Returns the default value to use in the GUI for the parameter.

Usually this will return an invalid variant, which indicates that the standard :py:func:`~QgsProcessingParameterDefinition.defaultValue`
will be used in the GUI.

.. seealso:: :py:func:`defaultValue`

.. seealso:: :py:func:`setGuiDefaultValueOverride`

.. seealso:: :py:func:`defaultValueForGui`

.. versionadded:: 3.18
%End

void setGuiDefaultValueOverride( const QVariant &value );
%Docstring
Sets the default ``value`` to use for the parameter in GUI widgets. Caller takes responsibility
to ensure that ``value`` is a valid input for the parameter subclass.

Usually the :py:func:`~QgsProcessingParameterDefinition.guiDefaultValueOverride` is a invalid variant, which indicates that the standard :py:func:`~QgsProcessingParameterDefinition.defaultValue`
should be used in the GUI. In cases where it is decided that a previous default value was inappropriate,
setting a non-invalid default GUI value can be used to change the default value for the parameter shown
to users when running algorithms without changing the actual :py:func:`~QgsProcessingParameterDefinition.defaultValue` and potentially breaking
third party scripts.

.. seealso:: :py:func:`guiDefaultValueOverride`

.. seealso:: :py:func:`setDefaultValue`

.. versionadded:: 3.18
%End

QVariant defaultValueForGui() const;
%Docstring
Returns the default value to use for the parameter in a GUI.

This will be the parameter's :py:func:`~QgsProcessingParameterDefinition.defaultValue`, unless a :py:func:`~QgsProcessingParameterDefinition.guiDefaultValueOverride` is set to
override that.

.. versionadded:: 3.18
%End

Flags flags() const;
Expand Down Expand Up @@ -665,6 +715,7 @@ The ``variables`` list should contain the variable names only, without the usual




};

QFlags<QgsProcessingParameterDefinition::Flag> operator|(QgsProcessingParameterDefinition::Flag f1, QFlags<QgsProcessingParameterDefinition::Flag> f2);
Expand Down
12 changes: 9 additions & 3 deletions python/plugins/processing/algs/gdal/buildvrt.py
Expand Up @@ -109,9 +109,15 @@ def isSupportedOutputValue(self, value, context):
self.tr('Resolution'),
options=[i[0] for i in self.RESOLUTION_OPTIONS],
defaultValue=0))
self.addParameter(QgsProcessingParameterBoolean(self.SEPARATE,
self.tr('Place each input file into a separate band'),
defaultValue=True))

separate_param = QgsProcessingParameterBoolean(self.SEPARATE,
self.tr('Place each input file into a separate band'),
defaultValue=True)
# default to not using separate bands is a friendlier option, but we can't change the parameter's actual
# defaultValue without breaking API!
separate_param.setGuiDefaultValueOverride(False)
self.addParameter(separate_param)

self.addParameter(QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
self.tr('Allow projection difference'),
defaultValue=False))
Expand Down
5 changes: 4 additions & 1 deletion src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -589,7 +589,8 @@ QStringList QgsProcessingParameters::parameterAsEnumStrings( const QgsProcessing
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QSet<QString> subtraction = enumValues.toSet().subtract( enumDef->options().toSet() );
#else
QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( enumDef->options().begin(), enumDef->options().end() ) );
const QStringList options = enumDef->options();
QSet<QString> subtraction = QSet<QString>( enumValues.begin(), enumValues.end() ).subtract( QSet<QString>( options.begin(), options.end() ) );
#endif

if ( enumValues.isEmpty() || !subtraction.isEmpty() )
Expand Down Expand Up @@ -2447,6 +2448,7 @@ QVariantMap QgsProcessingParameterDefinition::toVariantMap() const
map.insert( QStringLiteral( "description" ), mDescription );
map.insert( QStringLiteral( "help" ), mHelp );
map.insert( QStringLiteral( "default" ), mDefault );
map.insert( QStringLiteral( "defaultGui" ), mGuiDefault );
map.insert( QStringLiteral( "flags" ), static_cast< int >( mFlags ) );
map.insert( QStringLiteral( "metadata" ), mMetadata );
return map;
Expand All @@ -2458,6 +2460,7 @@ bool QgsProcessingParameterDefinition::fromVariantMap( const QVariantMap &map )
mDescription = map.value( QStringLiteral( "description" ) ).toString();
mHelp = map.value( QStringLiteral( "help" ) ).toString();
mDefault = map.value( QStringLiteral( "default" ) );
mGuiDefault = map.value( QStringLiteral( "defaultGui" ) );
mFlags = static_cast< Flags >( map.value( QStringLiteral( "flags" ) ).toInt() );
mMetadata = map.value( QStringLiteral( "metadata" ) ).toMap();
return true;
Expand Down
47 changes: 47 additions & 0 deletions src/core/processing/qgsprocessingparameters.h
Expand Up @@ -521,16 +521,60 @@ class CORE_EXPORT QgsProcessingParameterDefinition
/**
* Returns the default value for the parameter.
* \see setDefaultValue()
* \see defaultValueForGui()
* \see guiDefaultValueOverride()
*/
QVariant defaultValue() const { return mDefault; }

/**
* Sets the default \a value for the parameter. Caller takes responsibility
* to ensure that \a value is a valid input for the parameter subclass.
* \see defaultValue()
* \see setGuiDefaultValueOverride()
*/
void setDefaultValue( const QVariant &value ) { mDefault = value; }

/**
* Returns the default value to use in the GUI for the parameter.
*
* Usually this will return an invalid variant, which indicates that the standard defaultValue()
* will be used in the GUI.
*
* \see defaultValue()
* \see setGuiDefaultValueOverride()
* \see defaultValueForGui()
*
* \since QGIS 3.18
*/
QVariant guiDefaultValueOverride() const { return mGuiDefault; }

/**
* Sets the default \a value to use for the parameter in GUI widgets. Caller takes responsibility
* to ensure that \a value is a valid input for the parameter subclass.
*
* Usually the guiDefaultValueOverride() is a invalid variant, which indicates that the standard defaultValue()
* should be used in the GUI. In cases where it is decided that a previous default value was inappropriate,
* setting a non-invalid default GUI value can be used to change the default value for the parameter shown
* to users when running algorithms without changing the actual defaultValue() and potentially breaking
* third party scripts.
*
* \see guiDefaultValueOverride()
* \see setDefaultValue()
*
* \since QGIS 3.18
*/
void setGuiDefaultValueOverride( const QVariant &value ) { mGuiDefault = value; }

/**
* Returns the default value to use for the parameter in a GUI.
*
* This will be the parameter's defaultValue(), unless a guiDefaultValueOverride() is set to
* override that.
*
* \since QGIS 3.18
*/
QVariant defaultValueForGui() const { return mGuiDefault.isValid() ? mGuiDefault : mDefault; }

/**
* Returns any flags associated with the parameter.
* \see setFlags()
Expand Down Expand Up @@ -745,6 +789,9 @@ class CORE_EXPORT QgsProcessingParameterDefinition
//! Default value for parameter
QVariant mDefault;

//! Default value for parameter in GUI
QVariant mGuiDefault;

//! Parameter flags
Flags mFlags;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingmaplayercombobox.cpp
Expand Up @@ -251,7 +251,7 @@ void QgsProcessingMapLayerComboBox::setValue( const QVariant &value, QgsProcessi
}
else
{
val = val.value< QgsProperty >().valueAsString( context.expressionContext(), mParameter->defaultValue().toString() );
val = val.value< QgsProperty >().valueAsString( context.expressionContext(), mParameter->defaultValueForGui().toString() );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/processing/qgsprocessingoutputdestinationwidget.cpp
Expand Up @@ -55,7 +55,7 @@ QgsProcessingLayerOutputDestinationWidget::QgsProcessingLayerOutputDestinationWi
QgsSettings settings;
mEncoding = settings.value( QStringLiteral( "/Processing/encoding" ), QStringLiteral( "System" ) ).toString();

if ( !mParameter->defaultValue().isValid() )
if ( !mParameter->defaultValueForGui().isValid() )
{
// no default value -- we default to either skipping the output or a temporary output, depending on the createByDefault value
if ( mParameter->flags() & QgsProcessingParameterDefinition::FlagOptional && !mParameter->createByDefault() )
Expand All @@ -65,7 +65,7 @@ QgsProcessingLayerOutputDestinationWidget::QgsProcessingLayerOutputDestinationWi
}
else
{
setValue( mParameter->defaultValue() );
setValue( mParameter->defaultValueForGui() );
}

setToolTip( mParameter->toolTip() );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -153,7 +153,7 @@ QWidget *QgsAbstractProcessingParameterWidgetWrapper::createWrappedWidget( QgsPr
if ( !dynamic_cast<const QgsProcessingDestinationParameter * >( mParameterDefinition ) )
{
// an exception -- output widgets handle this themselves
setWidgetValue( mParameterDefinition->defaultValue(), context );
setWidgetValue( mParameterDefinition->defaultValueForGui(), context );
}

return wrappedWidget;
Expand Down

0 comments on commit c0a579c

Please sign in to comment.