CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Properties | List of all members
ctkWorkflow Class Reference

ctkWorkflow is the basis for a workflow engine, i.e. a state machine with enhancements to support ctkWorkflowStep. More...

#include <Libs/Core/ctkWorkflow.h>

Inheritance diagram for ctkWorkflow:
Inheritance graph
[legend]
Collaboration diagram for ctkWorkflow:
Collaboration graph
[legend]

Public Types

typedef QObject Superclass
 
enum  TransitionDirectionality { Bidirectional = 0 , Forward , Backward }
 Transition directionalities. More...
 

Public Slots

virtual void evaluateValidationResults (bool validationSucceeded, const QString &branchId)
 Receives the result of a step's validate(const QString&) function. More...
 
virtual void goBackward (const QString &desiredBranchId=QString())
 Use this to trigger transition to the previous step (does not require validation) More...
 
virtual void goForward (const QString &desiredBranchId=QString())
 
virtual void goToStep (const QString &targetId)
 Go to the given step by iteratively calling goForward() until we reach it. More...
 

Signals

void currentStepChanged (ctkWorkflowStep *currentStep)
 
void stepRegistered (ctkWorkflowStep *step)
 

Public Member Functions

virtual Q_INVOKABLE bool addTransition (ctkWorkflowStep *origin, ctkWorkflowStep *destination, const QString &branchId=QString(), const ctkWorkflow::TransitionDirectionality directionality=ctkWorkflow::Bidirectional)
 Creates a transition between two steps, and adds the two steps to the workflow if they have not been previously added. (Cannot add two steps with the same id). More...
 
Q_INVOKABLE int backwardDistanceToStep (ctkWorkflowStep *fromStep=0, ctkWorkflowStep *origin=0) const
 
Q_INVOKABLE QList< ctkWorkflowStep * > backwardSteps (ctkWorkflowStep *step=0) const
 
Q_INVOKABLE bool canGoBackward (ctkWorkflowStep *step=0) const
 
Q_INVOKABLE bool canGoForward (ctkWorkflowStep *step=0) const
 
Q_INVOKABLE bool canGoToStep (const QString &targetId, ctkWorkflowStep *step=0) const
 
 ctkWorkflow (QObject *parent=0)
 
Q_INVOKABLE ctkWorkflowStepcurrentStep () const
 
Q_INVOKABLE QList< ctkWorkflowStep * > finishSteps () const
 Get the steps that are 'finish' steps (i.e. have no step following them) More...
 
Q_INVOKABLE QList< ctkWorkflowStep * > forwardSteps (ctkWorkflowStep *step=0) const
 
bool goBackToOriginStepUponSuccess () const
 
Q_INVOKABLE bool hasStep (const QString &id) const
 
Q_INVOKABLE bool hasTransition (ctkWorkflowStep *origin, ctkWorkflowStep *destination, const QString &branchId=QString(), const ctkWorkflow::TransitionDirectionality directionality=ctkWorkflow::Bidirectional)
 Determine whether a transition has already been added. More...
 
Q_INVOKABLE ctkWorkflowStepinitialStep () const
 Set/get the initial step. More...
 
bool isRunning () const
 Returns whether the workflow is currently running. More...
 
void setGoBackToOriginStepUponSuccess (bool flag)
 
virtual Q_INVOKABLE void setInitialStep (ctkWorkflowStep *step)
 
void setVerbose (bool value)
 
virtual Q_INVOKABLE void start ()
 Start the workflow. The workflow will always start in the initial step, even if it is stopped and restarted). More...
 
Q_INVOKABLE ctkWorkflowStepstep (const QString &id) const
 
Q_INVOKABLE QList< ctkWorkflowStep * > steps () const
 Returns list of steps managed by the workflow. More...
 
virtual Q_INVOKABLE void stop ()
 Stops the workflow. More...
 
bool verbose () const
 If set debug messages will be displayed on standard output. More...
 
virtual ~ctkWorkflow ()
 

Protected Slots

void attemptToGoToNextStep ()
 
void performTransitionBetweenSteps ()
 Called when transitioning to the next step upon successful validation, or when transitioning to the previous step. Calls onExit() of the transition's origin step and then onEntry() of the transition's destination step. More...
 

Protected Member Functions

void goFromGoToStepToStartingStep ()
 Goes to the step from which the attempt to go to the 'goTo' step was initiated. More...
 
void goToNextStepAfterSuccessfulValidation (const QString &branchId)
 
void goToProcessingStateAfterValidationFailed ()
 
virtual void goToStepFailed ()
 Processing that occurs after the attempt to go to a 'goTo' step fails. More...
 
virtual void goToStepSucceeded ()
 Processing that occurs after the attempt to go to a 'goTo' step succeeds. More...
 

Protected Attributes

QScopedPointer< ctkWorkflowPrivate > d_ptr
 

Properties

bool goBackToOriginStepUponSuccess
 
bool isRunning
 
bool verbose
 

Detailed Description

ctkWorkflow is the basis for a workflow engine, i.e. a state machine with enhancements to support ctkWorkflowStep.

Definition at line 39 of file ctkWorkflow.h.

Member Typedef Documentation

◆ Superclass

typedef QObject ctkWorkflow::Superclass

Definition at line 49 of file ctkWorkflow.h.

Member Enumeration Documentation

◆ TransitionDirectionality

Transition directionalities.

The direction of transitions between an origin step and a destination step can be either:

  • Bidirectional: A transition from the origin to the destination, and a transition from the destination to the origin
  • Forward: A transition from the origin to the destination only
  • Backward: A transition from the destination to the origin only
Enumerator
Bidirectional 
Forward 
Backward 

Definition at line 74 of file ctkWorkflow.h.

Constructor & Destructor Documentation

◆ ctkWorkflow()

ctkWorkflow::ctkWorkflow ( QObject *  parent = 0)
explicit

◆ ~ctkWorkflow()

virtual ctkWorkflow::~ctkWorkflow ( )
virtual

Member Function Documentation

◆ addTransition()

virtual Q_INVOKABLE bool ctkWorkflow::addTransition ( ctkWorkflowStep origin,
ctkWorkflowStep destination,
const QString &  branchId = QString(),
const ctkWorkflow::TransitionDirectionality  directionality = ctkWorkflow::Bidirectional 
)
virtual

Creates a transition between two steps, and adds the two steps to the workflow if they have not been previously added. (Cannot add two steps with the same id).

The destination step should semantically be a next step, i.e. from a workflow perspective, the destination step is meant to appear after the origin step.

To add a single step, destination can be set to 0.

Returns true/false indicating whether the method was successful.

◆ attemptToGoToNextStep

void ctkWorkflow::attemptToGoToNextStep ( )
protectedslot

On an attempt to go to the next step, calls the current step's validate(const QString&) function to validate the processing step.

◆ backwardDistanceToStep()

Q_INVOKABLE int ctkWorkflow::backwardDistanceToStep ( ctkWorkflowStep fromStep = 0,
ctkWorkflowStep origin = 0 
) const

◆ backwardSteps()

Q_INVOKABLE QList<ctkWorkflowStep*> ctkWorkflow::backwardSteps ( ctkWorkflowStep step = 0) const

Get the steps that directly preceed the given step.

More specifically, the returned list of steps will be the origin steps for which addTransition() has been called with the given step as the destination step and directionality set to ctkWorkflow::Bidirectional or ctkWorkflow::Backward.

If no step is given, then the workflow's current step will be used.

◆ canGoBackward()

Q_INVOKABLE bool ctkWorkflow::canGoBackward ( ctkWorkflowStep step = 0) const

Returns whether or not we can go backward: i.e. there exists a step that directly preceeds the given step.

If no step is given, then the workflow's current step will be used.

◆ canGoForward()

Q_INVOKABLE bool ctkWorkflow::canGoForward ( ctkWorkflowStep step = 0) const

Returns whether or not we can go forward: i.e. there exists a step that directly follows the given step.

If no step is given, then the workflow's current step will be used.

◆ canGoToStep()

Q_INVOKABLE bool ctkWorkflow::canGoToStep ( const QString &  targetId,
ctkWorkflowStep step = 0 
) const

Returns whether or not we can go to the goal step from the origin step: i.e. there is a path in the workflow from the current step to the given step.

If no step is designated as the 'origin', then the workflow's current step will be used Note: does not currently work in branching workflows if the origin and target steps are not on the same branch

◆ currentStep()

Q_INVOKABLE ctkWorkflowStep* ctkWorkflow::currentStep ( ) const

Get the current step of the state machine

See also
initialStep(), step(), hasStep(), steps()

◆ currentStepChanged

void ctkWorkflow::currentStepChanged ( ctkWorkflowStep currentStep)
signal

Emitted when the current step has changed, after the step's onEntry() has completed.

Note
This signal is not emitted in the process of going to a goToStep

◆ evaluateValidationResults

virtual void ctkWorkflow::evaluateValidationResults ( bool  validationSucceeded,
const QString &  branchId 
)
virtualslot

Receives the result of a step's validate(const QString&) function.

If the validation is successful, then this slot begins the transition to the next step.

◆ finishSteps()

Q_INVOKABLE QList<ctkWorkflowStep*> ctkWorkflow::finishSteps ( ) const

Get the steps that are 'finish' steps (i.e. have no step following them)

◆ forwardSteps()

Q_INVOKABLE QList<ctkWorkflowStep*> ctkWorkflow::forwardSteps ( ctkWorkflowStep step = 0) const

Get the steps that directly follow the given step.

More specifically, the returned list of steps will be the destination steps for which addTransition() has been called with the given step as the origin step and directionality set to ctkWorkflow::Bidirectional or ctkWorkflow::Forward.

If no step is given, then the workflow's current step will be used.

◆ goBackToOriginStepUponSuccess()

bool ctkWorkflow::goBackToOriginStepUponSuccess ( ) const

Configures the behavior of goToStep(targetId).

If set to true, goToStep(targetId) goes back to the origin step after the attempt of going to the target step succeeded. If set to false, goToStep(targetId) stays at the target step when the attempt succeeded.

◆ goBackward

virtual void ctkWorkflow::goBackward ( const QString &  desiredBranchId = QString())
virtualslot

Use this to trigger transition to the previous step (does not require validation)

◆ goForward

virtual void ctkWorkflow::goForward ( const QString &  desiredBranchId = QString())
virtualslot

Use this to trigger evaluation of the processing state of the current step, and subsequent conditional transition to the next step.

◆ goFromGoToStepToStartingStep()

void ctkWorkflow::goFromGoToStepToStartingStep ( )
protected

Goes to the step from which the attempt to go to the 'goTo' step was initiated.

◆ goToNextStepAfterSuccessfulValidation()

void ctkWorkflow::goToNextStepAfterSuccessfulValidation ( const QString &  branchId)
protected

◆ goToProcessingStateAfterValidationFailed()

void ctkWorkflow::goToProcessingStateAfterValidationFailed ( )
protected

◆ goToStep

virtual void ctkWorkflow::goToStep ( const QString &  targetId)
virtualslot

Go to the given step by iteratively calling goForward() until we reach it.

◆ goToStepFailed()

virtual void ctkWorkflow::goToStepFailed ( )
protectedvirtual

Processing that occurs after the attempt to go to a 'goTo' step fails.

◆ goToStepSucceeded()

virtual void ctkWorkflow::goToStepSucceeded ( )
protectedvirtual

Processing that occurs after the attempt to go to a 'goTo' step succeeds.

◆ hasStep()

Q_INVOKABLE bool ctkWorkflow::hasStep ( const QString &  id) const

Check to see if there is a step with a given id in the workflow.

See also
step(), currentStep(), steps()

◆ hasTransition()

Q_INVOKABLE bool ctkWorkflow::hasTransition ( ctkWorkflowStep origin,
ctkWorkflowStep destination,
const QString &  branchId = QString(),
const ctkWorkflow::TransitionDirectionality  directionality = ctkWorkflow::Bidirectional 
)

Determine whether a transition has already been added.

  • If a branch id is not given or is empty: a transition exists if a transition has been previously added with the same origin, destination and directionality
  • If a non-empty branch id is given: a transition exists if the transition has been previously added with the same origin, destination and directionality, OR if a transition has been previously added with the same origin and branch id (for forward transitions) or with the same destination and branch id (for backward transitions)

◆ initialStep()

Q_INVOKABLE ctkWorkflowStep* ctkWorkflow::initialStep ( ) const

Set/get the initial step.

Note
In not specified, the first step added will be considered as the initialStep
See also
currentStep(), step(), hasStep(), steps()

◆ isRunning()

bool ctkWorkflow::isRunning ( ) const

Returns whether the workflow is currently running.

◆ performTransitionBetweenSteps

void ctkWorkflow::performTransitionBetweenSteps ( )
protectedslot

Called when transitioning to the next step upon successful validation, or when transitioning to the previous step. Calls onExit() of the transition's origin step and then onEntry() of the transition's destination step.

Note
Must be sent by a ctkWorkflowTransition.

◆ setGoBackToOriginStepUponSuccess()

void ctkWorkflow::setGoBackToOriginStepUponSuccess ( bool  flag)

◆ setInitialStep()

virtual Q_INVOKABLE void ctkWorkflow::setInitialStep ( ctkWorkflowStep step)
virtual

◆ setVerbose()

void ctkWorkflow::setVerbose ( bool  value)

◆ start()

virtual Q_INVOKABLE void ctkWorkflow::start ( )
virtual

Start the workflow. The workflow will always start in the initial step, even if it is stopped and restarted).

Note
Calls onEntry() for the initial step.

◆ step()

Q_INVOKABLE ctkWorkflowStep* ctkWorkflow::step ( const QString &  id) const

Return the step with matching id if any, 0 otherwise.

See also
hasStep(), currentStep(), steps()

◆ stepRegistered

void ctkWorkflow::stepRegistered ( ctkWorkflowStep step)
signal

Emitted when a step is registered with this workflow

See also
addTransition

◆ steps()

Q_INVOKABLE QList<ctkWorkflowStep*> ctkWorkflow::steps ( ) const

Returns list of steps managed by the workflow.

◆ stop()

virtual Q_INVOKABLE void ctkWorkflow::stop ( )
virtual

Stops the workflow.

Note
Calls onExit() for the current step.

◆ verbose()

bool ctkWorkflow::verbose ( ) const

If set debug messages will be displayed on standard output.

Member Data Documentation

◆ d_ptr

QScopedPointer<ctkWorkflowPrivate> ctkWorkflow::d_ptr
protected

Definition at line 247 of file ctkWorkflow.h.

Property Documentation

◆ goBackToOriginStepUponSuccess

bool ctkWorkflow::goBackToOriginStepUponSuccess
readwrite

Definition at line 1 of file ctkWorkflow.h.

◆ isRunning

bool ctkWorkflow::isRunning
read

Definition at line 1 of file ctkWorkflow.h.

◆ verbose

bool ctkWorkflow::verbose
readwrite

Definition at line 1 of file ctkWorkflow.h.


The documentation for this class was generated from the following file: