Skip to content
Permalink
Browse files

Rename QgsProcessingAlgorithm::clone to ::create

Since it better describes what the function does. It returns a new
pristine copy of the algorithm, not a clone of its current state
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent cd7776c commit e0c7daa2d88c6e91d1b6674b2518b3180e711d2f
@@ -44,9 +44,9 @@ class QgsProcessingAlgorithm



virtual QgsProcessingAlgorithm *clone() const = 0 /Factory/;
virtual QgsProcessingAlgorithm *create() const = 0 /Factory/;
%Docstring
Clones the algorithm, returning a new copy for safe use in background threads.
Creates a copy of the algorithm, ready for execution.
:rtype: QgsProcessingAlgorithm
%End

@@ -588,7 +588,7 @@ Copies are protected to avoid slicing

virtual QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const;

virtual QgsProcessingModelAlgorithm *clone() const /Factory/;
virtual QgsProcessingModelAlgorithm *create() const /Factory/;


void setName( const QString &name );
@@ -48,5 +48,5 @@ def trAlgorithm(self, string, context=''):
context = self.__class__.__name__
return string, QCoreApplication.translate(context, string)

def clone(self):
def create(self):
return type(self)()
@@ -237,7 +237,7 @@ def _mimeDataAlgorithm(items):
self.mActionRun.triggered.connect(self.runModel)

if model is not None:
self.model = model.clone()
self.model = model.create()
self.model.setSourceFilePath(model.sourceFilePath())
self.textGroup.setText(self.model.group())
self.textName.setText(self.model.displayName())
@@ -79,7 +79,7 @@ def __init__(self, descriptionFile, script=None):
self.cleaned_script = None
self.results = {}

def clone(self):
def create(self):
return ScriptAlgorithm(self.descriptionFile)

def icon(self):
@@ -48,7 +48,7 @@ def name(self):
def displayName(self):
return 'testalg'

def clone(self):
def create(self):
return TestAlg()

def processAlgorithm(self, parameters, context, feedback):
@@ -84,7 +84,7 @@ QString QgsCentroidAlgorithm::shortHelpString() const
"The attributes associated to each point in the output layer are the same ones associated to the original features." );
}

QgsCentroidAlgorithm *QgsCentroidAlgorithm::clone() const
QgsCentroidAlgorithm *QgsCentroidAlgorithm::create() const
{
return new QgsCentroidAlgorithm();
}
@@ -174,7 +174,7 @@ QString QgsBufferAlgorithm::shortHelpString() const
"The mitre limit parameter is only applicable for mitre join styles, and controls the maximum distance from the offset curve to use when creating a mitred join." );
}

QgsBufferAlgorithm *QgsBufferAlgorithm::clone() const
QgsBufferAlgorithm *QgsBufferAlgorithm::create() const
{
return new QgsBufferAlgorithm();
}
@@ -299,7 +299,7 @@ QString QgsDissolveAlgorithm::shortHelpString() const
"In case the input is a polygon layer, common boundaries of adjacent polygons being dissolved will get erased." );
}

QgsDissolveAlgorithm *QgsDissolveAlgorithm::clone() const
QgsDissolveAlgorithm *QgsDissolveAlgorithm::create() const
{
return new QgsDissolveAlgorithm();
}
@@ -458,7 +458,7 @@ QString QgsClipAlgorithm::shortHelpString() const
"be manually updated." );
}

QgsClipAlgorithm *QgsClipAlgorithm::clone() const
QgsClipAlgorithm *QgsClipAlgorithm::create() const
{
return new QgsClipAlgorithm();
}
@@ -620,7 +620,7 @@ QString QgsTransformAlgorithm::shortHelpString() const
"Attributes are not modified by this algorithm." );
}

QgsTransformAlgorithm *QgsTransformAlgorithm::clone() const
QgsTransformAlgorithm *QgsTransformAlgorithm::create() const
{
return new QgsTransformAlgorithm();
}
@@ -699,7 +699,7 @@ QString QgsSubdivideAlgorithm::shortHelpString() const
"Curved geometries will be segmentized before subdivision." );
}

QgsSubdivideAlgorithm *QgsSubdivideAlgorithm::clone() const
QgsSubdivideAlgorithm *QgsSubdivideAlgorithm::create() const
{
return new QgsSubdivideAlgorithm();
}
@@ -779,7 +779,7 @@ QString QgsMultipartToSinglepartAlgorithm::shortHelpString() const
"contain, and the same attributes are used for each of them." );
}

QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::clone() const
QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::create() const
{
return new QgsMultipartToSinglepartAlgorithm();
}
@@ -876,7 +876,7 @@ QString QgsExtractByExpressionAlgorithm::shortHelpString() const
"For more information about expressions see the <a href =\"{qgisdocs}/user_manual/working_with_vector/expression.html\">user manual</a>" );
}

QgsExtractByExpressionAlgorithm *QgsExtractByExpressionAlgorithm::clone() const
QgsExtractByExpressionAlgorithm *QgsExtractByExpressionAlgorithm::create() const
{
return new QgsExtractByExpressionAlgorithm();
}
@@ -1017,7 +1017,7 @@ QString QgsExtractByAttributeAlgorithm::shortHelpString() const
"of an attribute from the input layer." );
}

QgsExtractByAttributeAlgorithm *QgsExtractByAttributeAlgorithm::clone() const
QgsExtractByAttributeAlgorithm *QgsExtractByAttributeAlgorithm::create() const
{
return new QgsExtractByAttributeAlgorithm();
}
@@ -60,7 +60,7 @@ class QgsCentroidAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "centroid,center,average,point,middle" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry tools" ); }
QString shortHelpString() const override;
QgsCentroidAlgorithm *clone() const override SIP_FACTORY;
QgsCentroidAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -91,7 +91,7 @@ class QgsTransformAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "transform,reproject,crs,srs,warp" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector general tools" ); }
QString shortHelpString() const override;
QgsTransformAlgorithm *clone() const override SIP_FACTORY;
QgsTransformAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -123,7 +123,7 @@ class QgsBufferAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "buffer,grow" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry tools" ); }
QString shortHelpString() const override;
QgsBufferAlgorithm *clone() const override SIP_FACTORY;
QgsBufferAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -166,7 +166,7 @@ class QgsDissolveAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "dissolve,union,combine,collect" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry tools" ); }
QString shortHelpString() const override;
QgsDissolveAlgorithm *clone() const override SIP_FACTORY;
QgsDissolveAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -214,7 +214,7 @@ class QgsExtractByAttributeAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "extract,filter,attribute,value,contains,null,field" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector selection tools" ); }
QString shortHelpString() const override;
QgsExtractByAttributeAlgorithm *clone() const override SIP_FACTORY;
QgsExtractByAttributeAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -251,7 +251,7 @@ class QgsExtractByExpressionAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "extract,filter,expression,field" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector selection tools" ); }
QString shortHelpString() const override;
QgsExtractByExpressionAlgorithm *clone() const override SIP_FACTORY;
QgsExtractByExpressionAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -286,7 +286,7 @@ class QgsClipAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "clip,intersect,intersection,mask" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector overlay tools" ); }
QString shortHelpString() const override;
QgsClipAlgorithm *clone() const override SIP_FACTORY;
QgsClipAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -321,7 +321,7 @@ class QgsSubdivideAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "subdivide,segmentize,split,tesselate" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry tools" ); }
QString shortHelpString() const override;
QgsSubdivideAlgorithm *clone() const override SIP_FACTORY;
QgsSubdivideAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -354,7 +354,7 @@ class QgsMultipartToSinglepartAlgorithm : public QgsProcessingAlgorithm
virtual QStringList tags() const override { return QObject::tr( "multi,single,multiple,split,dump" ).split( ',' ); }
QString group() const override { return QObject::tr( "Vector geometry tools" ); }
QString shortHelpString() const override;
QgsMultipartToSinglepartAlgorithm *clone() const override SIP_FACTORY;
QgsMultipartToSinglepartAlgorithm *create() const override SIP_FACTORY;

protected:

@@ -321,7 +321,7 @@ bool QgsProcessingAlgorithm::hasHtmlOutputs() const

QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok ) const
{
std::unique_ptr< QgsProcessingAlgorithm > alg( clone() );
std::unique_ptr< QgsProcessingAlgorithm > alg( create() );
if ( ok )
*ok = false;

@@ -68,9 +68,9 @@ class CORE_EXPORT QgsProcessingAlgorithm
QgsProcessingAlgorithm &operator=( const QgsProcessingAlgorithm &other ) = delete;

/**
* Clones the algorithm, returning a new copy for safe use in background threads.
* Creates a copy of the algorithm, ready for execution.
*/
virtual QgsProcessingAlgorithm *clone() const = 0 SIP_FACTORY;
virtual QgsProcessingAlgorithm *create() const = 0 SIP_FACTORY;

/**
* Returns the algorithm name, used for identifying the algorithm. This string
@@ -27,7 +27,7 @@ QgsProcessingAlgRunnerTask::QgsProcessingAlgRunnerTask( const QgsProcessingAlgor
, mParameters( parameters )
, mContext( context )
, mFeedback( feedback )
, mAlgorithm( algorithm->clone() )
, mAlgorithm( algorithm->create() )
{
if ( !mFeedback )
{
@@ -524,7 +524,7 @@ bool QgsProcessingModelAlgorithm::processAlgorithm( QgsProcessingContext &contex
childTime.start();

bool ok = false;
std::unique_ptr< QgsProcessingAlgorithm > childAlg( child.algorithm()->clone() );
std::unique_ptr< QgsProcessingAlgorithm > childAlg( child.algorithm()->create() );
QVariantMap results = childAlg->run( childParams, context, feedback, &ok );
childAlg.reset( nullptr );
if ( !ok )
@@ -1115,7 +1115,7 @@ QString QgsProcessingModelAlgorithm::asPythonCommand( const QVariantMap &paramet
return QgsProcessingAlgorithm::asPythonCommand( parameters, context );
}

QgsProcessingModelAlgorithm *QgsProcessingModelAlgorithm::clone() const
QgsProcessingModelAlgorithm *QgsProcessingModelAlgorithm::create() const
{
QgsProcessingModelAlgorithm *alg = new QgsProcessingModelAlgorithm();
alg->loadVariant( toVariant() );
@@ -590,7 +590,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm

bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;
QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const override;
QgsProcessingModelAlgorithm *clone() const override SIP_FACTORY;
QgsProcessingModelAlgorithm *create() const override SIP_FACTORY;

/**
* Sets the model \a name.
@@ -47,7 +47,7 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QVariantMap postProcessAlgorithm( QgsProcessingContext &, QgsProcessingFeedback * ) override { return QVariantMap(); }

virtual Flags flags() const override { return mFlags; }
DummyAlgorithm *clone() const override { return new DummyAlgorithm( name() ); }
DummyAlgorithm *create() const override { return new DummyAlgorithm( name() ); }

QString mName;

0 comments on commit e0c7daa

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