Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryCommandManagerEvent.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 "berryCommandManager.h"
20 #include "berryIHandler.h"
21 #include "berryCommandCategory.h"
22 #include "berryParameterType.h"
23 
24 namespace berry
25 {
26 
27 const int CommandManagerEvent::CHANGED_CATEGORY_DEFINED = 1;
28 const int CommandManagerEvent::CHANGED_COMMAND_DEFINED = 1 << 1;
29 const int CommandManagerEvent::CHANGED_PARAMETER_TYPE_DEFINED = 1 << 2;
30 
32  const QString& commandId, const bool commandIdAdded,
33  const bool commandIdChanged, const QString& categoryId,
34  const bool categoryIdAdded, const bool categoryIdChanged) :
35  categoryId(categoryId), commandId(commandId), commandManager(commandManager)
36 {
37  // if (!commandManager) {
38  // throw Poco::NullPointerException(
39  // "An event must refer to its command manager");
40  // }
41 
42  if (commandIdChanged && (commandId.isEmpty()))
43  {
44  throw ctkInvalidArgumentException(
45  "If the list of defined commands changed, then the added/removed command must be mentioned");
46  }
47 
48  if (categoryIdChanged && (categoryId.isEmpty()))
49  {
50  throw ctkInvalidArgumentException(
51  "If the list of defined categories changed, then the added/removed category must be mentioned");
52  }
53 
54  int changedValues = 0;
55  if (categoryIdChanged && categoryIdAdded)
56  {
57  changedValues |= CHANGED_CATEGORY_DEFINED;
58  }
59  if (commandIdChanged && commandIdAdded)
60  {
61  changedValues |= CHANGED_COMMAND_DEFINED;
62  }
63  this->changedValues = changedValues;
64 }
65 
67  const QString& parameterTypeId, const bool parameterTypeIdAdded,
68  const bool parameterTypeIdChanged) :
69  parameterTypeId(parameterTypeId), commandManager(commandManager)
70 {
71 
72  // if (!commandManager) {
73  // throw Poco::NullPointerException(
74  // "An event must refer to its command manager"); //$NON-NLS-1$
75  // }
76 
77  if (parameterTypeIdChanged && (parameterTypeId.isEmpty()))
78  {
79  throw ctkInvalidArgumentException(
80  "If the list of defined command parameter types changed, then the added/removed parameter type must be mentioned"); //$NON-NLS-1$
81  }
82 
83  int changedValues = 0;
84  if (parameterTypeIdChanged && parameterTypeIdAdded)
85  {
86  changedValues |= CHANGED_PARAMETER_TYPE_DEFINED;
87  }
88 
89  this->changedValues = changedValues;
90 }
91 
93 {
94  return categoryId;
95 }
96 
98 {
99  return commandId;
100 }
101 
103 {
104  return commandManager;
105 }
106 
108 {
109  return parameterTypeId;
110 }
111 
113 {
114  return (!categoryId.isEmpty());
115 }
116 
118 {
119  return (((changedValues & CHANGED_CATEGORY_DEFINED) != 0)
120  && (!categoryId.isEmpty()));
121 }
122 
124 {
125  return (!commandId.isEmpty());
126 }
127 
129 {
130  return (((changedValues & CHANGED_COMMAND_DEFINED) != 0)
131  && (!commandId.isEmpty()));
132 }
133 
135 {
136  return (!parameterTypeId.isEmpty());
137 }
138 
140 {
141  return (((changedValues & CHANGED_PARAMETER_TYPE_DEFINED) != 0)
142  && (!parameterTypeId.isEmpty()));
143 }
144 
145 }
CommandManager & GetCommandManager() const
CommandManagerEvent(CommandManager &commandManager, const QString &commandId, const bool commandIdAdded, const bool commandIdChanged, const QString &categoryId, const bool categoryIdAdded, const bool categoryIdChanged)