Skip to content

Commit

Permalink
[processing] Add message bar to widget context
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 4, 2020
1 parent f961449 commit 70ee385
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.cpp
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/gui/processing/qgsprocessingwidgetwrapper.h
Expand Up @@ -38,6 +38,7 @@ class QgsProcessingModelAlgorithm;
class QgsMapCanvas;
class QgsProcessingAlgorithm;
class QgsProcessingAbstractParameterDefinitionWidget;
class QgsMessageBar;

/**
* \class QgsProcessingContextGenerator
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -148,6 +165,8 @@ class GUI_EXPORT QgsProcessingParameterWidgetContext

QgsMapCanvas *mMapCanvas = nullptr;

QgsMessageBar *mMessageBar = nullptr;

QgsProject *mProject = nullptr;

};
Expand Down
7 changes: 7 additions & 0 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -64,6 +64,7 @@
#include "qgscolorbutton.h"
#include "qgsprocessingparameterdefinitionwidget.h"
#include "qgscoordinateoperationwidget.h"
#include "qgsmessagebar.h"

class TestParamType : public QgsProcessingParameterDefinition
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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" ) );
}
Expand Down

0 comments on commit 70ee385

Please sign in to comment.