Skip to content

Commit

Permalink
Also add "Run from Here" action to right click menu on algorithms
Browse files Browse the repository at this point in the history
Allows running the part of the model which starts at the right
clicked algorithm only
  • Loading branch information
nyalldawson committed May 3, 2024
1 parent 7b600f3 commit e6fb69c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ Sets the ``results`` obtained for this child algorithm for the last model execut

signals:

void runFromHere();
%Docstring
Emitted when the user opts to run the model from this child algorithm.

.. versionadded:: 3.38
%End

void showPreviousResults();
%Docstring
Emitted when the user opts to view previous results from this child algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ Emitted whenever a component of the model is changed.
%Docstring
Emitted whenever the selected item changes.
If ``None``, no item is selected.
%End

void runFromChild( const QString &childId );
%Docstring
Emitted when the user opts to run the part of the model starting from the specified child algorithm.

.. versionadded:: 3.38
%End

void showChildAlgorithmOutputs( const QString &childId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ Sets the ``results`` obtained for this child algorithm for the last model execut

signals:

void runFromHere();
%Docstring
Emitted when the user opts to run the model from this child algorithm.

.. versionadded:: 3.38
%End

void showPreviousResults();
%Docstring
Emitted when the user opts to view previous results from this child algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ Emitted whenever a component of the model is changed.
%Docstring
Emitted whenever the selected item changes.
If ``None``, no item is selected.
%End

void runFromChild( const QString &childId );
%Docstring
Emitted when the user opts to run the part of the model starting from the specified child algorithm.

.. versionadded:: 3.38
%End

void showChildAlgorithmOutputs( const QString &childId );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@ QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcess
void QgsModelChildAlgorithmGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
{
QMenu *popupmenu = new QMenu( event->widget() );
QAction *runFromHereAction = popupmenu->addAction( QObject::tr( "Run from Here…" ) );
runFromHereAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStart.svg" ) ) );
connect( runFromHereAction, &QAction::triggered, this, &QgsModelChildAlgorithmGraphicItem::runFromHere );
popupmenu->addSeparator();

QAction *removeAction = popupmenu->addAction( QObject::tr( "Remove" ) );
connect( removeAction, &QAction::triggered, this, &QgsModelChildAlgorithmGraphicItem::deleteComponent );
QAction *editAction = popupmenu->addAction( QObject::tr( "Edit…" ) );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra

signals:

/**
* Emitted when the user opts to run the model from this child algorithm.
*
* \since QGIS 3.38
*/
void runFromHere();

/**
* Emitted when the user opts to view previous results from this child algorithm.
*
Expand Down
8 changes: 8 additions & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void QgsModelDesignerDialog::setModelScene( QgsModelGraphicsScene *scene )
} );
connect( mScene, &QgsModelGraphicsScene::componentAboutToChange, this, [ = ]( const QString & description, int id ) { beginUndoCommand( description, id ); } );
connect( mScene, &QgsModelGraphicsScene::componentChanged, this, [ = ] { endUndoCommand(); } );
connect( mScene, &QgsModelGraphicsScene::runFromChild, this, &QgsModelDesignerDialog::runFromChild );
connect( mScene, &QgsModelGraphicsScene::showChildAlgorithmOutputs, this, &QgsModelDesignerDialog::showChildAlgorithmOutputs );
connect( mScene, &QgsModelGraphicsScene::showChildAlgorithmLog, this, &QgsModelDesignerDialog::showChildAlgorithmLog );

Expand Down Expand Up @@ -1015,6 +1016,13 @@ void QgsModelDesignerDialog::runSelectedSteps()
run( children );
}

void QgsModelDesignerDialog::runFromChild( const QString &id )
{
QSet<QString> children = mModel->dependentChildAlgorithms( id );
children.insert( id );
run( children );
}

void QgsModelDesignerDialog::run( const QSet<QString> &childAlgorithmSubset )
{
QStringList errors;
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
void setPanelVisibility( bool hidden );
void editHelp();
void runSelectedSteps();
void runFromChild( const QString &id );
void run( const QSet<QString> &childAlgorithmSubset = QSet<QString>() );
void showChildAlgorithmOutputs( const QString &childId );
void showChildAlgorithmLog( const QString &childId );
Expand Down
4 changes: 4 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
connect( item, &QgsModelComponentGraphicItem::requestModelRepaint, this, &QgsModelGraphicsScene::rebuildRequired );
connect( item, &QgsModelComponentGraphicItem::changed, this, &QgsModelGraphicsScene::componentChanged );
connect( item, &QgsModelComponentGraphicItem::aboutToChange, this, &QgsModelGraphicsScene::componentAboutToChange );
connect( item, &QgsModelChildAlgorithmGraphicItem::runFromHere, this, [this, childId]
{
emit runFromChild( childId );
} );
connect( item, &QgsModelChildAlgorithmGraphicItem::showPreviousResults, this, [this, childId]
{
emit showChildAlgorithmOutputs( childId );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ class GUI_EXPORT QgsModelGraphicsScene : public QGraphicsScene
*/
void selectedItemChanged( QgsModelComponentGraphicItem *selected );

/**
* Emitted when the user opts to run the part of the model starting from the specified child algorithm.
*
* \since QGIS 3.38
*/
void runFromChild( const QString &childId );

/**
* Emitted when the user opts to view previous results from the child algorithm with matching ID.
*
Expand Down

0 comments on commit e6fb69c

Please sign in to comment.