QGIS API Documentation  3.27.0-Master (aef1b1ec20)
qgsprocessingmodelchildparametersource.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingmodelchildparametersource.h
3  ----------------------------------------
4  begin : June 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H
19 #define QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgsprocessing.h"
25 class QgsProcessingModelAlgorithm;
26 
28 
34 class CORE_EXPORT QgsProcessingModelChildParameterSource
35 {
36  public:
37 
39  enum Source
40  {
41  ModelParameter,
42  ChildOutput,
43  StaticValue,
44  Expression,
45  ExpressionText,
46  ModelOutput,
47  };
48 
53  QgsProcessingModelChildParameterSource() = default;
54 
55  bool operator==( const QgsProcessingModelChildParameterSource &other ) const;
56  bool operator!=( const QgsProcessingModelChildParameterSource &other ) const
57  {
58  return !operator==( other );
59  }
60 
68  static QgsProcessingModelChildParameterSource fromStaticValue( const QVariant &value );
69 
77  static QgsProcessingModelChildParameterSource fromModelParameter( const QString &parameterName );
78 
86  static QgsProcessingModelChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
87 
99  static QgsProcessingModelChildParameterSource fromExpression( const QString &expression );
100 
113  static QgsProcessingModelChildParameterSource fromExpressionText( const QString &text );
114 
118  Source source() const;
119 
125  void setSource( Source source );
126 
131  QVariant staticValue() const { return mStaticValue; }
132 
137  void setStaticValue( const QVariant &value ) { mStaticValue = value; mSource = StaticValue; }
138 
143  QString parameterName() const { return mParameterName; }
144 
149  void setParameterName( const QString &name ) { mParameterName = name; mSource = ModelParameter; }
150 
156  QString outputChildId() const { return mChildId; }
157 
163  void setOutputChildId( const QString &id ) { mChildId = id; mSource = ChildOutput; }
164 
170  QString outputName() const { return mOutputName; }
171 
177  void setOutputName( const QString &name ) { mOutputName = name; mSource = ChildOutput; }
178 
183  QString expression() const { return mExpression; }
184 
192  void setExpression( const QString &expression ) { mExpression = expression; mSource = Expression; }
193 
200  QString expressionText() const { return mExpressionText; }
201 
211  void setExpressionText( const QString &text ) { mExpressionText = text; mSource = ExpressionText; }
212 
217  QVariant toVariant() const;
218 
223  bool loadVariant( const QVariantMap &map );
224 
230  QString asPythonCode( QgsProcessing::PythonOutputType outputType, const QgsProcessingParameterDefinition *definition, const QMap< QString, QString > &friendlyChildNames ) const;
231 
237  QString asPythonComment( const QgsProcessingParameterDefinition *definition ) const;
238 
243  QString friendlyIdentifier( QgsProcessingModelAlgorithm *model ) const;
244 
245  private:
246 
247  Source mSource = StaticValue;
248  QVariant mStaticValue;
249  QString mParameterName;
250  QString mChildId;
251  QString mOutputName;
252  QString mExpression;
253  QString mExpressionText;
254 
255 };
256 
257 Q_DECLARE_METATYPE( QgsProcessingModelChildParameterSource );
258 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsProcessingModelChildParameterSource &source );
259 CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsProcessingModelChildParameterSource &source );
260 
261 #ifndef SIP_RUN
263 typedef QList< QgsProcessingModelChildParameterSource > QgsProcessingModelChildParameterSources;
264 #endif
265 
267 
268 #endif // QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H
Base class for the definition of processing parameters.
PythonOutputType
Available Python output types.
Definition: qgsprocessing.h:63
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QDataStream & operator<<(QDataStream &out, const QgsFeature &feature)
Writes the feature to stream out. QGIS version compatibility is not guaranteed.
Definition: qgsfeature.cpp:398
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
Definition: qgsfeature.cpp:415
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)