Save algorithm results to dialog

This commit is contained in:
Nyall Dawson 2017-12-21 10:38:38 +10:00
parent edcd058e32
commit ce28cf5087
4 changed files with 51 additions and 0 deletions

View File

@ -69,6 +69,19 @@ Switches the dialog to the log page.
bool wasExecuted() const;
%Docstring
Returns true if an algorithm was executed in the dialog.
.. seealso:: :py:func:`results()`
.. seealso:: :py:func:`setExecuted()`
%End
QVariantMap results() const;
%Docstring
Returns the results returned by the algorithm executed.
.. seealso:: :py:func:`wasExecuted()`
.. seealso:: :py:func:`setResults()`
%End
QgsProcessingFeedback *createFeedback() /Factory/;
@ -157,6 +170,19 @@ Clears any current progress from the dialog.
void setExecuted( bool executed );
%Docstring
Sets whether the algorithm was executed through the dialog.
.. seealso:: :py:func:`wasExecuted()`
.. seealso:: :py:func:`setResults()`
%End
void setResults( const QVariantMap &results );
%Docstring
Sets the algorithm results.
.. seealso:: :py:func:`results()`
.. seealso:: :py:func:`setExecuted()`
%End
void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );

View File

@ -276,6 +276,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
return
self.setExecuted(True)
self.setResults(result)
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.algorithm().displayName()), escapeHtml=False)
if not keepOpen:

View File

@ -210,6 +210,11 @@ void QgsProcessingAlgorithmDialogBase::setExecuted( bool executed )
mExecuted = executed;
}
void QgsProcessingAlgorithmDialogBase::setResults( const QVariantMap &results )
{
mResults = results;
}
void QgsProcessingAlgorithmDialogBase::finished( bool, const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
{

View File

@ -118,9 +118,18 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
/**
* Returns true if an algorithm was executed in the dialog.
* \see results()
* \see setExecuted()
*/
bool wasExecuted() const { return mExecuted; }
/**
* Returns the results returned by the algorithm executed.
* \see wasExecuted()
* \see setResults()
*/
QVariantMap results() const { return mResults; }
/**
* Creates a new processing feedback object, automatically connected to the appropriate
* slots in this dialog.
@ -203,9 +212,18 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
/**
* Sets whether the algorithm was executed through the dialog.
* \see wasExecuted()
* \see setResults()
*/
void setExecuted( bool executed );
/**
* Sets the algorithm results.
* \see results()
* \see setExecuted()
*/
void setResults( const QVariantMap &results );
/**
* Displays an info \a message in the dialog's log.
*/
@ -250,6 +268,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
QgsMessageBar *mMessageBar = nullptr;
bool mExecuted = false;
QVariantMap mResults;
QWidget *mMainWidget = nullptr;
QgsProcessingAlgorithm *mAlgorithm = nullptr;
bool mHelpCollapsed = false;