Skip to content

Commit

Permalink
Add Run Selected option to right click menu for selected algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 3, 2024
1 parent e6fb69c commit 2f5ad6b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ Sets the ``results`` obtained for this child algorithm for the last model execut
%Docstring
Emitted when the user opts to run the model from this child algorithm.

.. versionadded:: 3.38
%End

void runSelected();
%Docstring
Emitted when the user opts to run selected steps from the model.

.. versionadded:: 3.38
%End

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 runSelected();
%Docstring
Emitted when the user opts to run selected steps from the model.

.. versionadded:: 3.38
%End

void runFromChild( const QString &childId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ Sets the ``results`` obtained for this child algorithm for the last model execut
%Docstring
Emitted when the user opts to run the model from this child algorithm.

.. versionadded:: 3.38
%End

void runSelected();
%Docstring
Emitted when the user opts to run selected steps from the model.

.. versionadded:: 3.38
%End

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 runSelected();
%Docstring
Emitted when the user opts to run selected steps from the model.

.. versionadded:: 3.38
%End

void runFromChild( const QString &childId );
Expand Down
9 changes: 9 additions & 0 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,18 @@ QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcess
void QgsModelChildAlgorithmGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
{
QMenu *popupmenu = new QMenu( event->widget() );

if ( isSelected() )
{
QAction *runSelectedStepsAction = popupmenu->addAction( QObject::tr( "Run Selected Steps…" ) );
runSelectedStepsAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStart.svg" ) ) );
connect( runSelectedStepsAction, &QAction::triggered, this, &QgsModelChildAlgorithmGraphicItem::runSelected );
}

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" ) );
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 @@ -475,6 +475,13 @@ class GUI_EXPORT QgsModelChildAlgorithmGraphicItem : public QgsModelComponentGra
*/
void runFromHere();

/**
* Emitted when the user opts to run selected steps from the model.
*
* \since QGIS 3.38
*/
void runSelected();

/**
* Emitted when the user opts to view previous results from this child algorithm.
*
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodeldesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,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::runSelected, this, &QgsModelDesignerDialog::runSelectedSteps );
connect( mScene, &QgsModelGraphicsScene::showChildAlgorithmOutputs, this, &QgsModelDesignerDialog::showChildAlgorithmOutputs );
connect( mScene, &QgsModelGraphicsScene::showChildAlgorithmLog, this, &QgsModelDesignerDialog::showChildAlgorithmLog );

Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodelgraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void QgsModelGraphicsScene::createItems( QgsProcessingModelAlgorithm *model, Qgs
{
emit runFromChild( childId );
} );
connect( item, &QgsModelChildAlgorithmGraphicItem::runSelected, this, &QgsModelGraphicsScene::runSelected );
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 selected steps from the model.
*
* \since QGIS 3.38
*/
void runSelected();

/**
* Emitted when the user opts to run the part of the model starting from the specified child algorithm.
*
Expand Down

0 comments on commit 2f5ad6b

Please sign in to comment.