Skip to content

Commit

Permalink
Add methods to convert parameter definitions to/from variants
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 20, 2017
1 parent 9a2f14b commit f21f502
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 0 deletions.
76 changes: 76 additions & 0 deletions python/core/processing/qgsprocessingparameters.sip
Expand Up @@ -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:


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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};


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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

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

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


};

class QgsProcessingParameterFolderOutput : QgsProcessingParameterDefinition
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -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 );
Expand Down
20 changes: 20 additions & 0 deletions src/core/processing/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f21f502

Please sign in to comment.