NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxWorkflowStateMachine.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxWorkflowStateMachine.h"
13 #include <QAbstractTransition>
14 #include <QMenu>
15 #include <QToolBar>
16 #include "cxWorkflowState.h"
18 #include "cxPatientModelService.h"
19 #include "cxCoreServices.h"
20 
21 namespace cx
22 {
23 
25 {
26  mStarted = false;
27  connect(this, SIGNAL(started()), this, SLOT(startedSlot()));
28  mActionGroup = new QActionGroup(this);
29 
31 
32  connect(mServices->patient().get(), SIGNAL(clinicalApplicationChanged()), this, SLOT(clinicalApplicationChangedSlot()));
33 }
34 
36 {
37 }
38 
39 void WorkflowStateMachine::clinicalApplicationChangedSlot()
40 {
41  this->setActiveState("PatientDataUid");
42 }
43 
44 void WorkflowStateMachine::startedSlot()
45 {
46  mStarted = true;
47 }
48 
50 {
52  transToState->setTargetState(state);
53  mParentState->addTransition(transToState);
54 
55  connect(state, SIGNAL(entered()), this, SIGNAL(activeStateChanged()));
56 
57  mStates[state->getUid()] = state;
58 
59  connect(state, SIGNAL(aboutToExit()), this, SIGNAL(activeStateAboutToChange()));
60 
61  return state;
62 }
63 
65 {
66 // mActionGroup
67  this->fillActionGroup(mParentState, mActionGroup);
68 
69  QList<QAction *> actions = mActionGroup->actions();
70  for (int i = 1; i <= actions.size(); ++i)
71  {
72  QString shortcut = "Ctrl+" + QString::number(i);
73  actions[i - 1]->setShortcut(shortcut);
74  }
75 
76  return mActionGroup;
77 }
78 
79 void WorkflowStateMachine::fillActionGroup(WorkflowState* current, QActionGroup* group)
80 {
81  std::vector<WorkflowState*> childStates = current->getChildStates();
82 
83  if (childStates.empty())
84  {
85  group->addAction(current->createAction(group));
86  }
87  else // current is a node. create submenu and fill in recursively
88  {
89  for (unsigned i = 0; i < childStates.size(); ++i)
90  this->fillActionGroup(childStates[i], group);
91  }
92 }
93 
95 {
96 
97  if (mStarted)
98  this->postEvent(new RequestEnterStateEvent(uid));
99 }
100 
102 {
103  QSet<QAbstractState *> states = this->configuration();
104  for (QSet<QAbstractState *>::iterator iter = states.begin(); iter != states.end(); ++iter)
105  {
106  WorkflowState* wfs = dynamic_cast<WorkflowState*>(*iter);
107  if (!wfs || !wfs->getChildStates().empty())
108  continue;
109 
110  return wfs->getUid();
111  }
112  return QString();
113 }
114 
115 } //namespace cx
cxWorkflowStateMachine.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::WorkflowState
State in a WorkflowStateMachine.
Definition: cxWorkflowState.h:42
cx::ParentWorkflowState
Definition: cxWorkflowState.h:91
cxWorkflowState.h
cx::WorkflowStateMachine::activeStateAboutToChange
void activeStateAboutToChange()
cx::RequestEnterStateEvent
Utility class for StateService states.
Definition: cxRequestEnterStateTransition.h:31
cx::WorkflowState::getUid
virtual QString getUid() const
Definition: cxWorkflowState.h:61
cx::WorkflowStateMachine::setActiveState
void setActiveState(QString uid)
Definition: cxWorkflowStateMachine.cpp:94
cx::WorkflowStateMachine::activeStateChanged
void activeStateChanged()
cx::WorkflowStateMachine::newState
virtual WorkflowState * newState(WorkflowState *state)
Definition: cxWorkflowStateMachine.cpp:49
cx::CoreServicesPtr
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:37
cx::WorkflowStateMachine::WorkflowStateMachine
WorkflowStateMachine(CoreServicesPtr services)
Definition: cxWorkflowStateMachine.cpp:24
cxRequestEnterStateTransition.h
cx::WorkflowStateMachine::mParentState
WorkflowState * mParentState
Definition: cxWorkflowStateMachine.h:60
cxPatientModelService.h
cx::WorkflowState::getChildStates
std::vector< WorkflowState * > getChildStates()
Definition: cxWorkflowState.cpp:37
cx::WorkflowStateMachine::getActionGroup
QActionGroup * getActionGroup()
Definition: cxWorkflowStateMachine.cpp:64
cxCoreServices.h
cx::WorkflowStateMachine::getActiveUidState
QString getActiveUidState()
Definition: cxWorkflowStateMachine.cpp:101
cx::WorkflowStateMachine::~WorkflowStateMachine
virtual ~WorkflowStateMachine()
Definition: cxWorkflowStateMachine.cpp:35
cx::WorkflowState::createAction
QAction * createAction(QActionGroup *group)
Definition: cxWorkflowState.cpp:50
cx::RequestEnterStateTransition
Utility class for StateService states.
Definition: cxRequestEnterStateTransition.h:45
cx::WorkflowStateMachine::mServices
CoreServicesPtr mServices
Definition: cxWorkflowStateMachine.h:61