Skip to content
Permalink
Browse files

[FEATURE][processing] Remember parameter values between model designe…

…r runs

When designing a model, users typically will need to run the model
many times as they tweak its structure.

This change causes the parameters used when running the model from
the designer to be remembered and saved into the model, so that
each time you run the model from the designer you don't have to
re-set all the input parameter values to the desired test ones.

Makes iterative model design SO much easier!

Sponsored by Alta Ehf
  • Loading branch information
nyalldawson committed Mar 4, 2020
1 parent b3864db commit 2a1bf56493ba1373fcccadff489e28d584a52c64
@@ -441,6 +441,32 @@ These variables are added to the model's expression context scope, allowing for
.. seealso:: :py:func:`variables`

.. versionadded:: 3.8
%End

QVariantMap designerParameterValues() const;
%Docstring
Returns the parameter values to use as default values when running this model through the
designer dialog.

This usually corresponds to the last set of parameter values used when the model was
run through the designer.

.. seealso:: :py:func:`setDesignerParameterValues`

.. versionadded:: 3.14
%End

void setDesignerParameterValues( const QVariantMap &values );
%Docstring
Sets the parameter ``values`` to use as default values when running this model through the
designer dialog.

This usually corresponds to the last set of parameter values used when the model was
run through the designer.

.. seealso:: :py:func:`designerParameterValues`

.. versionadded:: 3.14
%End

protected:
@@ -543,8 +543,12 @@ def runModel(self):
return

dlg = AlgorithmDialog(self.model.create(), parent=iface.mainWindow())
dlg.setParameters(self.model.designerParameterValues())
dlg.exec_()

if dlg.wasExecuted():
self.model.setDesignerParameterValues(dlg.getParameterValues())

def save(self):
self.saveModel(False)

@@ -1162,6 +1162,8 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const

map.insert( QStringLiteral( "modelVariables" ), mVariables );

map.insert( QStringLiteral( "designerParameterValues" ), mDesignerParameterValues );

return map;
}

@@ -1175,6 +1177,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
mHelpContent = map.value( QStringLiteral( "help" ) ).toMap();

mVariables = map.value( QStringLiteral( "modelVariables" ) ).toMap();
mDesignerParameterValues = map.value( QStringLiteral( "designerParameterValues" ) ).toMap();

mChildAlgorithms.clear();
QVariantMap childMap = map.value( QStringLiteral( "children" ) ).toMap();
@@ -398,6 +398,32 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
*/
void setVariables( const QVariantMap &variables );

/**
* Returns the parameter values to use as default values when running this model through the
* designer dialog.
*
* This usually corresponds to the last set of parameter values used when the model was
* run through the designer.
*
* \see setDesignerParameterValues()
*
* \since QGIS 3.14
*/
QVariantMap designerParameterValues() const { return mDesignerParameterValues; }

/**
* Sets the parameter \a values to use as default values when running this model through the
* designer dialog.
*
* This usually corresponds to the last set of parameter values used when the model was
* run through the designer.
*
* \see designerParameterValues()
*
* \since QGIS 3.14
*/
void setDesignerParameterValues( const QVariantMap &values ) { mDesignerParameterValues = values; }

protected:

QgsProcessingAlgorithm *createInstance() const override SIP_FACTORY;
@@ -424,6 +450,8 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm

QVariantMap mVariables;

QVariantMap mDesignerParameterValues;

void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;

0 comments on commit 2a1bf56

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