Skip to content

Commit

Permalink
[processing] Fix duplicate parameter warnings shown when loading models
Browse files Browse the repository at this point in the history
This is caused because the internal hidden VERBOSE_LOG parameter was
always being added to the model twice, so now we skip it during
writing/reading the model
  • Loading branch information
nyalldawson committed Nov 9, 2020
1 parent b567a7c commit 37a0b0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -1348,6 +1348,9 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const
QVariantMap paramDefMap;
for ( const QgsProcessingParameterDefinition *def : mParameters )
{
if ( def->name() == QStringLiteral( "VERBOSE_LOG" ) )
continue;

paramDefMap.insert( def->name(), def->toVariantMap() );
}
map.insert( QStringLiteral( "parameterDefinitions" ), paramDefMap );
Expand Down Expand Up @@ -1420,7 +1423,12 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
// otherwise models may become unusable (e.g. due to removed plugins providing algs/parameters)
// with no way for users to repair them
if ( param )
{
if ( param->name() == QLatin1String( "VERBOSE_LOG" ) )
return; // internal parameter -- some versions of QGIS incorrectly stored this in the model definition file

addParameter( param.release() );
}
else
{
QVariantMap map = value.toMap();
Expand Down
7 changes: 6 additions & 1 deletion tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -9677,7 +9677,12 @@ void TestQgsProcessing::modelerAlgorithm()
alg5.setDesignerParameterValues( lastParams );

QDomDocument doc = QDomDocument( "model" );
QDomElement elem = QgsXmlUtils::writeVariant( alg5.toVariant(), doc );
alg5.initAlgorithm();
const QVariant v = alg5.toVariant();
// make sure private parameters weren't included in the definition
QVERIFY( !v.toMap().value( QStringLiteral( "parameterDefinitions" ) ).toMap().contains( QStringLiteral( "VERBOSE_LOG" ) ) );

QDomElement elem = QgsXmlUtils::writeVariant( v, doc );
doc.appendChild( elem );

QgsProcessingModelAlgorithm alg6;
Expand Down

0 comments on commit 37a0b0e

Please sign in to comment.