QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsprocessingparameterfieldmap.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingparameterfieldmap.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
18QgsProcessingParameterFieldMapping::QgsProcessingParameterFieldMapping( const QString &name, const QString &description, const QString &parentLayerParameterName, bool optional )
19 : QgsProcessingParameterDefinition( name, description, QVariant(), optional )
20 , mParentLayerParameterName( parentLayerParameterName )
21{
22}
23
28
30{
31 return typeName();
32}
33
35{
36 if ( !input.isValid() )
38
39 if ( input.userType() != QMetaType::Type::QVariantList )
40 return false;
41
42 const QVariantList inputList = input.toList();
43 for ( const QVariant &inputItem : inputList )
44 {
45 if ( inputItem.userType() != QMetaType::Type::QVariantMap )
46 return false;
47
48 const QVariantMap inputItemMap = inputItem.toMap();
49
50 if ( !inputItemMap.contains( "name" ) )
51 return false;
52 if ( !inputItemMap.contains( "type" ) )
53 return false;
54 if ( !inputItemMap.contains( "expression" ) )
55 return false;
56 }
57
58 return true;
59}
60
65
67{
68 switch ( outputType )
69 {
71 {
72 QString code = QStringLiteral( "QgsProcessingParameterFieldMapping('%1', %2" )
74 if ( !mParentLayerParameterName.isEmpty() )
75 code += QStringLiteral( ", parentLayerParameterName=%1" ).arg( QgsProcessingUtils::stringToPythonLiteral( mParentLayerParameterName ) );
76
78 code += QLatin1String( ", optional=True" );
79 code += ')';
80 return code;
81 }
82 }
83 return QString();
84}
85
87{
89 map.insert( QStringLiteral( "parent_layer" ), mParentLayerParameterName );
90 return map;
91}
92
94{
96 mParentLayerParameterName = map.value( QStringLiteral( "parent_layer" ) ).toString();
97 return true;
98}
99
101{
102 QStringList depends;
103 if ( !mParentLayerParameterName.isEmpty() )
104 depends << mParentLayerParameterName;
105 return depends;
106}
107
109{
110 return mParentLayerParameterName;
111}
112
114{
115 mParentLayerParameterName = name;
116}
117
@ Optional
Parameter is optional.
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
QString description() const
Returns the description for the parameter.
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.
A parameter for "field mapping" configurations, which consist of a definition of desired output field...
QgsProcessingParameterFieldMapping(const QString &name, const QString &description=QString(), const QString &parentLayerParameterName=QString(), bool optional=false)
Constructor for QgsProcessingParameterFieldMapping.
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...
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.
void setParentLayerParameterName(const QString &name)
Sets the name of the parent layer parameter.
QString parentLayerParameterName() const
Returns the name of the parent layer parameter, or an empty string if this is not set.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QString typeName()
Returns the type name for the parameter class.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
QString type() const override
Unique parameter type name.
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.