Skip to content
Permalink
Browse files

[processing] Add message bar to widget context

  • Loading branch information
nyalldawson committed Jan 4, 2020
1 parent f961449 commit 70ee385f4a7d1dd2294530948e0fd61bb8bd8cb0
@@ -69,6 +69,26 @@ map scale and other properties from the canvas.
Returns the map canvas associated with the widget.

.. seealso:: :py:func:`setMapCanvas`
%End

void setMessageBar( QgsMessageBar *bar );
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the user.

.. seealso:: :py:func:`messageBar`

.. versionadded:: 3.12
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns the message bar associated with the widget. This allows the widget to push feedback messages
to the user.

.. seealso:: :py:func:`setMessageBar`

.. versionadded:: 3.12
%End

void setProject( QgsProject *project );
@@ -495,6 +495,9 @@ def setCellWrapper(self, row, column, wrapper, context):
widget_context.setProject(QgsProject.instance())
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())

widget_context.setMessageBar(self.parent.messageBar())

if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)
wrapper.setWidgetContext(widget_context)
@@ -129,6 +129,7 @@ def initWidgets(self):
widget_context.setProject(QgsProject.instance())
if iface is not None:
widget_context.setMapCanvas(iface.mapCanvas())
widget_context.setMessageBar(self.parent.messageBar())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)

@@ -41,6 +41,16 @@ QgsMapCanvas *QgsProcessingParameterWidgetContext::mapCanvas() const
return mMapCanvas;
}

void QgsProcessingParameterWidgetContext::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}

QgsMessageBar *QgsProcessingParameterWidgetContext::messageBar() const
{
return mMessageBar;
}

void QgsProcessingParameterWidgetContext::setProject( QgsProject *project )
{
mProject = project;
@@ -38,6 +38,7 @@ class QgsProcessingModelAlgorithm;
class QgsMapCanvas;
class QgsProcessingAlgorithm;
class QgsProcessingAbstractParameterDefinitionWidget;
class QgsMessageBar;

/**
* \class QgsProcessingContextGenerator
@@ -94,6 +95,22 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext
*/
QgsMapCanvas *mapCanvas() const;

/**
* Sets the message \a bar associated with the widget. This allows the widget to push feedback messages
* to the user.
* \see messageBar()
* \since QGIS 3.12
*/
void setMessageBar( QgsMessageBar *bar );

/**
* Returns the message bar associated with the widget. This allows the widget to push feedback messages
* to the user.
* \see setMessageBar()
* \since QGIS 3.12
*/
QgsMessageBar *messageBar() const;

/**
* Sets the \a project associated with the widget. This allows the widget to retrieve the map layers
* and other properties from the correct project.
@@ -148,6 +165,8 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext

QgsMapCanvas *mMapCanvas = nullptr;

QgsMessageBar *mMessageBar = nullptr;

QgsProject *mProject = nullptr;

};
@@ -64,6 +64,7 @@
#include "qgscolorbutton.h"
#include "qgsprocessingparameterdefinitionwidget.h"
#include "qgscoordinateoperationwidget.h"
#include "qgsmessagebar.h"

class TestParamType : public QgsProcessingParameterDefinition
{
@@ -417,6 +418,11 @@ void TestProcessingGui::testWrapperGeneral()
QgsProcessingParameterWidgetContext widgetContext;
widgetContext.setMapCanvas( mc.get() );
QCOMPARE( widgetContext.mapCanvas(), mc.get() );

std::unique_ptr< QgsMessageBar > mb = qgis::make_unique< QgsMessageBar >();
widgetContext.setMessageBar( mb.get() );
QCOMPARE( widgetContext.messageBar(), mb.get() );

QgsProject p;
widgetContext.setProject( &p );
QCOMPARE( widgetContext.project(), &p );
@@ -428,6 +434,7 @@ void TestProcessingGui::testWrapperGeneral()

wrapper.setWidgetContext( widgetContext );
QCOMPARE( wrapper.widgetContext().mapCanvas(), mc.get() );
QCOMPARE( wrapper.widgetContext().messageBar(), mb.get() );
QCOMPARE( wrapper.widgetContext().model(), model.get() );
QCOMPARE( wrapper.widgetContext().modelChildAlgorithmId(), QStringLiteral( "xx" ) );
}

0 comments on commit 70ee385

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