mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
[processing] Allow algorithms to provide additional configuration widgets
This commit is contained in:
parent
9e8c995ac8
commit
e6ef7639cb
@ -10,12 +10,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%ModuleHeaderCode
|
%ModuleHeaderCode
|
||||||
#include <qgsprocessingmodelalgorithm.h>
|
#include <qgsprocessingmodelalgorithm.h>
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
|
||||||
class QgsProcessingAlgorithm
|
class QgsProcessingAlgorithm
|
||||||
{
|
{
|
||||||
%Docstring
|
%Docstring
|
||||||
@ -351,6 +349,12 @@ If an algorithm subclass implements a custom parameters widget, a copy of this w
|
|||||||
should be constructed and returned by this method.
|
should be constructed and returned by this method.
|
||||||
The base class implementation returns None, which indicates that an autogenerated
|
The base class implementation returns None, which indicates that an autogenerated
|
||||||
parameters widget should be used.
|
parameters widget should be used.
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const /Factory/;
|
||||||
|
%Docstring
|
||||||
|
If an algorithm subclass implements a configuration widget for the algorithm itself,
|
||||||
|
a new instance of this widget should be returned by this method.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsExpressionContext createExpressionContext( const QVariantMap ¶meters,
|
QgsExpressionContext createExpressionContext( const QVariantMap ¶meters,
|
||||||
|
@ -208,7 +208,7 @@ class ModelerGraphicItem(QGraphicsItem):
|
|||||||
self.scene.dialog.repaintModel()
|
self.scene.dialog.repaintModel()
|
||||||
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
|
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
|
||||||
elemAlg = self.element.algorithm()
|
elemAlg = self.element.algorithm()
|
||||||
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId())
|
dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration())
|
||||||
if dlg.exec_():
|
if dlg.exec_():
|
||||||
alg = dlg.createAlgorithm()
|
alg = dlg.createAlgorithm()
|
||||||
alg.setChildId(self.element.childId())
|
alg.setChildId(self.element.childId())
|
||||||
|
@ -63,13 +63,15 @@ from processing.gui.MultipleInputPanel import MultipleInputPanel
|
|||||||
|
|
||||||
|
|
||||||
class ModelerParametersDialog(QDialog):
|
class ModelerParametersDialog(QDialog):
|
||||||
def __init__(self, alg, model, algName=None):
|
|
||||||
|
def __init__(self, alg, model, algName=None, configuration=None):
|
||||||
QDialog.__init__(self)
|
QDialog.__init__(self)
|
||||||
self.setModal(True)
|
self.setModal(True)
|
||||||
|
|
||||||
self._alg = alg # The algorithm to define in this dialog. It is an instance of QgsProcessingAlgorithm
|
self._alg = alg # The algorithm to define in this dialog. It is an instance of QgsProcessingAlgorithm
|
||||||
self.model = model # The model this algorithm is going to be added to. It is an instance of QgsProcessingModelAlgorithm
|
self.model = model # The model this algorithm is going to be added to. It is an instance of QgsProcessingModelAlgorithm
|
||||||
self.childId = algName # The name of the algorithm in the model, in case we are editing it and not defining it for the first time
|
self.childId = algName # The name of the algorithm in the model, in case we are editing it and not defining it for the first time
|
||||||
|
self.configuration = configuration
|
||||||
|
|
||||||
self.setupUi()
|
self.setupUi()
|
||||||
self.params = None
|
self.params = None
|
||||||
@ -87,6 +89,8 @@ class ModelerParametersDialog(QDialog):
|
|||||||
self.wrappers = {}
|
self.wrappers = {}
|
||||||
self.valueItems = {}
|
self.valueItems = {}
|
||||||
self.dependentItems = {}
|
self.dependentItems = {}
|
||||||
|
self.algorithmItem = None
|
||||||
|
|
||||||
self.resize(650, 450)
|
self.resize(650, 450)
|
||||||
self.buttonBox = QDialogButtonBox()
|
self.buttonBox = QDialogButtonBox()
|
||||||
self.buttonBox.setOrientation(Qt.Horizontal)
|
self.buttonBox.setOrientation(Qt.Horizontal)
|
||||||
@ -114,6 +118,10 @@ class ModelerParametersDialog(QDialog):
|
|||||||
line.setFrameShape(QFrame.HLine)
|
line.setFrameShape(QFrame.HLine)
|
||||||
line.setFrameShadow(QFrame.Sunken)
|
line.setFrameShadow(QFrame.Sunken)
|
||||||
self.verticalLayout.addWidget(line)
|
self.verticalLayout.addWidget(line)
|
||||||
|
self.algorithmItem = self._alg.createModelerWidget()
|
||||||
|
if self.configuration:
|
||||||
|
self.algorithmItem.setConfiguration(self.configuration)
|
||||||
|
self.verticalLayout.addWidget(self.algorithmItem)
|
||||||
|
|
||||||
for param in self._alg.parameterDefinitions():
|
for param in self._alg.parameterDefinitions():
|
||||||
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
||||||
@ -284,6 +292,8 @@ class ModelerParametersDialog(QDialog):
|
|||||||
else:
|
else:
|
||||||
alg.setChildId(self.childId)
|
alg.setChildId(self.childId)
|
||||||
alg.setDescription(self.descriptionBox.text())
|
alg.setDescription(self.descriptionBox.text())
|
||||||
|
if self.algorithmItem:
|
||||||
|
alg.setConfiguration(self.algorithmItem.configuration())
|
||||||
for param in self._alg.parameterDefinitions():
|
for param in self._alg.parameterDefinitions():
|
||||||
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
||||||
continue
|
continue
|
||||||
|
@ -131,6 +131,11 @@ QWidget *QgsProcessingAlgorithm::createCustomParametersWidget( QWidget * ) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsProcessingAlgorithmConfigurationWidget *QgsProcessingAlgorithm::createModelerWidget() const
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVariantMap ¶meters,
|
QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVariantMap ¶meters,
|
||||||
QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
|
QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,8 @@ class QgsProcessingProvider;
|
|||||||
class QgsProcessingFeedback;
|
class QgsProcessingFeedback;
|
||||||
class QgsFeatureSink;
|
class QgsFeatureSink;
|
||||||
class QgsProcessingFeedback;
|
class QgsProcessingFeedback;
|
||||||
|
class QgsProcessingModelAlgorithm;
|
||||||
|
class QgsProcessingAlgorithmConfigurationWidget;
|
||||||
|
|
||||||
#ifdef SIP_RUN
|
#ifdef SIP_RUN
|
||||||
% ModuleHeaderCode
|
% ModuleHeaderCode
|
||||||
@ -41,7 +42,6 @@ class QgsProcessingFeedback;
|
|||||||
% End
|
% End
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class QgsProcessingAlgorithm
|
* \class QgsProcessingAlgorithm
|
||||||
* \ingroup core
|
* \ingroup core
|
||||||
@ -356,6 +356,12 @@ class CORE_EXPORT QgsProcessingAlgorithm
|
|||||||
*/
|
*/
|
||||||
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;
|
virtual QWidget *createCustomParametersWidget( QWidget *parent = nullptr ) const SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If an algorithm subclass implements a configuration widget for the algorithm itself,
|
||||||
|
* a new instance of this widget should be returned by this method.
|
||||||
|
*/
|
||||||
|
virtual QgsProcessingAlgorithmConfigurationWidget *createModelerWidget() const SIP_FACTORY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an expression context relating to the algorithm. This can be called by algorithms
|
* Creates an expression context relating to the algorithm. This can be called by algorithms
|
||||||
* to create a new expression context ready for evaluating expressions within the algorithm.
|
* to create a new expression context ready for evaluating expressions within the algorithm.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user