Skip to content

Commit

Permalink
[processing] Add api to allow providers to report warnings which should
Browse files Browse the repository at this point in the history
be shown to users when using that provider

This can be used to return a translated warning message which should be
shown to users of this provider. It's intended for use in cases such as
a provider which relies on a 3rd-party backend, where the version of the
backend software is not officially supported, or for alerting users to
providers in a "beta" or "untrustworthy" state.
  • Loading branch information
nyalldawson committed Dec 6, 2019
1 parent d664459 commit 61454c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingprovider.sip.in
Expand Up @@ -105,6 +105,18 @@ Returns ``True`` if the provider can be activated, or ``False`` if it cannot be
missing external dependencies).

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

virtual QString warningMessage() const;
%Docstring
Returns an optional warning message to show users when running algorithms from this provider.

This can be used to return a translated warning message which should be shown to users
of this provider. It's intended for use in cases such as a provider which relies on a 3rd-party
backend, where the version of the backend software is not officially supported, or for
alerting users to providers in a "beta" or "untrustworthy" state.

.. versionadded:: 3.10.1
%End

virtual bool isActive() const;
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -202,6 +202,9 @@ def runAlgorithm(self):

self.clearProgress()
self.feedback.pushVersionInfo(self.algorithm().provider())
if self.algorithm().provider().warningMessage():
self.feedback.reportError(self.algorithm().provider().warningMessage())

self.setProgressText(QCoreApplication.translate('AlgorithmDialog', 'Processing algorithm…'))

self.setInfo(
Expand Down
12 changes: 12 additions & 0 deletions src/core/processing/qgsprocessingprovider.h
Expand Up @@ -115,6 +115,18 @@ class CORE_EXPORT QgsProcessingProvider : public QObject
*/
virtual bool canBeActivated() const { return true; }

/**
* Returns an optional warning message to show users when running algorithms from this provider.
*
* This can be used to return a translated warning message which should be shown to users
* of this provider. It's intended for use in cases such as a provider which relies on a 3rd-party
* backend, where the version of the backend software is not officially supported, or for
* alerting users to providers in a "beta" or "untrustworthy" state.
*
* \since QGIS 3.10.1
*/
virtual QString warningMessage() const { return QString(); }

/**
* Returns TRUE if the provider is active and able to run algorithms.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -155,6 +155,12 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
{
mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Help ) );
}

const QString warning = algorithm->provider()->warningMessage();
if ( !warning.isEmpty() )
{
mMessageBar->pushMessage( warning, Qgis::Warning, 0 );
}
}

QgsProcessingAlgorithm *QgsProcessingAlgorithmDialogBase::algorithm()
Expand Down

0 comments on commit 61454c6

Please sign in to comment.