Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryAbstractHandlerWithState.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "berryState.h"
20 
21 namespace berry {
22 
23 void AbstractHandlerWithState::AddState(const QString& stateId, const SmartPointer<State>& state)
24 {
25  if (state.IsNull())
26  {
27  throw ctkInvalidArgumentException("Cannot add a null state");
28  }
29 
30  states.insert(stateId, state);
31  state->AddListener(this);
32  HandleStateChange(state, Object::Pointer(nullptr));
33 }
34 
36 {
37  QHash<QString,State::Pointer>::const_iterator i = states.find(stateId);
38  if (i != states.end()) return *i;
39  return State::Pointer(nullptr);
40 }
41 
43 {
44  return states.keys();
45 }
46 
47 void AbstractHandlerWithState::RemoveState(const QString& stateId)
48 {
49  if (stateId.isNull())
50  {
51  throw ctkInvalidArgumentException("Cannot remove a null state");
52  }
53 
54  QHash<QString,State::Pointer>::iterator i = states.find(stateId);
55  if (i != states.end())
56  {
57  (*i)->RemoveListener(this);
58  states.erase(i);
59  }
60 }
61 
62 }
Implements transparent reference counting.
virtual void HandleStateChange(const SmartPointer< State > &state, const SmartPointer< Object > &oldValue)=0
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:88
void RemoveState(const QString &stateId) override
QList< QString > GetStateIds() const override
SmartPointer< State > GetState(const QString &stateId) const override