Skip to content
Permalink
Browse files

Merge pull request #4715 from nyalldawson/processing_pt31

[processing] Bring back iterating mode for algorithms
  • Loading branch information
nyalldawson committed Jun 12, 2017
2 parents 40cae29 + 63611b1 commit 492ad2db0873bf707ba5f8f4b221697386a5d572
@@ -255,6 +255,16 @@ class QgsProcessingAlgorithm
:rtype: bool
%End

virtual QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const;
%Docstring
Returns a Python command string which can be executed to run the algorithm
using the specified ``parameters``.

Algorithms which cannot be run from a Python command should return an empty
string.
:rtype: str
%End

protected:

bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
@@ -288,6 +288,14 @@ class QgsProcessingParameterDefinition
:rtype: bool
%End

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
%Docstring
Returns a string version of the parameter input ``value``, which is suitable for use as an input
parameter value when running an algorithm directly from a Python command.
The returned value must be correctly escaped - e.g. string values must be wrapped in ' 's.
:rtype: str
%End

protected:


@@ -517,6 +525,8 @@ class QgsProcessingParameterBoolean : QgsProcessingParameterDefinition
%End

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

};

class QgsProcessingParameterCrs : QgsProcessingParameterDefinition
@@ -540,6 +550,8 @@ class QgsProcessingParameterCrs : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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

};

class QgsProcessingParameterMapLayer : QgsProcessingParameterDefinition
@@ -563,6 +575,8 @@ class QgsProcessingParameterMapLayer : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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

};

class QgsProcessingParameterExtent : QgsProcessingParameterDefinition
@@ -586,6 +600,8 @@ class QgsProcessingParameterExtent : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


};

@@ -693,6 +709,8 @@ class QgsProcessingParameterMatrix : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QStringList headers() const;
%Docstring
@@ -763,6 +781,8 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QgsProcessingParameterDefinition::LayerType layerType() const;
%Docstring
@@ -826,6 +846,8 @@ class QgsProcessingParameterNumber : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


double minimum() const;
%Docstring
@@ -891,6 +913,8 @@ class QgsProcessingParameterRange : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QgsProcessingParameterNumber::Type dataType() const;
%Docstring
@@ -928,6 +952,8 @@ class QgsProcessingParameterRasterLayer : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


};

@@ -954,6 +980,8 @@ class QgsProcessingParameterEnum : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QStringList options() const;
%Docstring
@@ -1003,6 +1031,8 @@ class QgsProcessingParameterString : QgsProcessingParameterDefinition
%End

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


bool multiLine() const;
%Docstring
@@ -1039,6 +1069,8 @@ class QgsProcessingParameterExpression : QgsProcessingParameterDefinition
%End

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


QString parentLayerParameter() const;
%Docstring
@@ -1109,6 +1141,8 @@ class QgsProcessingParameterTableField : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QString parentLayerParameter() const;
%Docstring
@@ -1173,6 +1207,8 @@ class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition
virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QList< int > dataTypes() const;
%Docstring
@@ -1214,6 +1250,8 @@ class QgsProcessingParameterFeatureSink : QgsProcessingParameterDefinition
virtual bool isDestination() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QgsProcessingParameterDefinition::LayerType dataType() const;
%Docstring
@@ -1260,6 +1298,8 @@ class QgsProcessingParameterRasterOutput : QgsProcessingParameterDefinition
virtual bool isDestination() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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

};

class QgsProcessingParameterFileOutput : QgsProcessingParameterDefinition
@@ -1286,6 +1326,8 @@ class QgsProcessingParameterFileOutput : QgsProcessingParameterDefinition
virtual bool isDestination() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

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


QString fileFilter() const;
%Docstring
@@ -126,6 +126,15 @@ class QgsProcessingUtils
:rtype: QgsRectangle
%End

static QVariant generateIteratingDestination( const QVariant &input, const QVariant &id, QgsProcessingContext &context );
%Docstring
Converts an ``input`` parameter value for use in source iterating mode, where one individual sink
is created per input feature.
The ``id`` parameter represents the unique ID for this output, which is embedded into the resulting
parameter value.
:rtype: QVariant
%End

};


@@ -224,9 +224,9 @@ def accept(self):
parameters = self.getParamValues()
if parameters:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
ProcessingLog.addToLog(self.alg.getAsCommand())

context = dataobjects.createContext()
ProcessingLog.addToLog(self.alg.asPythonCommand(parameters, context))

self.executed, results = execute(self.alg, parameters, context, self.feedback)
if self.executed:
handleAlgorithmResults(self.alg,
@@ -301,23 +301,6 @@ def getOutputValue(self, name):
return out.value
return None

def getAsCommand(self):
"""Returns the command that would run this same algorithm from
the console.
Should return None if the algorithm cannot be run from the
console.
"""

s = 'processing.run("' + self.id() + '",'
for param in self.parameterDefinitions():
s += param.getValueAsCommandLineParameter() + ','
for out in self.outputs:
if not out.flags() & QgsProcessingParameterDefinition.FlagHidden:
s += out.getValueAsCommandLineParameter() + ','
s = s[:-1] + ')'
return s

def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
@@ -139,13 +139,8 @@ def runAlgorithm(algOrName, onFinish, *args, **kwargs):
for (name, value) in list(args[0].items()):
param = alg.parameterDefinition(name)
if param:
# TODO
# and param.setValue(value):
parameters[param.name()] = value
continue
output = alg.getOutputFromName(name)
if output and output.setValue(value):
continue
# fix_print_with_import
print('Error: Wrong parameter value %s for parameter %s.' % (value, name))
QgsMessageLog.logMessage(
@@ -249,7 +244,7 @@ def runAlgorithm(algOrName, onFinish, *args, **kwargs):
QApplication.restoreOverrideCursor()
if isinstance(feedback, MessageBarProgress):
feedback.close()
return alg
return results

@staticmethod
def tr(string, context=''):

0 comments on commit 492ad2d

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