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 authored and github-actions committed Jul 1, 2021
1 parent fa1a59f commit 8840865d09da64b6817f4b9e118cb988c92e77a5
Showing with 8 additions and 1 deletion.
  1. +7 −1 src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
  2. +1 −0 tests/src/gui/testprocessinggui.cpp
@@ -4000,7 +4000,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 = std::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();
}
@@ -3054,6 +3054,7 @@ void TestProcessingGui::testFieldWrapper()
std::unique_ptr< QgsProcessingParameterDefinitionWidget > widget = std::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 8840865

Please sign in to comment.