QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsprocessingparameteraggregate.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingparameteraggregate.cpp
3 -------------------------
4 begin : June 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include <QString>
19
20using namespace Qt::StringLiterals;
21
23 : QgsProcessingParameterDefinition( name, description, QVariant(), optional )
24 , mParentLayerParameterName( parentLayerParameterName )
25{
26}
27
32
34{
35 return typeName();
36}
37
39{
40 if ( !input.isValid() )
42
43 if ( input.userType() != QMetaType::Type::QVariantList )
44 return false;
45
46 const QVariantList inputList = input.toList();
47 for ( const QVariant &inputItem : inputList )
48 {
49 if ( inputItem.userType() != QMetaType::Type::QVariantMap )
50 return false;
51
52 const QVariantMap inputItemMap = inputItem.toMap();
53
54 if ( !inputItemMap.contains( "name" ) )
55 return false;
56 if ( !inputItemMap.contains( "type" ) )
57 return false;
58 if ( !inputItemMap.contains( "input" ) )
59 return false;
60 if ( !inputItemMap.contains( "aggregate" ) )
61 return false;
62 }
63
64 return true;
65}
66
71
73{
74 switch ( outputType )
75 {
77 {
78 QString code = u"QgsProcessingParameterAggregate('%1', %2"_s
80 if ( !mParentLayerParameterName.isEmpty() )
81 code += u", parentLayerParameterName=%1"_s.arg( QgsProcessingUtils::stringToPythonLiteral( mParentLayerParameterName ) );
82
84 code += ", optional=True"_L1;
85 code += ')';
86 return code;
87 }
88 }
89 return QString();
90}
91
93{
95 map.insert( u"parent_layer"_s, mParentLayerParameterName );
96 return map;
97}
98
100{
102 mParentLayerParameterName = map.value( u"parent_layer"_s ).toString();
103 return true;
104}
105
107{
108 QStringList depends;
109 if ( !mParentLayerParameterName.isEmpty() )
110 depends << mParentLayerParameterName;
111 return depends;
112}
113
115{
116 return mParentLayerParameterName;
117}
118
120{
121 mParentLayerParameterName = name;
122}
123
@ Optional
Parameter is optional.
Definition qgis.h:3836
Contains information about the context in which a processing algorithm is executed.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString type() const override
Unique parameter type name.
static QString typeName()
Returns the type name for the parameter class.
void setParentLayerParameterName(const QString &name)
Sets the name of the parent layer parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterAggregate(const QString &name, const QString &description=QString(), const QString &parentLayerParameterName=QString(), bool optional=false)
Constructor for QgsProcessingParameterAggregate.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
QString description() const
Returns the description for the parameter.
QgsProcessingParameterDefinition(const QString &name, const QString &description=QString(), const QVariant &defaultValue=QVariant(), bool optional=false, const QString &help=QString())
Constructor for QgsProcessingParameterDefinition.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
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.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.