Skip to content
Permalink
Browse files

[processing] Add API to convert a parameter definition to an equivalent

Python constructor string
  • Loading branch information
nyalldawson committed Jan 29, 2019
1 parent d4b262c commit 63b6a777026072045fa6f69e7887de654ca2458f
@@ -39,6 +39,11 @@ and parameters.
TypeMesh
};

enum PythonOutputType
{
PythonQgsProcessingAlgorithmSubclass,
};

static QString sourceTypeToString( SourceType type );
%Docstring
Converts a source ``type`` to a string representation.
@@ -303,7 +303,18 @@ The returned value must be correctly escaped - e.g. string values must be wrappe
virtual QString asScriptCode() const;
%Docstring
Returns the parameter definition encoded in a string which can be used within a
Python processing script.
Processing script.
%End

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;
%Docstring
Returns the parameter definition as a Python command which can be used within a
Python Processing script.

The ``outputType`` argument specifies the desired output format for the Python string,
i.e. the intended end use of the generated Python code.

.. versionadded:: 3.6
%End

virtual QVariantMap toVariantMap() const;
@@ -1172,6 +1183,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


Behavior behavior() const;
%Docstring
@@ -1245,6 +1258,8 @@ Returns the type name for the parameter class.

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QStringList headers() const;
%Docstring
@@ -1343,6 +1358,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QgsProcessing::SourceType layerType() const;
%Docstring
@@ -1440,6 +1457,8 @@ Returns the type name for the parameter class.

virtual QString toolTip() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


double minimum() const;
%Docstring
@@ -1542,6 +1561,8 @@ Returns the type name for the parameter class.

virtual QStringList dependsOnOtherParameters() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QString parentParameterName() const;
%Docstring
@@ -1614,6 +1635,8 @@ Returns the type name for the parameter class.

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QgsProcessingParameterNumber::Type dataType() const;
%Docstring
@@ -1713,6 +1736,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QStringList options() const;
%Docstring
@@ -1785,6 +1810,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


bool multiLine() const;
%Docstring
@@ -1887,6 +1914,8 @@ Returns the type name for the parameter class.

virtual QStringList dependsOnOtherParameters() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QString parentLayerParameterName() const;
%Docstring
@@ -1985,6 +2014,8 @@ Returns the type name for the parameter class.

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


virtual QVariantMap toVariantMap() const;

@@ -2080,6 +2111,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;

virtual QStringList dependsOnOtherParameters() const;


@@ -2171,6 +2204,8 @@ Returns the type name for the parameter class.

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


virtual QVariantMap toVariantMap() const;

@@ -2212,6 +2247,8 @@ output will not be created by default.

virtual bool fromVariantMap( const QVariantMap &map );

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


virtual QgsProcessingOutputDefinition *toOutputDefinition() const = 0 /Factory/;
%Docstring
@@ -2321,6 +2358,8 @@ Returns the type name for the parameter class.

virtual QString defaultFileExtension() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


virtual QStringList supportedOutputVectorLayerExtensions() const;
%Docstring
@@ -2411,6 +2450,8 @@ Returns the type name for the parameter class.

virtual QString defaultFileExtension() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


virtual QStringList supportedOutputVectorLayerExtensions() const;
%Docstring
@@ -2551,6 +2592,8 @@ Returns the type name for the parameter class.

virtual QString defaultFileExtension() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QString fileFilter() const;
%Docstring
@@ -2658,6 +2701,8 @@ Returns the type name for the parameter class.

virtual QStringList dependsOnOtherParameters() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;


QString parentLayerParameterName() const;
%Docstring
@@ -23,6 +23,7 @@
#include "qgsexception.h"
#include "qgsvectorlayer.h"
#include "qgsapplication.h"
#include "qgsprocessingparametertype.h"

#include <QFile>
#include <QTextStream>
@@ -54,6 +54,12 @@ class CORE_EXPORT QgsProcessing
TypeMesh = 6 //!< Mesh layers \since QGIS 3.6
};

//! Available Python output types
enum PythonOutputType
{
PythonQgsProcessingAlgorithmSubclass, //!< Full Python QgsProcessingAlgorithm subclass
};

/**
* Converts a source \a type to a string representation.
*

0 comments on commit 63b6a77

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