Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix interface for QgsProcessingParametersGenerator was modified for
the python subclasses only and no longer correctly overrides the
base class method
  • Loading branch information
nyalldawson committed Dec 16, 2021
1 parent 25337c2 commit 86794da
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_additions/qgsprocessingwidgetwrapper.py
@@ -0,0 +1,5 @@
# The following has been generated automatically from src/gui/processing/qgsprocessingwidgetwrapper.h
# monkey patching scoped based enum
QgsProcessingParametersGenerator.Flag.SkipDefaultValueParameters.__doc__ = "Parameters which are unchanged from their default values should not be included"
QgsProcessingParametersGenerator.Flag.__doc__ = 'Flags controlling parameter generation.\n\n.. versionadded:: 3.24\n\n' + '* ``SkipDefaultValueParameters``: ' + QgsProcessingParametersGenerator.Flag.SkipDefaultValueParameters.__doc__
# --
Expand Up @@ -49,15 +49,28 @@ An interface for objects which can create sets of parameter values for processin
%End
public:

virtual QVariantMap createProcessingParameters() = 0;
enum class Flag
{
SkipDefaultValueParameters,
};
typedef QFlags<QgsProcessingParametersGenerator::Flag> Flags;


virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;
%Docstring
This method needs to be reimplemented in all classes which implement this interface
and return a algorithm parameters.

Since QGIS 3.24 the optional ``flags`` argument can be used to control the behaviour
of the parameter generation.
%End

virtual ~QgsProcessingParametersGenerator();
};

QFlags<QgsProcessingParametersGenerator::Flag> operator|(QgsProcessingParametersGenerator::Flag f1, QFlags<QgsProcessingParametersGenerator::Flag> f2);



class QgsProcessingParameterWidgetContext
{
Expand Down
9 changes: 5 additions & 4 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -37,7 +37,8 @@
QgsProxyProgressTask,
QgsProcessingFeatureSourceDefinition)
from qgis.gui import (QgsGui,
QgsProcessingAlgorithmDialogBase)
QgsProcessingAlgorithmDialogBase,
QgsProcessingParametersGenerator)
from qgis.utils import iface

from processing.core.ProcessingLog import ProcessingLog
Expand Down Expand Up @@ -109,11 +110,11 @@ def blockAdditionalControlsWhileRunning(self):
def setParameters(self, parameters):
self.mainWidget().setParameters(parameters)

def createProcessingParameters(self, include_default=True):
def createProcessingParameters(self, flags=QgsProcessingParametersGenerator.Flags()):
if self.mainWidget() is None:
return {}
else:
return self.mainWidget().createProcessingParameters(include_default)

return self.mainWidget().createProcessingParameters(flags)

def runAlgorithm(self):
self.feedback = self.createFeedback()
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -198,7 +198,8 @@ def initWidgets(self):
for wrapper in list(self.wrappers.values()):
wrapper.postInitialize(list(self.wrappers.values()))

def createProcessingParameters(self, include_default=True):
def createProcessingParameters(self, flags=QgsProcessingParametersGenerator.Flags()):
include_default = not (flags & QgsProcessingParametersGenerator.Flag.SkipDefaultValueParameters)
parameters = {}
for p, v in self.extra_parameters.items():
parameters[p] = v
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -47,7 +47,8 @@
QgsProcessingParameterWidgetContext,
QgsModelGraphicsScene,
QgsModelDesignerDialog,
QgsProcessingContextGenerator)
QgsProcessingContextGenerator,
QgsProcessingParametersGenerator)
from processing.gui.HelpEditionDialog import HelpEditionDialog
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
Expand Down Expand Up @@ -159,7 +160,7 @@ def on_finished(successful, results):
dlg.exec_()

if dlg.wasExecuted():
self.model().setDesignerParameterValues(dlg.createProcessingParameters(include_default=False))
self.model().setDesignerParameterValues(dlg.createProcessingParameters(flags=QgsProcessingParametersGenerator.Flags(QgsProcessingParametersGenerator.Flag.SkipDefaultValueParameters)))

def saveInProject(self):
if not self.validateSave():
Expand Down
18 changes: 17 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -76,15 +76,31 @@ class GUI_EXPORT QgsProcessingParametersGenerator
{
public:

/**
* Flags controlling parameter generation.
*
* \since QGIS 3.24
*/
enum class Flag : int
{
SkipDefaultValueParameters = 1 << 0, //!< Parameters which are unchanged from their default values should not be included
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* This method needs to be reimplemented in all classes which implement this interface
* and return a algorithm parameters.
*
* Since QGIS 3.24 the optional \a flags argument can be used to control the behaviour
* of the parameter generation.
*/
virtual QVariantMap createProcessingParameters() = 0;
virtual QVariantMap createProcessingParameters( QgsProcessingParametersGenerator::Flags flags = QgsProcessingParametersGenerator::Flags() ) = 0;

virtual ~QgsProcessingParametersGenerator() = default;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParametersGenerator::Flags )


/**
* \ingroup gui
Expand Down

0 comments on commit 86794da

Please sign in to comment.