26using namespace Qt::StringLiterals;
30bool QgsProcessingModelChildParameterSource::operator==(
const QgsProcessingModelChildParameterSource &other )
const
32 if ( mSource != other.mSource )
38 return mStaticValue == other.mStaticValue;
40 return mChildId == other.mChildId && mOutputName == other.mOutputName;
42 return mParameterName == other.mParameterName;
44 return mExpression == other.mExpression;
46 return mExpressionText == other.mExpressionText;
53QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromStaticValue(
const QVariant &value )
55 QgsProcessingModelChildParameterSource src;
57 src.mStaticValue = value;
61QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromModelParameter(
const QString ¶meterName )
63 QgsProcessingModelChildParameterSource src;
65 src.mParameterName = parameterName;
69QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromChildOutput(
const QString &childId,
const QString &outputName )
71 QgsProcessingModelChildParameterSource src;
73 src.mChildId = childId;
74 src.mOutputName = outputName;
78QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromExpression(
const QString &expression )
80 QgsProcessingModelChildParameterSource src;
82 src.mExpression = expression;
86QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromExpressionText(
const QString &text )
88 QgsProcessingModelChildParameterSource src;
90 src.mExpressionText = text;
104QVariant QgsProcessingModelChildParameterSource::toVariant()
const
107 map.insert( u
"source"_s,
static_cast< int >( mSource ) );
111 map.insert( u
"parameter_name"_s, mParameterName );
115 map.insert( u
"child_id"_s, mChildId );
116 map.insert( u
"output_name"_s, mOutputName );
120 map.insert( u
"static_value"_s, mStaticValue );
124 map.insert( u
"expression"_s, mExpression );
128 map.insert( u
"expression_text"_s, mExpressionText );
137bool QgsProcessingModelChildParameterSource::loadVariant(
const QVariantMap &map )
143 mParameterName = map.value( u
"parameter_name"_s ).toString();
147 mChildId = map.value( u
"child_id"_s ).toString();
148 mOutputName = map.value( u
"output_name"_s ).toString();
152 mStaticValue = map.value( u
"static_value"_s );
156 mExpression = map.value( u
"expression"_s ).toString();
160 mExpressionText = map.value( u
"expression_text"_s ).toString();
174 return u
"parameters['%1']"_s.arg( mParameterName );
177 return u
"outputs['%1']['%2']"_s.arg( friendlyChildNames.value( mChildId, mChildId ), mOutputName );
194 return mExpressionText;
227QString QgsProcessingModelChildParameterSource::friendlyIdentifier( QgsProcessingModelAlgorithm *model )
const
238 return paramDefinition->description();
242 return mParameterName;
248 const QgsProcessingModelChildAlgorithm &alg = model->childAlgorithm( mChildId );
249 QString outputName = alg.algorithm() && alg.algorithm()->outputDefinition( mOutputName ) ? alg.algorithm()->outputDefinition( mOutputName )->description() : mOutputName;
251 const QMap<QString, QgsProcessingModelOutput> outputs = alg.modelOutputs();
252 for (
auto it = outputs.constBegin(); it != outputs.constEnd(); ++it )
254 if ( it.value().childOutputName() == mOutputName )
256 outputName = it.key();
260 return QObject::tr(
"'%1' from algorithm '%2'" ).arg( outputName, alg.description() );
264 return QObject::tr(
"'%1' from algorithm '%2'" ).arg( mOutputName, mChildId );
269 return mStaticValue.toString();
275 return mExpressionText;
283QDataStream &
operator<<( QDataStream &out,
const QgsProcessingModelChildParameterSource &source )
285 out << static_cast< int >( source.source() );
286 out << source.staticValue();
287 out << source.parameterName();
288 out << source.outputChildId();
289 out << source.outputName();
290 out << source.expression();
291 out << source.expressionText();
295QDataStream &
operator>>( QDataStream &in, QgsProcessingModelChildParameterSource &source )
298 QVariant staticValue;
299 QString parameterName;
300 QString outputChildId;
303 QString expressionText;
305 in >> sourceType >> staticValue >> parameterName >> outputChildId >> outputName >> expression >> expressionText;
307 source.setStaticValue( staticValue );
308 source.setParameterName( parameterName );
309 source.setOutputChildId( outputChildId );
310 source.setOutputName( outputName );
311 source.setExpression( expression );
312 source.setExpressionText( expressionText );
ProcessingModelChildParameterSource
Processing model child parameter sources.
@ ExpressionText
Parameter value is taken from a text with expressions, evaluated just before the algorithm runs.
@ ModelOutput
Parameter value is linked to an output parameter for the model.
@ ChildOutput
Parameter value is taken from an output generated by a child algorithm.
@ ModelParameter
Parameter value is taken from a parent model parameter.
@ StaticValue
Parameter value is a static value.
@ Expression
Parameter value is taken from an expression, evaluated just before the algorithm runs.
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
virtual QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
virtual QString valueAsPythonComment(const QVariant &value, QgsProcessingContext &context) const
Returns a Python comment explaining a parameter value, or an empty string if no comment is required.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
PythonOutputType
Available Python output types.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.