Navigation Menu

Skip to content

Commit

Permalink
Add mechanism to show warning messages in modeler designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent 0f66c3e commit 0558d64
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
Expand Up @@ -132,6 +132,25 @@ Sets the results for child algorithms for the last model execution.
void setChildAlgorithmInputs( const QVariantMap &inputs );
%Docstring
Sets the inputs for child algorithms for the last model execution.
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns the message bar associated with the scene.

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

void setMessageBar( QgsMessageBar *bar );
%Docstring
Sets the message ``bar`` associated with the scene.

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

void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::Warning );
%Docstring
Shows a warning message, allowing users to click a button to see the full details (``longMessage``).
%End

signals:
Expand Down
29 changes: 29 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Expand Up @@ -19,7 +19,11 @@
#include "qgsmodelcomponentgraphicitem.h"
#include "qgsmodelarrowitem.h"
#include "qgsprocessingmodelgroupbox.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsmessageviewer.h"
#include <QGraphicsSceneMouseEvent>
#include <QPushButton>

///@cond NOT_STABLE

Expand Down Expand Up @@ -431,5 +435,30 @@ void QgsModelGraphicsScene::addCommentItemForComponent( QgsProcessingModelAlgori
addItem( arrow.release() );
}

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

void QgsModelGraphicsScene::setMessageBar( QgsMessageBar *messageBar )
{
mMessageBar = messageBar;
}

void QgsModelGraphicsScene::showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level )
{
QgsMessageBarItem *messageWidget = mMessageBar->createMessage( QString(), shortMessage );
QPushButton *detailsButton = new QPushButton( tr( "Details" ) );
connect( detailsButton, &QPushButton::clicked, detailsButton, [ = ]
{
QgsMessageViewer dialog( mMessageBar, QgsGuiUtils::ModalDialogFlags, false );
dialog.setTitle( title );
dialog.setMessage( longMessage, QgsMessageOutput::MessageHtml );
dialog.showMessage();
} );
messageWidget->layout()->addWidget( detailsButton );
mMessageBar->pushWidget( messageWidget, level, 0 );
}

///@endcond

22 changes: 22 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Expand Up @@ -30,6 +30,7 @@ class QgsProcessingModelComponent;
class QgsProcessingModelComment;
class QgsModelChildAlgorithmGraphicItem;
class QgsProcessingModelGroupBox;
class QgsMessageBar;

///@cond NOT_STABLE

Expand Down Expand Up @@ -146,6 +147,25 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
void setChildAlgorithmInputs( const QVariantMap &inputs );

/**
* Returns the message bar associated with the scene.
*
* \see setMessageBar()
*/
QgsMessageBar *messageBar() const;

/**
* Sets the message \a bar associated with the scene.
*
* \see messageBar()
*/
void setMessageBar( QgsMessageBar *bar );

/**
* Shows a warning message, allowing users to click a button to see the full details (\a longMessage).
*/
void showWarning( const QString &shortMessage, const QString &title, const QString &longMessage, Qgis::MessageLevel level = Qgis::Warning );

signals:

/**
Expand Down Expand Up @@ -223,6 +243,8 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
QVariantMap mChildResults;
QVariantMap mChildInputs;

QgsMessageBar *mMessageBar = nullptr;

};

Q_DECLARE_METATYPE( QgsModelGraphicsScene::Flags )
Expand Down

0 comments on commit 0558d64

Please sign in to comment.