QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsprocessingmodeloutput.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingmodeloutput.cpp
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
19
21
22QgsProcessingModelOutput::QgsProcessingModelOutput( const QString &name, const QString &description )
23 : QgsProcessingModelComponent( description )
24 , mName( name )
25{}
26
27QgsProcessingModelOutput *QgsProcessingModelOutput::clone() const
28{
29 return new QgsProcessingModelOutput( *this );
30}
31
32QVariant QgsProcessingModelOutput::toVariant() const
33{
34 QVariantMap map;
35 map.insert( QStringLiteral( "name" ), mName );
36
37 if ( mDefaultValue.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
38 {
39 QVariantMap defaultMap = mDefaultValue.value<QgsProcessingOutputLayerDefinition>().toVariant().toMap();
40 defaultMap.insert( QStringLiteral( "class" ), QStringLiteral( "QgsProcessingOutputLayerDefinition" ) );
41 map.insert( QStringLiteral( "default_value" ), defaultMap );
42 }
43 else
44 {
45 map.insert( QStringLiteral( "default_value" ), mDefaultValue );
46 }
47
48 map.insert( QStringLiteral( "child_id" ), mChildId );
49 map.insert( QStringLiteral( "output_name" ), mOutputName );
50 map.insert( QStringLiteral( "mandatory" ), mMandatory );
51 saveCommonProperties( map );
52 return map;
53}
54
55bool QgsProcessingModelOutput::loadVariant( const QVariantMap &map )
56{
57 mName = map.value( QStringLiteral( "name" ) ).toString();
58
59 const QVariant defaultValue = map.value( QStringLiteral( "default_value" ) );
60 if ( defaultValue.type() == QVariant::Map )
61 {
62 QVariantMap defaultMap = defaultValue.toMap();
63 if ( defaultMap["class"] == QLatin1String( "QgsProcessingOutputLayerDefinition" ) )
64 {
66 value.loadVariant( defaultMap );
67 mDefaultValue = QVariant( value );
68 }
69 else
70 {
71 mDefaultValue = QVariant();
72 }
73 }
74 else
75 {
76 mDefaultValue = map.value( QStringLiteral( "default_value" ) );
77 }
78
79 mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
80 mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
81 mMandatory = map.value( QStringLiteral( "mandatory" ), false ).toBool();
82 restoreCommonProperties( map );
83 return true;
84}
85
86
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.