Skip to content
Permalink
Browse files

[processing] Add API to set contexts for QgsProcessingAlgorithmConfig…

…urationWidgets
  • Loading branch information
nyalldawson committed Feb 19, 2019
1 parent 892224c commit 24529b1963044eee6179e8315f64df0d7d932493
@@ -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,18 +24,20 @@

#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.
*
* \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;
};


0 comments on commit 24529b1

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