Skip to content
Permalink
Browse files

Add clone method to QgsProcessingModelComponent

  • Loading branch information
nyalldawson committed Mar 2, 2020
1 parent 16841ef commit d9cc2aedeb0322378ce6c13eec1150a4fd7191f6
@@ -32,6 +32,9 @@ should be set to a QgsProcessingAlgorithm algorithm ID.

QgsProcessingModelChildAlgorithm( const QgsProcessingModelChildAlgorithm &other );

virtual QgsProcessingModelChildAlgorithm *clone() /Factory/;


QString childId() const;
%Docstring
Returns the child algorithm's unique ID string, used the identify
@@ -23,6 +23,8 @@ Represents a component of a model algorithm.
%End
public:

virtual ~QgsProcessingModelComponent();

QString description() const;
%Docstring
Returns the friendly description text for the component.
@@ -49,6 +51,13 @@ Returns the position of the model component within the graphical modeler.
Sets the ``position`` of the model component within the graphical modeler.

.. seealso:: :py:func:`position`
%End

virtual QgsProcessingModelComponent *clone() = 0 /Factory/;
%Docstring
Clones the component.

Ownership is transferred to the caller.
%End

protected:
@@ -28,6 +28,9 @@ Represents a final output created by the model.
Constructor for QgsProcessingModelOutput with the specified ``name`` and ``description``.
%End

virtual QgsProcessingModelOutput *clone() /Factory/;


QString name() const;
%Docstring
Returns the model output name.
@@ -30,6 +30,9 @@ Constructor for QgsProcessingModelParameter. The parameter name should match one
parameters from the parent model.
%End

virtual QgsProcessingModelParameter *clone() /Factory/;


QString parameterName() const;
%Docstring
Returns the associated parameter name. The parameter name should match one of the
@@ -56,6 +56,11 @@ QgsProcessingModelChildAlgorithm &QgsProcessingModelChildAlgorithm::operator=( c
return *this;
}

QgsProcessingModelChildAlgorithm *QgsProcessingModelChildAlgorithm::clone()
{
return new QgsProcessingModelChildAlgorithm( *this );
}

const QgsProcessingAlgorithm *QgsProcessingModelChildAlgorithm::algorithm() const
{
return mAlgorithm.get();
@@ -48,6 +48,8 @@ class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelCo
QgsProcessingModelChildAlgorithm( const QgsProcessingModelChildAlgorithm &other );
QgsProcessingModelChildAlgorithm &operator=( const QgsProcessingModelChildAlgorithm &other );

QgsProcessingModelChildAlgorithm *clone() override SIP_FACTORY;

/**
* Returns the child algorithm's unique ID string, used the identify
* this child algorithm within its parent model.
@@ -33,6 +33,8 @@ class CORE_EXPORT QgsProcessingModelComponent
{
public:

virtual ~QgsProcessingModelComponent() = default;

/**
* Returns the friendly description text for the component.
* \see setDescription()
@@ -57,6 +59,13 @@ class CORE_EXPORT QgsProcessingModelComponent
*/
void setPosition( QPointF position );

/**
* Clones the component.
*
* Ownership is transferred to the caller.
*/
virtual QgsProcessingModelComponent *clone() = 0 SIP_FACTORY;

protected:

//! Only subclasses can be created
@@ -24,6 +24,11 @@ QgsProcessingModelOutput::QgsProcessingModelOutput( const QString &name, const Q
, mName( name )
{}

QgsProcessingModelOutput *QgsProcessingModelOutput::clone()
{
return new QgsProcessingModelOutput( *this );
}

QVariant QgsProcessingModelOutput::toVariant() const
{
QVariantMap map;
@@ -39,6 +39,8 @@ class CORE_EXPORT QgsProcessingModelOutput : public QgsProcessingModelComponent
*/
QgsProcessingModelOutput( const QString &name = QString(), const QString &description = QString() );

QgsProcessingModelOutput *clone() override SIP_FACTORY;

/**
* Returns the model output name.
* \see setName()
@@ -25,6 +25,11 @@ QgsProcessingModelParameter::QgsProcessingModelParameter( const QString &paramet

}

QgsProcessingModelParameter *QgsProcessingModelParameter::clone()
{
return new QgsProcessingModelParameter( *this );
}

QVariant QgsProcessingModelParameter::toVariant() const
{
QVariantMap map;
@@ -40,6 +40,8 @@ class CORE_EXPORT QgsProcessingModelParameter : public QgsProcessingModelCompone
*/
QgsProcessingModelParameter( const QString &parameterName = QString() );

QgsProcessingModelParameter *clone() override SIP_FACTORY;

/**
* Returns the associated parameter name. The parameter name should match one of the
* parameters from the parent model.
@@ -7705,6 +7705,9 @@ void TestQgsProcessing::modelerAlgorithm()

QCOMPARE( child.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, extraParams, 4, 2, friendlyNames, friendlyOutputNames ).join( '\n' ), QStringLiteral( " # desc\n alg_params = {\n 'a': 5,\n 'b': [7,9],\n 'SOMETHING': SOMETHING_ELSE,\n 'SOMETHING2': SOMETHING_ELSE2\n }\n outputs['my_id'] = processing.run('native:centroids', alg_params, context=context, feedback=feedback, is_child_algorithm=True)" ) );

std::unique_ptr< QgsProcessingModelChildAlgorithm > childClone( child.clone() );
QCOMPARE( childClone->toVariant(), child.toVariant() );

QgsProcessingModelOutput testModelOut;
testModelOut.setChildId( QStringLiteral( "my_id" ) );
QCOMPARE( testModelOut.childId(), QStringLiteral( "my_id" ) );
@@ -7714,6 +7717,8 @@ void TestQgsProcessing::modelerAlgorithm()
QCOMPARE( testModelOut.defaultValue().toString(), QStringLiteral( "my_value" ) );
testModelOut.setMandatory( true );
QVERIFY( testModelOut.isMandatory() );
std::unique_ptr< QgsProcessingModelOutput > outputClone( testModelOut.clone() );
QCOMPARE( outputClone->toVariant(), testModelOut.toVariant() );

QgsProcessingOutputLayerDefinition layerDef( QStringLiteral( "my_path" ) );
layerDef.createOptions["fileEncoding"] = QStringLiteral( "my_encoding" );
@@ -7841,6 +7846,8 @@ void TestQgsProcessing::modelerAlgorithm()
QgsProcessingModelParameter pc1;
pc1.setParameterName( QStringLiteral( "my_param" ) );
QCOMPARE( pc1.parameterName(), QStringLiteral( "my_param" ) );
std::unique_ptr< QgsProcessingModelParameter > paramClone( pc1.clone() );
QCOMPARE( paramClone->toVariant(), pc1.toVariant() );
pComponents.insert( QStringLiteral( "my_param" ), pc1 );
alg.setParameterComponents( pComponents );
QCOMPARE( alg.parameterComponents().count(), 1 );

0 comments on commit d9cc2ae

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