Skip to content

Commit

Permalink
Merge pull request #7890 from luipir/fix_cascaded_grass_algs_in_modeler
Browse files Browse the repository at this point in the history
Fix cascaded grass algs in modeler
  • Loading branch information
luipir committed Sep 14, 2018
2 parents 73528cd + f88850a commit efa7277
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit efa7277

Please sign in to comment.