Skip to content
Permalink
Browse files
[processing] Fix default value of multiple field selection inputs
in models cannot be set to no value

Fixes #44005
  • Loading branch information
nyalldawson committed Jul 5, 2021
1 parent 574a35e commit cd3ff911f29894c1cdc88509002d4016bb3daf2e
Showing with 8 additions and 1 deletion.
  1. +7 −1 src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
  2. +1 −0 tests/src/gui/testprocessinggui.cpp
@@ -3928,7 +3928,13 @@ QgsProcessingFieldParameterDefinitionWidget::QgsProcessingFieldParameterDefiniti
QgsProcessingParameterDefinition *QgsProcessingFieldParameterDefinitionWidget::createParameter( const QString &name, const QString &description, QgsProcessingParameterDefinition::Flags flags ) const
{
QgsProcessingParameterField::DataType dataType = static_cast< QgsProcessingParameterField::DataType >( mDataTypeComboBox->currentData().toInt() );
auto param = qgis::make_unique< QgsProcessingParameterField >( name, description, mDefaultLineEdit->text(), mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(), false, mDefaultToAllCheckBox->isChecked() );

QVariant defaultValue;
if ( !mDefaultLineEdit->text().trimmed().isEmpty() )
{
defaultValue = mDefaultLineEdit->text();
}
auto param = std::make_unique< QgsProcessingParameterField >( name, description, defaultValue, mParentLayerComboBox->currentData().toString(), dataType, mAllowMultipleCheckBox->isChecked(), false, mDefaultToAllCheckBox->isChecked() );
param->setFlags( flags );
return param.release();
}
@@ -3024,6 +3024,7 @@ void TestProcessingGui::testFieldWrapper()
std::unique_ptr< QgsProcessingParameterDefinitionWidget > widget = qgis::make_unique< QgsProcessingParameterDefinitionWidget >( QStringLiteral( "field" ), context, widgetContext );
std::unique_ptr< QgsProcessingParameterDefinition > def( widget->createParameter( QStringLiteral( "param_name" ) ) );
QCOMPARE( def->name(), QStringLiteral( "param_name" ) );
QVERIFY( !def->defaultValue().isValid() );
QVERIFY( !( def->flags() & QgsProcessingParameterDefinition::FlagOptional ) ); // should default to mandatory
QVERIFY( !( def->flags() & QgsProcessingParameterDefinition::FlagAdvanced ) );

0 comments on commit cd3ff91

Please sign in to comment.