Skip to content

Commit

Permalink
Fix strange behaviour when mix of model outputs and fixed inputs are …
Browse files Browse the repository at this point in the history
…selected as the input for a multi layer parameter
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Aug 3, 2020
1 parent 00c3554 commit cca77d5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/gui/processing/qgsprocessingmultipleselectiondialog.cpp
Expand Up @@ -88,11 +88,34 @@ QVariantList QgsProcessingMultipleSelectionPanelWidget::selectedOptions() const
{
QVariantList options;
options.reserve( mModel->rowCount() );
bool hasModelSources = false;
for ( int i = 0; i < mModel->rowCount(); ++i )
{
if ( mModel->item( i )->checkState() == Qt::Checked )
options << mModel->item( i )->data( Qt::UserRole );
{
const QVariant option = mModel->item( i )->data( Qt::UserRole );

if ( option.canConvert< QgsProcessingModelChildParameterSource >() )
hasModelSources = true;

options << option;
}
}

if ( hasModelSources )
{
// if any selected value is a QgsProcessingModelChildParameterSource, then we need to upgrade them all
QVariantList originalOptions = options;
options.clear();
for ( const QVariant &option : originalOptions )
{
if ( option.canConvert< QgsProcessingModelChildParameterSource >() )
options << option;
else
options << QVariant::fromValue( QgsProcessingModelChildParameterSource::fromStaticValue( option ) );
}
}

return options;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -3140,6 +3140,28 @@ void TestProcessingGui::testMultipleSelectionDialog()
QCOMPARE( dlg->mModel->item( 1 )->text(), QStringLiteral( "6_" ) );
QCOMPARE( dlg->mModel->item( 2 )->text(), QStringLiteral( "6.2_" ) );

// mix of fixed + model choices
availableOptions = QVariantList() << QVariant( "a" ) << 6 << 6.2
<< QVariant::fromValue( QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) )
<< QVariant::fromValue( QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "input" ) ) );
dlg = qgis::make_unique< QgsProcessingMultipleSelectionPanelWidget >( availableOptions, QVariantList() << 6
<< QVariant::fromValue( QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) )
<< QVariant::fromValue( QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "input" ) ) ) );

// when any selected option is a model child parameter source, then we require that all options are upgraded in place to model child parameter sources
QVariantList res = dlg->selectedOptions();
QCOMPARE( res.size(), 3 );
QCOMPARE( res.at( 0 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromStaticValue( 6 ) );
QCOMPARE( res.at( 1 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) );
QCOMPARE( res.at( 2 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "input" ) ) );
dlg->selectAll( true );
res = dlg->selectedOptions();
QCOMPARE( res.size(), 5 );
QCOMPARE( res.at( 0 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromStaticValue( 6 ) );
QCOMPARE( res.at( 1 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromChildOutput( QStringLiteral( "alg" ), QStringLiteral( "out" ) ) );
QCOMPARE( res.at( 2 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromModelParameter( QStringLiteral( "input" ) ) );
QCOMPARE( res.at( 3 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromStaticValue( QStringLiteral( "a" ) ) );
QCOMPARE( res.at( 4 ).value< QgsProcessingModelChildParameterSource >(), QgsProcessingModelChildParameterSource::fromStaticValue( 6.2 ) );
}

void TestProcessingGui::testMultipleFileSelectionDialog()
Expand Down

0 comments on commit cca77d5

Please sign in to comment.