mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[processing] Add API to set contexts for QgsProcessingAlgorithmConfigurationWidgets
This commit is contained in:
parent
892224c62b
commit
24529b1963
@ -12,7 +12,8 @@
|
||||
|
||||
|
||||
|
||||
class QgsProcessingAlgorithmConfigurationWidget : QWidget
|
||||
|
||||
class QgsProcessingAlgorithmConfigurationWidget : QWidget, QgsExpressionContextGenerator
|
||||
{
|
||||
%Docstring
|
||||
A configuration widget for processing algorithms allows providing additional
|
||||
@ -41,6 +42,47 @@ Read the current configuration from this widget.
|
||||
%Docstring
|
||||
Set the configuration which this widget should represent.
|
||||
%End
|
||||
|
||||
virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
|
||||
%Docstring
|
||||
Sets the ``context`` in which the Processing algorithm widget is shown, e.g., the
|
||||
parent model algorithm, a linked map canvas, and other relevant information which allows the widget
|
||||
to fine-tune its behavior.
|
||||
|
||||
Subclasses should take care to call the base class method when reimplementing this method.
|
||||
|
||||
.. seealso:: :py:func:`widgetContext`
|
||||
%End
|
||||
|
||||
void setAlgorithm( const QgsProcessingAlgorithm *algorithm );
|
||||
%Docstring
|
||||
Sets the algorithm instance associated with the widget.
|
||||
|
||||
.. seealso:: :py:func:`algorithm`
|
||||
|
||||
.. versionadded:: 3.6
|
||||
%End
|
||||
|
||||
const QgsProcessingAlgorithm *algorithm() const;
|
||||
%Docstring
|
||||
Returns the algorithm instance associated with this widget.
|
||||
|
||||
.. seealso:: :py:func:`setAlgorithm`
|
||||
|
||||
.. versionadded:: 3.6
|
||||
%End
|
||||
|
||||
void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
|
||||
%Docstring
|
||||
Registers a Processing context ``generator`` class that will be used to retrieve
|
||||
a Processing context for the widget when required.
|
||||
|
||||
.. versionadded:: 3.6
|
||||
%End
|
||||
|
||||
virtual QgsExpressionContext createExpressionContext() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -109,6 +109,7 @@ Sets the child algorithm ``id`` within the model which the parameter widget is a
|
||||
|
||||
};
|
||||
|
||||
|
||||
class QgsAbstractProcessingParameterWidgetWrapper : QObject, QgsExpressionContextGenerator
|
||||
{
|
||||
%Docstring
|
||||
|
@ -21,3 +21,23 @@ QgsProcessingAlgorithmConfigurationWidget::QgsProcessingAlgorithmConfigurationWi
|
||||
: QWidget( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmConfigurationWidget::setWidgetContext( const QgsProcessingParameterWidgetContext &context )
|
||||
{
|
||||
mWidgetContext = context;
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmConfigurationWidget::setAlgorithm( const QgsProcessingAlgorithm *algorithm )
|
||||
{
|
||||
mAlgorithm = algorithm;
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmConfigurationWidget::registerProcessingContextGenerator( QgsProcessingContextGenerator *generator )
|
||||
{
|
||||
mContextGenerator = generator;
|
||||
}
|
||||
|
||||
QgsExpressionContext QgsProcessingAlgorithmConfigurationWidget::createExpressionContext() const
|
||||
{
|
||||
return QgsProcessingGuiUtils::createExpressionContext( mContextGenerator, mWidgetContext, mAlgorithm, nullptr );
|
||||
}
|
||||
|
@ -24,10 +24,12 @@
|
||||
|
||||
#include "qgis_gui.h"
|
||||
#include "qgis_sip.h"
|
||||
#include "qgsprocessingwidgetwrapper.h"
|
||||
|
||||
class QgsProcessingAlgorithm;
|
||||
class QgsProcessingAlgorithmConfigurationWidget;
|
||||
|
||||
|
||||
/**
|
||||
* A configuration widget for processing algorithms allows providing additional
|
||||
* configuration options directly on algorithm level, in addition to parameters.
|
||||
@ -35,7 +37,7 @@ class QgsProcessingAlgorithmConfigurationWidget;
|
||||
* \ingroup gui
|
||||
* \since QGIS 3.2
|
||||
*/
|
||||
class GUI_EXPORT QgsProcessingAlgorithmConfigurationWidget : public QWidget
|
||||
class GUI_EXPORT QgsProcessingAlgorithmConfigurationWidget : public QWidget, public QgsExpressionContextGenerator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -56,6 +58,49 @@ class GUI_EXPORT QgsProcessingAlgorithmConfigurationWidget : public QWidget
|
||||
* Set the configuration which this widget should represent.
|
||||
*/
|
||||
virtual void setConfiguration( const QVariantMap &configuration ) = 0;
|
||||
|
||||
/**
|
||||
* Sets the \a context in which the Processing algorithm widget is shown, e.g., the
|
||||
* parent model algorithm, a linked map canvas, and other relevant information which allows the widget
|
||||
* to fine-tune its behavior.
|
||||
*
|
||||
* Subclasses should take care to call the base class method when reimplementing this method.
|
||||
*
|
||||
* \see widgetContext()
|
||||
*/
|
||||
virtual void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
|
||||
|
||||
/**
|
||||
* Sets the algorithm instance associated with the widget.
|
||||
*
|
||||
* \see algorithm()
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
void setAlgorithm( const QgsProcessingAlgorithm *algorithm );
|
||||
|
||||
/**
|
||||
* Returns the algorithm instance associated with this widget.
|
||||
*
|
||||
* \see setAlgorithm()
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
const QgsProcessingAlgorithm *algorithm() const { return mAlgorithm; }
|
||||
|
||||
/**
|
||||
* Registers a Processing context \a generator class that will be used to retrieve
|
||||
* a Processing context for the widget when required.
|
||||
*
|
||||
* \since QGIS 3.6
|
||||
*/
|
||||
void registerProcessingContextGenerator( QgsProcessingContextGenerator *generator );
|
||||
|
||||
QgsExpressionContext createExpressionContext() const override;
|
||||
|
||||
private:
|
||||
|
||||
QgsProcessingContextGenerator *mContextGenerator = nullptr;
|
||||
const QgsProcessingAlgorithm *mAlgorithm = nullptr;
|
||||
QgsProcessingParameterWidgetContext mWidgetContext;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user