Skip to content
Permalink
Browse files

Rename QgsProcessingFeatureSink to QgsProcessingFeatureSinkDefinition

For consistency with QgsProcessingFeatureSourceDefinition
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 81da209 commit 77072b15ac2998e81158211c724c050f6f5af369
@@ -56,7 +56,7 @@ Allows direct construction of QVariants.



class QgsProcessingFeatureSink
class QgsProcessingFeatureSinkDefinition
{
%Docstring

@@ -70,16 +70,16 @@ class QgsProcessingFeatureSink
%End
public:

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

QgsProcessingFeatureSink( const QgsProperty &sink, QgsProject *destinationProject = 0 );
QgsProcessingFeatureSinkDefinition( const QgsProperty &sink, QgsProject *destinationProject = 0 );
%Docstring
Constructor for QgsProcessingFeatureSink, accepting a QgsProperty sink.
Constructor for QgsProcessingFeatureSinkDefinition, accepting a QgsProperty sink.
The ``destinationProject`` parameter can be set to a QgsProject instance in which
to automatically load the resulting sink after completing processing.
%End
@@ -35,7 +35,7 @@
QgsMessageLog,
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer,
QgsProcessingFeatureSink,
QgsProcessingFeatureSinkDefinition,
QgsProcessingParameterFeatureSink)
from qgis.gui import QgsMessageBar
from qgis.utils import iface
@@ -116,7 +116,7 @@ def getParamValues(self):
if self.mainWidget.checkBoxes[param.name()].isChecked():
dest_project = QgsProject.instance()

parameters[param.name()] = QgsProcessingFeatureSink(self.mainWidget.outputWidgets[param.name()].getValue(), dest_project)
parameters[param.name()] = QgsProcessingFeatureSinkDefinition(self.mainWidget.outputWidgets[param.name()].getValue(), dest_project)

return parameters

@@ -215,10 +215,10 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar

QgsProject *destinationProject = nullptr;
QVariantMap createOptions;
if ( val.canConvert<QgsProcessingFeatureSink>() )
if ( val.canConvert<QgsProcessingFeatureSinkDefinition>() )
{
// input is a QgsProcessingFeatureSink - get extra properties from it
QgsProcessingFeatureSink fromVar = qvariant_cast<QgsProcessingFeatureSink>( val );
// input is a QgsProcessingFeatureSinkDefinition - get extra properties from it
QgsProcessingFeatureSinkDefinition fromVar = qvariant_cast<QgsProcessingFeatureSinkDefinition>( 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<QgsProcessingFeatureSink>() )
if ( var.canConvert<QgsProcessingFeatureSinkDefinition>() )
{
QgsProcessingFeatureSink fromVar = qvariant_cast<QgsProcessingFeatureSink>( var );
QgsProcessingFeatureSinkDefinition fromVar = qvariant_cast<QgsProcessingFeatureSinkDefinition>( var );
var = fromVar.sink;
}

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

/**
* \class QgsProcessingFeatureSink
* \class QgsProcessingFeatureSinkDefinition
* \ingroup core
*
* Encapsulates settings relating to a feature sink input to a processing algorithm.
*
* \since QGIS 3.0
*/

class CORE_EXPORT QgsProcessingFeatureSink
class CORE_EXPORT QgsProcessingFeatureSinkDefinition
{
public:

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

/**
* Constructor for QgsProcessingFeatureSink, accepting a QgsProperty sink.
* Constructor for QgsProcessingFeatureSinkDefinition, accepting a QgsProperty sink.
* The \a destinationProject parameter can be set to a QgsProject instance in which
* to automatically load the resulting sink after completing processing.
*/
QgsProcessingFeatureSink( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
QgsProcessingFeatureSinkDefinition( const QgsProperty &sink, QgsProject *destinationProject = nullptr )
: sink( sink )
, destinationProject( destinationProject )
{}
@@ -144,7 +144,7 @@ class CORE_EXPORT QgsProcessingFeatureSink

};

Q_DECLARE_METATYPE( QgsProcessingFeatureSink )
Q_DECLARE_METATYPE( QgsProcessingFeatureSinkDefinition )



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

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

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
// QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );
@@ -1147,9 +1147,9 @@ void TestQgsProcessing::parameters()
QCOMPARE( layer->wkbType(), wkbType );
QCOMPARE( layer->crs(), crs );

// QgsProcessingFeatureSink as parameter
// QgsProcessingFeatureSinkDefinition as parameter
QgsProject p;
QgsProcessingFeatureSink fs( QStringLiteral( "test.shp" ) );
QgsProcessingFeatureSinkDefinition fs( QStringLiteral( "test.shp" ) );
fs.destinationProject = &p;
QVERIFY( context.layersToLoadOnCompletion().isEmpty() );
params.insert( QStringLiteral( "fs" ), QVariant::fromValue( fs ) );
@@ -2270,7 +2270,7 @@ void TestQgsProcessing::parameterFeatureSink()
QVERIFY( def->checkValueIsAcceptable( "layer12312312" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSink( "layer1231123" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSinkDefinition( "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" ) );
@@ -2285,7 +2285,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( QgsProcessingFeatureSink( "layer1231123" ) ) );
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSinkDefinition( "layer1231123" ) ) );
}

void TestQgsProcessing::checkParamValues()
@@ -2378,15 +2378,15 @@ void TestQgsProcessing::processingFeatureSink()
{
QString sinkString( QStringLiteral( "test.shp" ) );
QgsProject p;
QgsProcessingFeatureSink fs( sinkString, &p );
QgsProcessingFeatureSinkDefinition 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() );

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

@@ -2397,7 +2397,7 @@ void TestQgsProcessing::processingFeatureSink()
// first using static string definition
QgsProcessingParameterDefinition *def = new QgsProcessingParameterString( QStringLiteral( "layer" ) );
QVariantMap params;
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSink( "memory:test", nullptr ) );
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSinkDefinition( "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() );
@@ -2406,7 +2406,7 @@ void TestQgsProcessing::processingFeatureSink()
QCOMPARE( layer->crs().authid(), QStringLiteral( "EPSG:3111" ) );

// next using property based definition
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSink( QgsProperty::fromExpression( QStringLiteral( "trim('memory' + ':test2')" ) ), nullptr ) );
params.insert( QStringLiteral( "layer" ), QgsProcessingFeatureSinkDefinition( 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 77072b1

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