Skip to content
Permalink
Browse files

[processing][model] Fix handling of mandatory checkbox in output defi…

…nitions
  • Loading branch information
nyalldawson committed May 7, 2018
1 parent 4ccd444 commit 1a45a797196efcc2d5168034371d7f3a9261a242
@@ -58,6 +58,28 @@ Sets the default value for the model output.

.. seealso:: :py:func:`defaultValue`

.. versionadded:: 3.2
%End

bool isMandatory() const;
%Docstring
Returns true if the output is mandatory. This may override the associated
child algorithm's parameter optional status - e.g. allowing
an optional output from an algorithm to be mandatory within a model.

.. seealso:: :py:func:`setMandatory`

.. versionadded:: 3.2
%End

void setMandatory( bool mandatory );
%Docstring
Sets whether the output is ``mandatory``. This may override the associated
child algorithm's parameter optional status - e.g. allowing
an optional output from an algorithm to be mandatory within a model.

.. seealso:: :py:func:`isMandatory`

.. versionadded:: 3.2
%End

@@ -233,6 +233,7 @@ def editElement(self):
model_output = child_alg.modelOutput(self.element.name())
model_output.setDescription(dlg.param.description())
model_output.setDefaultValue(dlg.param.defaultValue())
model_output.setMandatory(not (dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional))
self.model.updateDestinationParameters()

def updateAlgorithm(self, alg):
@@ -443,34 +443,29 @@ def accept(self):
name=name,
description=self.param.description(),
type=self.param.dataType(),
defaultValue=self.defaultWidget.getValue(),
optional=self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
defaultValue=self.defaultWidget.getValue())
elif (isinstance(self.param, QgsProcessingParameterFileDestination)):
self.param = QgsProcessingParameterFileDestination(
name=name,
description=self.param.description(),
fileFilter=self.param.fileFilter(),
defaultValue=str(self.defaultWidget.getValue()),
optional=self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
defaultValue=str(self.defaultWidget.getValue()))
elif (isinstance(self.param, QgsProcessingParameterFolderDestination)):
self.param = QgsProcessingParameterFolderDestination(
name=name,
description=self.param.description(),
defaultValue=str(self.defaultWidget.getValue()),
optional=self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
defaultValue=str(self.defaultWidget.getValue()))
elif (isinstance(self.param, QgsProcessingParameterRasterDestination)):
self.param = QgsProcessingParameterRasterDestination(
name=name,
description=self.param.description(),
defaultValue=str(self.defaultWidget.getValue()),
optional=self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
defaultValue=str(self.defaultWidget.getValue()))
elif (isinstance(self.param, QgsProcessingParameterVectorDestination)):
self.param = QgsProcessingParameterVectorDestination(
name=name,
description=self.param.description(),
type=self.param.dataType(),
defaultValue=str(self.defaultWidget.getValue()),
optional=self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
defaultValue=str(self.defaultWidget.getValue()))

else:
if self.paramType:
@@ -488,6 +483,8 @@ def accept(self):

if not self.requiredCheck.isChecked():
self.param.setFlags(self.param.flags() | QgsProcessingParameterDefinition.FlagOptional)
else:
self.param.setFlags(self.param.flags() & ~QgsProcessingParameterDefinition.FlagOptional)

settings = QgsSettings()
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
@@ -786,6 +786,8 @@ void QgsProcessingModelAlgorithm::updateDestinationParameters()
// Even if an output was hidden in a child algorithm, we want to show it here for the final
// outputs.
param->setFlags( param->flags() & ~QgsProcessingParameterDefinition::FlagHidden );
if ( outputIt->isMandatory() )
param->setFlags( param->flags() & ~QgsProcessingParameterDefinition::FlagOptional );
param->setName( outputIt->childId() + ':' + outputIt->name() );
param->setDescription( outputIt->description() );
param->setDefaultValue( outputIt->defaultValue() );
@@ -42,6 +42,7 @@ QVariant QgsProcessingModelOutput::toVariant() const

map.insert( QStringLiteral( "child_id" ), mChildId );
map.insert( QStringLiteral( "output_name" ), mOutputName );
map.insert( QStringLiteral( "mandatory" ), mMandatory );
saveCommonProperties( map );
return map;
}
@@ -72,6 +73,7 @@ bool QgsProcessingModelOutput::loadVariant( const QVariantMap &map )

mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
mMandatory = map.value( QStringLiteral( "mandatory" ), false ).toBool();
restoreCommonProperties( map );
return true;
}
@@ -70,6 +70,24 @@ class CORE_EXPORT QgsProcessingModelOutput : public QgsProcessingModelComponent
*/
void setDefaultValue( const QVariant &value ) { mDefaultValue = value; }

/**
* Returns true if the output is mandatory. This may override the associated
* child algorithm's parameter optional status - e.g. allowing
* an optional output from an algorithm to be mandatory within a model.
* \see setMandatory()
* \since QGIS 3.2
*/
bool isMandatory() const { return mMandatory; }

/**
* Sets whether the output is \a mandatory. This may override the associated
* child algorithm's parameter optional status - e.g. allowing
* an optional output from an algorithm to be mandatory within a model.
* \see isMandatory()
* \since QGIS 3.2
*/
void setMandatory( bool mandatory ) { mMandatory = mandatory; }

/**
* Returns the child algorithm ID from which this output is generated.
* \see setChildId()
@@ -112,6 +130,7 @@ class CORE_EXPORT QgsProcessingModelOutput : public QgsProcessingModelComponent
QVariant mDefaultValue;
QString mChildId;
QString mOutputName;
bool mMandatory = false;
};

///@endcond

0 comments on commit 1a45a79

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