Skip to content
Permalink
Browse files

Merge pull request #7890 from luipir/fix_cascaded_grass_algs_in_modeler

Fix cascaded grass algs in modeler
  • Loading branch information
luipir committed Sep 14, 2018
2 parents 73528cd + f88850a commit efa72779afebebd548b2565e96224a8235372d91
@@ -330,6 +330,9 @@ def prepareGrassExecution(commands):
Prepare GRASS batch job in a script and
returns it as a command ready for subprocess.
"""
if Grass7Utils.command is None:
Grass7Utils.grassBin()

env = os.environ.copy()
env['GRASS_MESSAGE_FORMAT'] = 'plain'
if 'GISBASE' in env:
@@ -528,6 +528,18 @@ QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParam
return layer;
}

if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
{
// input is a QgsProcessingOutputLayerDefinition - get extra properties from it
QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
val = fromVar.sink;
}

if ( val.canConvert<QgsProperty>() && val.value< QgsProperty >().propertyType() == QgsProperty::StaticProperty )
{
val = val.value< QgsProperty >().staticValue();
}

if ( !val.isValid() || val.toString().isEmpty() )
{
// fall back to default
@@ -2344,6 +2344,24 @@ void TestQgsProcessing::parameterLayer()
QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) );
QCOMPARE( fromCode->flags(), def->flags() );
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );

// check if can manage QgsProcessingOutputLayerDefinition
// as QVariat value in parameters (e.g. coming from an input of
// another algorithm)

// all ok
def.reset( new QgsProcessingParameterMapLayer( "non_optional", QString(), r1->id(), true ) );
QString sink_name( r1->id() );
QgsProcessingOutputLayerDefinition val( sink_name );
params.insert( "non_optional", QVariant::fromValue( val ) );
QCOMPARE( QgsProcessingParameters::parameterAsLayer( def.get(), params, context )->id(), r1->id() );

// not ok, e.g. source name is not a layer and it's not possible to generate a layer from it source
def.reset( new QgsProcessingParameterMapLayer( "non_optional", QString(), r1->id(), true ) );
sink_name = QString( "i'm not a layer, and nothing you can do will make me one" );
QgsProcessingOutputLayerDefinition val2( sink_name );
params.insert( "non_optional", QVariant::fromValue( val2 ) );
QVERIFY( !QgsProcessingParameters::parameterAsLayer( def.get(), params, context ) );
}

void TestQgsProcessing::parameterExtent()

0 comments on commit efa7277

Please sign in to comment.
You can’t perform that action at this time.