Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
berryCommandManagerEvent.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "berryCommandManager.h"
16 #include "berryIHandler.h"
17 #include "berryCommandCategory.h"
18 #include "berryParameterType.h"
19 
20 namespace berry
21 {
22 
23 const int CommandManagerEvent::CHANGED_CATEGORY_DEFINED = 1;
24 const int CommandManagerEvent::CHANGED_COMMAND_DEFINED = 1 << 1;
25 const int CommandManagerEvent::CHANGED_PARAMETER_TYPE_DEFINED = 1 << 2;
26 
28  const QString& commandId, const bool commandIdAdded,
29  const bool commandIdChanged, const QString& categoryId,
30  const bool categoryIdAdded, const bool categoryIdChanged) :
31  categoryId(categoryId), commandId(commandId), commandManager(commandManager)
32 {
33  // if (!commandManager) {
34  // throw Poco::NullPointerException(
35  // "An event must refer to its command manager");
36  // }
37 
38  if (commandIdChanged && (commandId.isEmpty()))
39  {
40  throw ctkInvalidArgumentException(
41  "If the list of defined commands changed, then the added/removed command must be mentioned");
42  }
43 
44  if (categoryIdChanged && (categoryId.isEmpty()))
45  {
46  throw ctkInvalidArgumentException(
47  "If the list of defined categories changed, then the added/removed category must be mentioned");
48  }
49 
50  int changedValues = 0;
51  if (categoryIdChanged && categoryIdAdded)
52  {
53  changedValues |= CHANGED_CATEGORY_DEFINED;
54  }
55  if (commandIdChanged && commandIdAdded)
56  {
57  changedValues |= CHANGED_COMMAND_DEFINED;
58  }
59  this->changedValues = changedValues;
60 }
61 
63  const QString& parameterTypeId, const bool parameterTypeIdAdded,
64  const bool parameterTypeIdChanged) :
65  parameterTypeId(parameterTypeId), commandManager(commandManager)
66 {
67 
68  // if (!commandManager) {
69  // throw Poco::NullPointerException(
70  // "An event must refer to its command manager"); //$NON-NLS-1$
71  // }
72 
73  if (parameterTypeIdChanged && (parameterTypeId.isEmpty()))
74  {
75  throw ctkInvalidArgumentException(
76  "If the list of defined command parameter types changed, then the added/removed parameter type must be mentioned"); //$NON-NLS-1$
77  }
78 
79  int changedValues = 0;
80  if (parameterTypeIdChanged && parameterTypeIdAdded)
81  {
82  changedValues |= CHANGED_PARAMETER_TYPE_DEFINED;
83  }
84 
85  this->changedValues = changedValues;
86 }
87 
89 {
90  return categoryId;
91 }
92 
94 {
95  return commandId;
96 }
97 
99 {
100  return commandManager;
101 }
102 
104 {
105  return parameterTypeId;
106 }
107 
109 {
110  return (!categoryId.isEmpty());
111 }
112 
114 {
115  return (((changedValues & CHANGED_CATEGORY_DEFINED) != 0)
116  && (!categoryId.isEmpty()));
117 }
118 
120 {
121  return (!commandId.isEmpty());
122 }
123 
125 {
126  return (((changedValues & CHANGED_COMMAND_DEFINED) != 0)
127  && (!commandId.isEmpty()));
128 }
129 
131 {
132  return (!parameterTypeId.isEmpty());
133 }
134 
136 {
137  return (((changedValues & CHANGED_PARAMETER_TYPE_DEFINED) != 0)
138  && (!parameterTypeId.isEmpty()));
139 }
140 
141 }
CommandManager & GetCommandManager() const
CommandManagerEvent(CommandManager &commandManager, const QString &commandId, const bool commandIdAdded, const bool commandIdChanged, const QString &categoryId, const bool categoryIdAdded, const bool categoryIdChanged)