Skip to content

Commit b1879df

Browse files
committed
Destination parameters track whether they support non-file based outputs
1 parent d1ed7d1 commit b1879df

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *def
214214
if ( QgsProcessingAlgorithm::parameterDefinition( definition->name() ) )
215215
return false;
216216

217+
if ( definition->isDestination() )
218+
{
219+
QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
220+
destParam->setSupportsNonFileBasedOutputs( mProvider->supportsNonFileBasedOutput() );
221+
}
222+
217223
mParameters << definition;
218224
return true;
219225
}

src/core/processing/qgsprocessingparameters.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,14 +2088,14 @@ void QgsProcessingParameterFeatureSink::setDataType( QgsProcessingParameterDefin
20882088

20892089
QVariantMap QgsProcessingParameterFeatureSink::toVariantMap() const
20902090
{
2091-
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
2091+
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
20922092
map.insert( QStringLiteral( "data_type" ), mDataType );
20932093
return map;
20942094
}
20952095

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

22312231
QVariantMap QgsProcessingParameterFileOutput::toVariantMap() const
22322232
{
2233-
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
2233+
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
22342234
map.insert( QStringLiteral( "file_filter" ), mFileFilter );
22352235
return map;
22362236
}
22372237

22382238
bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map )
22392239
{
2240-
QgsProcessingParameterDefinition::fromVariantMap( map );
2240+
QgsProcessingDestinationParameter::fromVariantMap( map );
22412241
mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
22422242
return true;
22432243

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

22792279
}
22802280

2281+
QVariantMap QgsProcessingDestinationParameter::toVariantMap() const
2282+
{
2283+
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
2284+
map.insert( QStringLiteral( "support_non_file_outputs" ), mSupportsNonFileBasedOutputs );
2285+
return map;
2286+
}
2287+
2288+
bool QgsProcessingDestinationParameter::fromVariantMap( const QVariantMap &map )
2289+
{
2290+
QgsProcessingParameterDefinition::fromVariantMap( map );
2291+
mSupportsNonFileBasedOutputs = map.value( QStringLiteral( "supports_non_file_outputs" ) ).toBool();
2292+
return true;
2293+
}
2294+
22812295
QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional )
22822296
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
22832297
, mDataType( type )
@@ -2363,14 +2377,14 @@ void QgsProcessingParameterVectorOutput::setDataType( QgsProcessingParameterDefi
23632377

23642378
QVariantMap QgsProcessingParameterVectorOutput::toVariantMap() const
23652379
{
2366-
QVariantMap map = QgsProcessingParameterDefinition::toVariantMap();
2380+
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
23672381
map.insert( QStringLiteral( "data_type" ), mDataType );
23682382
return map;
23692383
}
23702384

23712385
bool QgsProcessingParameterVectorOutput::fromVariantMap( const QVariantMap &map )
23722386
{
2373-
QgsProcessingParameterDefinition::fromVariantMap( map );
2387+
QgsProcessingDestinationParameter::fromVariantMap( map );
23742388
mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
23752389
return true;
23762390
}

src/core/processing/qgsprocessingparameters.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,13 +1284,33 @@ class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParame
12841284
bool optional = false );
12851285

12861286
bool isDestination() const override { return true; }
1287+
QVariantMap toVariantMap() const override;
1288+
bool fromVariantMap( const QVariantMap &map ) override;
12871289

12881290
/**
12891291
* Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination
12901292
* parameter.
12911293
*/
12921294
virtual QgsProcessingOutputDefinition *toOutputDefinition() const = 0 SIP_FACTORY;
12931295

1296+
/**
1297+
* Returns true if the destination parameter supports non filed-based outputs,
1298+
* such as memory layers or direct database outputs.
1299+
* \see setSupportsNonFileBasedOutputs()
1300+
*/
1301+
bool supportsNonFileBasedOutputs() const { return mSupportsNonFileBasedOutputs; }
1302+
1303+
/**
1304+
* Sets whether the destination parameter supports non filed-based outputs,
1305+
* such as memory layers or direct database outputs.
1306+
* \see supportsNonFileBasedOutputs()
1307+
*/
1308+
void setSupportsNonFileBasedOutputs( bool supportsNonFileBasedOutputs ) { mSupportsNonFileBasedOutputs = supportsNonFileBasedOutputs; }
1309+
1310+
private:
1311+
1312+
bool mSupportsNonFileBasedOutputs = true;
1313+
12941314
};
12951315

12961316

tests/src/core/testqgsprocessing.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
106106
QVERIFY( addParameter( p6 ) );
107107
QCOMPARE( destinationParameterDefinitions(), QgsProcessingParameterDefinitions() << p5 << p6 );
108108

109+
// check that supportsNonFileBasedOutputs flags is set automatically to match provider
110+
// when adding a destination parameter
111+
QgsProcessingParameterFeatureSink *p7 = new QgsProcessingParameterFeatureSink( "p7" );
112+
p7->setSupportsNonFileBasedOutputs( false );
113+
QVERIFY( addParameter( p7 ) );
114+
QVERIFY( destinationParameterDefinitions().at( 2 )->supportsNonFileBasedOutputs() );
115+
109116
// remove parameter
110117
removeParameter( "non existent" );
111118
removeParameter( "p6" );
@@ -2813,6 +2820,7 @@ void TestQgsProcessing::parameterFeatureSink()
28132820
QCOMPARE( fromMap.flags(), def->flags() );
28142821
QCOMPARE( fromMap.defaultValue(), def->defaultValue() );
28152822
QCOMPARE( fromMap.dataType(), def->dataType() );
2823+
QCOMPARE( fromMap.supportsNonFileBasedOutputs(), def->supportsNonFileBasedOutputs() );
28162824
def.reset( dynamic_cast< QgsProcessingParameterFeatureSink *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
28172825
QVERIFY( dynamic_cast< QgsProcessingParameterFeatureSink *>( def.get() ) );
28182826

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

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

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

0 commit comments

Comments
 (0)