Skip to content
Permalink
Browse files

Rename QgsProcessingFeatureSinkDefinition to QgsProcessingOutputLayer…

…Definition

Since it also applies to raster layer outputs, we need a more generic name
  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent f64f74f commit b75a174780a95fea8eafdb0d81e56260159f7ea3
@@ -56,11 +56,11 @@ Allows direct construction of QVariants.



class QgsProcessingFeatureSinkDefinition
class QgsProcessingOutputLayerDefinition
{
%Docstring

Encapsulates settings relating to a feature sink input to a processing algorithm.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.

.. versionadded:: 3.0
%End
@@ -70,35 +70,35 @@ class QgsProcessingFeatureSinkDefinition
%End
public:

QgsProcessingFeatureSinkDefinition( const QString &sink = QString(), QgsProject *destinationProject = 0 );
QgsProcessingOutputLayerDefinition( const QString &sink = QString(), QgsProject *destinationProject = 0 );
%Docstring
Constructor for QgsProcessingFeatureSinkDefinition, accepting a static string sink.
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
The ``destinationProject`` parameter can be set to a QgsProject instance in which
to automatically load the resulting sink after completing processing.
to automatically load the resulting sink/layer after completing processing.
%End

QgsProcessingFeatureSinkDefinition( const QgsProperty &sink, QgsProject *destinationProject = 0 );
QgsProcessingOutputLayerDefinition( const QgsProperty &sink, QgsProject *destinationProject = 0 );
%Docstring
Constructor for QgsProcessingFeatureSinkDefinition, accepting a QgsProperty sink.
Constructor for QgsProcessingOutputLayerDefinition, accepting a QgsProperty sink/layer.
The ``destinationProject`` parameter can be set to a QgsProject instance in which
to automatically load the resulting sink after completing processing.
to automatically load the resulting sink/layer after completing processing.
%End

QgsProperty sink;
%Docstring
Sink definition. Usually a static property set to the destination file name for the sink's layer.
Sink/layer definition. Usually a static property set to the destination file name for the sink's layer.
%End

QgsProject *destinationProject;
%Docstring
Destination project. Can be set to a QgsProject instance in which
to automatically load the resulting sink after completing processing.
to automatically load the resulting sink/layer after completing processing.
The default behavior is not to load the result into any project (None).
%End

QVariantMap createOptions;
%Docstring
Map of optional sink creation options, which
Map of optional sink/layer creation options, which
are passed to the underlying provider when creating new layers. Known options also
include 'fileEncoding', which is used to specify a file encoding to use for created
files.
@@ -35,7 +35,7 @@
QgsMessageLog,
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer,
QgsProcessingFeatureSinkDefinition,
QgsProcessingOutputLayerDefinition,
QgsProcessingParameterFeatureSink,
QgsProcessingAlgorithm)
from qgis.gui import QgsMessageBar
@@ -39,7 +39,7 @@
QgsExpression,
QgsSettings,
QgsProcessingParameterFeatureSink,
QgsProcessingFeatureSinkDefinition)
QgsProcessingOutputLayerDefinition)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.outputs import OutputVector
from processing.core.outputs import OutputDirectory
@@ -234,6 +234,6 @@ def getValue(self):
key = 'memory:'
else:
key = self.leText.text()
value = QgsProcessingFeatureSinkDefinition(key)
value = QgsProcessingOutputLayerDefinition(key)
value.createOptions = {'fileEncoding': self.encoding}
return value
@@ -215,10 +215,10 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar

QgsProject *destinationProject = nullptr;
QVariantMap createOptions;
if ( val.canConvert<QgsProcessingFeatureSinkDefinition>() )
if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
{
// input is a QgsProcessingFeatureSinkDefinition - get extra properties from it
QgsProcessingFeatureSinkDefinition fromVar = qvariant_cast<QgsProcessingFeatureSinkDefinition>( val );
// input is a QgsProcessingOutputLayerDefinition - get extra properties from it
QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
destinationProject = fromVar.destinationProject;
createOptions = fromVar.createOptions;
val = fromVar.sink;
@@ -1323,9 +1323,9 @@ bool QgsProcessingParameterFeatureSink::checkValueIsAcceptable( const QVariant &
if ( !var.isValid() )
return mFlags & FlagOptional;

if ( var.canConvert<QgsProcessingFeatureSinkDefinition>() )
if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
{
QgsProcessingFeatureSinkDefinition fromVar = qvariant_cast<QgsProcessingFeatureSinkDefinition>( var );
QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
var = fromVar.sink;
}

@@ -83,52 +83,52 @@ class CORE_EXPORT QgsProcessingFeatureSourceDefinition
Q_DECLARE_METATYPE( QgsProcessingFeatureSourceDefinition )

/**
* \class QgsProcessingFeatureSinkDefinition
* \class QgsProcessingOutputLayerDefinition
* \ingroup core
*
* Encapsulates settings relating to a feature sink input to a processing algorithm.
* Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
*
* \since QGIS 3.0
*/

class CORE_EXPORT QgsProcessingFeatureSinkDefinition
class CORE_EXPORT QgsProcessingOutputLayerDefinition
{
public:

/**
* Constructor for QgsProcessingFeatureSinkDefinition, accepting a static string sink.
* Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
* The \a destinationProject parameter can be set to a QgsProject instance in which
* to automatically load the resulting sink after completing processing.
* to automatically load the resulting sink/layer after completing processing.
*/
QgsProcessingFeatureSinkDefinition( const QString &sink = QString(), QgsProject *destinationProject = nullptr )
QgsProcessingOutputLayerDefinition( const QString &sink = QString(), QgsProject *destinationProject = nullptr )
: sink( QgsProperty::fromValue( sink ) )
, destinationProject( destinationProject )
{}

/**
* Constructor for QgsProcessingFeatureSinkDefinition, accepting a QgsProperty sink.
* Constructor for QgsProcessingOutputLayerDefinition, accepting a QgsProperty sink/layer.
* The \a destinationProject parameter can be set to a QgsProject instance in which
* to automatically load the resulting sink after completing processing.
* to automatically load the resulting sink/layer after completing processing.
*/
QgsProcessingFeatureSinkDefinition( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
QgsProcessingOutputLayerDefinition( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
: sink( sink )
, destinationProject( destinationProject )
{}

/**
* Sink definition. Usually a static property set to the destination file name for the sink's layer.
* Sink/layer definition. Usually a static property set to the destination file name for the sink's layer.
*/
QgsProperty sink;

/**
* Destination project. Can be set to a QgsProject instance in which
* to automatically load the resulting sink after completing processing.
* to automatically load the resulting sink/layer after completing processing.
* The default behavior is not to load the result into any project (nullptr).
*/
QgsProject *destinationProject;

/**
* Map of optional sink creation options, which
* Map of optional sink/layer creation options, which
* are passed to the underlying provider when creating new layers. Known options also
* include 'fileEncoding', which is used to specify a file encoding to use for created
* files.
@@ -144,7 +144,7 @@ class CORE_EXPORT QgsProcessingFeatureSinkDefinition

};

Q_DECLARE_METATYPE( QgsProcessingFeatureSinkDefinition )
Q_DECLARE_METATYPE( QgsProcessingOutputLayerDefinition )



@@ -131,7 +131,7 @@ void QgsApplication::init( QString customConfigPath )

qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" );
qRegisterMetaType<QgsProcessingFeatureSinkDefinition>( "QgsProcessingFeatureSinkDefinition" );
qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" );

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
// QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );
@@ -1151,7 +1151,7 @@ void TestQgsProcessing::parameters()

// QgsProcessingFeatureSinkDefinition as parameter
QgsProject p;
QgsProcessingFeatureSinkDefinition fs( QStringLiteral( "test.shp" ) );
QgsProcessingOutputLayerDefinition fs( QStringLiteral( "test.shp" ) );
fs.destinationProject = &p;
QVERIFY( context.layersToLoadOnCompletion().isEmpty() );
params.insert( QStringLiteral( "fs" ), QVariant::fromValue( fs ) );
@@ -2272,7 +2272,7 @@ void TestQgsProcessing::parameterFeatureSink()
QVERIFY( def->checkValueIsAcceptable( "layer12312312" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSinkDefinition( "layer1231123" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );

// should be OK with or without context - it's an output layer!
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
@@ -2287,7 +2287,7 @@ void TestQgsProcessing::parameterFeatureSink()
QVERIFY( def->checkValueIsAcceptable( "c:/Users/admin/Desktop/roads_clipped_transformed_v1_reprojected_final_clipped_aAAA.shp" ) );
QVERIFY( def->checkValueIsAcceptable( "" ) );
QVERIFY( def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSinkDefinition( "layer1231123" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( "layer1231123" ) ) );

// test hasGeometry
QVERIFY( QgsProcessingParameterFeatureSink( "test", QString(), QgsProcessingParameterDefinition::TypeAny ).hasGeometry() );
@@ -2391,15 +2391,15 @@ void TestQgsProcessing::processingFeatureSink()
{
QString sinkString( QStringLiteral( "test.shp" ) );
QgsProject p;
QgsProcessingFeatureSinkDefinition fs( sinkString, &p );
QgsProcessingOutputLayerDefinition fs( sinkString, &p );
QCOMPARE( fs.sink.staticValue().toString(), sinkString );
QCOMPARE( fs.destinationProject, &p );

// test storing QgsProcessingFeatureSink in variant and retrieving
QVariant fsInVariant = QVariant::fromValue( fs );
QVERIFY( fsInVariant.isValid() );

QgsProcessingFeatureSinkDefinition fromVar = qvariant_cast<QgsProcessingFeatureSinkDefinition>( fsInVariant );
QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( fsInVariant );
QCOMPARE( fromVar.sink.staticValue().toString(), sinkString );
QCOMPARE( fromVar.destinationProject, &p );

@@ -2410,7 +2410,7 @@ void TestQgsProcessing::processingFeatureSink()
// first using static string definition
QgsProcessingParameterDefinition *def = new QgsProcessingParameterString( QStringLiteral( "layer" ) );
QVariantMap params;
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSinkDefinition( "memory:test", nullptr ) );
params.insert( QStringLiteral( "layer" ), QgsProcessingOutputLayerDefinition( "memory:test", nullptr ) );
QString dest;
std::unique_ptr< QgsFeatureSink > sink( QgsProcessingParameters::parameterAsSink( def, params, QgsFields(), QgsWkbTypes::Point, QgsCoordinateReferenceSystem( "EPSG:3111" ), context, dest ) );
QVERIFY( sink.get() );
@@ -2419,7 +2419,7 @@ void TestQgsProcessing::processingFeatureSink()
QCOMPARE( layer->crs().authid(), QStringLiteral( "EPSG:3111" ) );

// next using property based definition
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSinkDefinition( QgsProperty::fromExpression( QStringLiteral( "trim('memory' + ':test2')" ) ), nullptr ) );
params.insert( QStringLiteral( "layer" ), QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( QStringLiteral( "trim('memory' + ':test2')" ) ), nullptr ) );
sink.reset( QgsProcessingParameters::parameterAsSink( def, params, QgsFields(), QgsWkbTypes::Point, QgsCoordinateReferenceSystem( "EPSG:3113" ), context, dest ) );
QVERIFY( sink.get() );
QgsVectorLayer *layer2 = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( dest, context, false ) );

0 comments on commit b75a174

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