Skip to content

Commit

Permalink
Setup framework for receiving model child results after running throu…
Browse files Browse the repository at this point in the history
…gh model designer
  • Loading branch information
nyalldawson committed Mar 31, 2020
1 parent 4a85110 commit cb990c6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 0 deletions.
Expand Up @@ -95,6 +95,11 @@ Checks if the model can current be saved, and returns ``True`` if it can.
Checks if there are unsaved changes in the model, and if so, prompts the user to save them.

Returns ``False`` if the cancel option was selected
%End

void setLastRunChildAlgorithmResults( const QVariantMap &results );
%Docstring
Sets the results of child algorithms for the last run of the model through the designer window.
%End

};
Expand Down
Expand Up @@ -299,6 +299,15 @@ by the dialog. Ownership of ``task`` is transferred to the dialog.
Formats an input ``string`` for display in the log tab.

.. versionadded:: 3.0.1
%End

signals:

void algorithmFinished( bool successful, const QVariantMap &result );
%Docstring
Emitted whenever an algorithm has finished executing in the dialog.

.. versionadded:: 3.14
%End

protected slots:
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -342,6 +342,7 @@ def finish(self, successful, result, context, feedback, in_place=False):
self.setExecuted(True)
self.setResults(result)
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.algorithm().displayName()), escapeHtml=False)
self.algorithmFinished.emit(successful, result)

if not in_place and not keepOpen:
self.close()
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -120,8 +120,12 @@ def runModel(self):
duration=5)
return

def on_finished(successful, results):
self.setLastRunChildAlgorithmResults(dlg.results()['CHILD_RESULTS'])

dlg = AlgorithmDialog(self.model().create(), parent=self)
dlg.setParameters(self.model().designerParameterValues())
dlg.algorithmFinished.connect(on_finished)
dlg.exec_()

if dlg.wasExecuted():
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -402,6 +402,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
feedback->pushDebugInfo( QObject::tr( "Model processed OK. Executed %1 algorithms total in %2 s." ).arg( executed.count() ).arg( totalTime.elapsed() / 1000.0 ) );

mResults = finalResults;
mResults.insert( QStringLiteral( "CHILD_RESULTS" ), childResults );
return mResults;
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Expand Up @@ -437,6 +437,11 @@ bool QgsModelDesignerDialog::checkForUnsavedChanges()
}
}

void QgsModelDesignerDialog::setLastRunChildAlgorithmResults( const QVariantMap &results )
{
mChildResults = results;
}

void QgsModelDesignerDialog::zoomIn()
{
mView->setTransformationAnchor( QGraphicsView::NoAnchor );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Expand Up @@ -120,6 +120,11 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
*/
bool checkForUnsavedChanges();

/**
* Sets the results of child algorithms for the last run of the model through the designer window.
*/
void setLastRunChildAlgorithmResults( const QVariantMap &results );

private slots:
void zoomIn();
void zoomOut();
Expand Down Expand Up @@ -164,6 +169,8 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode

int mBlockRepaints = 0;

QVariantMap mChildResults;

bool isDirty() const;

void fillInputsTree();
Expand Down
9 changes: 9 additions & 0 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -343,6 +343,15 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
*/
static QString formatStringForLog( const QString &string );

signals:

/**
* Emitted whenever an algorithm has finished executing in the dialog.
*
* \since QGIS 3.14
*/
void algorithmFinished( bool successful, const QVariantMap &result );

protected slots:

/**
Expand Down

0 comments on commit cb990c6

Please sign in to comment.