Skip to content
Permalink
Browse files

Destination parameters track whether they support non-file based outputs

  • Loading branch information
nyalldawson committed Jun 21, 2017
1 parent d1ed7d1 commit b1879df34b66a7b5a292b073c620454d1e524bfc
@@ -214,6 +214,12 @@ bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *def
if ( QgsProcessingAlgorithm::parameterDefinition( definition->name() ) )
return false;

if ( definition->isDestination() )
{
QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
destParam->setSupportsNonFileBasedOutputs( mProvider->supportsNonFileBasedOutput() );
}

mParameters << definition;
return true;
}
@@ -2088,14 +2088,14 @@ void QgsProcessingParameterFeatureSink::setDataType( QgsProcessingParameterDefin

QVariantMap QgsProcessingParameterFeatureSink::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
map.insert( QStringLiteral( "data_type" ), mDataType );
return map;
}

bool QgsProcessingParameterFeatureSink::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
QgsProcessingDestinationParameter::fromVariantMap( map );
mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
return true;
}
@@ -2230,14 +2230,14 @@ void QgsProcessingParameterFileOutput::setFileFilter( const QString &fileFilter

QVariantMap QgsProcessingParameterFileOutput::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
map.insert( QStringLiteral( "file_filter" ), mFileFilter );
return map;
}

bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
QgsProcessingDestinationParameter::fromVariantMap( map );
mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
return true;

@@ -2278,6 +2278,20 @@ QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QStr

}

QVariantMap QgsProcessingDestinationParameter::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
map.insert( QStringLiteral( "support_non_file_outputs" ), mSupportsNonFileBasedOutputs );
return map;
}

bool QgsProcessingDestinationParameter::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
return true;
}

QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mDataType( type )
@@ -2363,14 +2377,14 @@ void QgsProcessingParameterVectorOutput::setDataType( QgsProcessingParameterDefi

QVariantMap QgsProcessingParameterVectorOutput::toVariantMap() const
{
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
map.insert( QStringLiteral( "data_type" ), mDataType );
return map;
}

bool QgsProcessingParameterVectorOutput::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
QgsProcessingDestinationParameter::fromVariantMap( map );
mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
return true;
}
@@ -1284,13 +1284,33 @@ class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParame
bool optional = false );

bool isDestination() const override { return true; }
QVariantMap toVariantMap() const override;
bool fromVariantMap( const QVariantMap &map ) override;

/**
* Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination
* parameter.
*/
virtual QgsProcessingOutputDefinition *toOutputDefinition() const = 0 SIP_FACTORY;

/**
* Returns true if the destination parameter supports non filed-based outputs,
* such as memory layers or direct database outputs.
* \see setSupportsNonFileBasedOutputs()
*/
bool supportsNonFileBasedOutputs() const { return mSupportsNonFileBasedOutputs; }

/**
* Sets whether the destination parameter supports non filed-based outputs,
* such as memory layers or direct database outputs.
* \see supportsNonFileBasedOutputs()
*/
void setSupportsNonFileBasedOutputs( bool supportsNonFileBasedOutputs ) { mSupportsNonFileBasedOutputs = supportsNonFileBasedOutputs; }

private:

bool mSupportsNonFileBasedOutputs = true;

};


@@ -106,6 +106,13 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QVERIFY( addParameter( p6 ) );
QCOMPARE( destinationParameterDefinitions(), QgsProcessingParameterDefinitions() << p5 << p6 );

// check that supportsNonFileBasedOutputs flags is set automatically to match provider
// when adding a destination parameter
QgsProcessingParameterFeatureSink *p7 = new QgsProcessingParameterFeatureSink( "p7" );
p7->setSupportsNonFileBasedOutputs( false );
QVERIFY( addParameter( p7 ) );
QVERIFY( destinationParameterDefinitions().at( 2 )->supportsNonFileBasedOutputs() );

// remove parameter
removeParameter( "non existent" );
removeParameter( "p6" );
@@ -2813,6 +2820,7 @@ void TestQgsProcessing::parameterFeatureSink()
QCOMPARE( fromMap.flags(), def->flags() );
QCOMPARE( fromMap.defaultValue(), def->defaultValue() );
QCOMPARE( fromMap.dataType(), def->dataType() );
QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() );
def.reset( dynamic_cast< QgsProcessingParameterFeatureSink *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
QVERIFY( dynamic_cast< QgsProcessingParameterFeatureSink *>( def.get() ) );

@@ -2942,6 +2950,7 @@ void TestQgsProcessing::parameterRasterOut()
QCOMPARE( fromMap.description(), def->description() );
QCOMPARE( fromMap.flags(), def->flags() );
QCOMPARE( fromMap.defaultValue(), def->defaultValue() );
QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() );
def.reset( dynamic_cast< QgsProcessingParameterRasterOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
QVERIFY( dynamic_cast< QgsProcessingParameterRasterOutput *>( def.get() ) );

@@ -3007,6 +3016,7 @@ void TestQgsProcessing::parameterFileOut()
QCOMPARE( fromMap.flags(), def->flags() );
QCOMPARE( fromMap.defaultValue(), def->defaultValue() );
QCOMPARE( fromMap.fileFilter(), def->fileFilter() );
QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() );
def.reset( dynamic_cast< QgsProcessingParameterFileOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
QVERIFY( dynamic_cast< QgsProcessingParameterFileOutput *>( def.get() ) );

@@ -3060,6 +3070,7 @@ void TestQgsProcessing::parameterFolderOut()
QCOMPARE( fromMap.description(), def->description() );
QCOMPARE( fromMap.flags(), def->flags() );
QCOMPARE( fromMap.defaultValue(), def->defaultValue() );
QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() );
def.reset( dynamic_cast< QgsProcessingParameterFolderOutput *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
QVERIFY( dynamic_cast< QgsProcessingParameterFolderOutput *>( def.get() ) );

0 comments on commit b1879df

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