Skip to content
Permalink
Browse files

Add methods to convert parameter definitions to/from variants

  • Loading branch information
nyalldawson committed Jun 20, 2017
1 parent 9a2f14b commit f21f502a18657f544e5b71bb58d8aca5c0d26326
@@ -298,6 +298,22 @@ class QgsProcessingParameterDefinition
:rtype: str
%End

virtual QVariantMap toVariantMap() const;
%Docstring
Saves this parameter to a QVariantMap. Subclasses should ensure that they call the base class
method and then extend the result with additional properties.
.. seealso:: fromVariantMap()
:rtype: QVariantMap
%End

virtual bool fromVariantMap( const QVariantMap &map );
%Docstring
Restores this parameter to a QVariantMap. Subclasses should ensure that they call the base class
method.
.. seealso:: toVariantMap()
:rtype: bool
%End

protected:


@@ -686,6 +702,11 @@ class QgsProcessingParameterFile : QgsProcessingParameterDefinition
.. seealso:: extension()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterMatrix : QgsProcessingParameterDefinition
@@ -759,6 +780,11 @@ class QgsProcessingParameterMatrix : QgsProcessingParameterDefinition
.. seealso:: hasFixedNumberRows()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
@@ -814,6 +840,11 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
.. seealso:: minimumNumberInputs()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterNumber : QgsProcessingParameterDefinition
@@ -890,6 +921,11 @@ class QgsProcessingParameterNumber : QgsProcessingParameterDefinition
.. seealso:: dataType()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterRange : QgsProcessingParameterDefinition
@@ -931,6 +967,11 @@ class QgsProcessingParameterRange : QgsProcessingParameterDefinition
.. seealso:: dataType()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterRasterLayer : QgsProcessingParameterDefinition
@@ -1011,6 +1052,11 @@ class QgsProcessingParameterEnum : QgsProcessingParameterDefinition
.. seealso:: allowMultiple()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterString : QgsProcessingParameterDefinition
@@ -1049,6 +1095,11 @@ class QgsProcessingParameterString : QgsProcessingParameterDefinition
.. seealso:: multiLine()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterExpression : QgsProcessingParameterDefinition
@@ -1087,6 +1138,11 @@ class QgsProcessingParameterExpression : QgsProcessingParameterDefinition
.. seealso:: parentLayerParameter()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterTable : QgsProcessingParameterDefinition
@@ -1185,6 +1241,11 @@ class QgsProcessingParameterTableField : QgsProcessingParameterDefinition
.. seealso:: allowMultiple()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition
@@ -1225,6 +1286,11 @@ class QgsProcessingParameterFeatureSource : QgsProcessingParameterDefinition
.. seealso:: dataTypes()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};


@@ -1275,6 +1341,11 @@ class QgsProcessingParameterFeatureSink : QgsProcessingParameterDefinition
.. seealso:: dataType()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterRasterOutput : QgsProcessingParameterDefinition
@@ -1344,6 +1415,11 @@ class QgsProcessingParameterFileOutput : QgsProcessingParameterDefinition
.. seealso:: fileFilter()
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterFolderOutput : QgsProcessingParameterDefinition
@@ -458,6 +458,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
// friend class to access setProvider() - we do not want this public!
friend class QgsProcessingProvider;
friend class TestQgsProcessing;
friend class QgsProcessingModelAlgorithm;

#ifdef SIP_RUN
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other );
@@ -349,6 +349,13 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const
}
map.insert( "parameters", paramMap );

QVariantMap paramDefMap;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
{
paramDefMap.insert( def->name(), def->toVariantMap() );
}
map.insert( "parameterDefinitions", paramDefMap );

return map;
}

@@ -383,6 +390,19 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
mParameterComponents.insert( param.parameterName(), param );
}

qDeleteAll( mParameters );
mParameters.clear();
QVariantMap paramDefMap = map.value( QStringLiteral( "parameterDefinitions" ) ).toMap();
QVariantMap::const_iterator paramDefIt = paramDefMap.constBegin();
for ( ; paramDefIt != paramDefMap.constEnd(); ++paramDefIt )
{
//QgsProcessingParameterDefinition *param;
//if ( !param.loadVariant( paramDefIt.value().toMap() ) )
// return false;

//mParameterComponents.insert( param.parameterName(), param );
}

return true;
}

0 comments on commit f21f502

Please sign in to comment.
You can’t perform that action at this time.