Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
Medical Imaging Interaction Toolkit
berryCommandCategory.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 
13 #include "berryCommandCategory.h"
15 
16 #include <Poco/Exception.h>
17 #include <QTextStream>
18 
19 namespace berry {
20 
22 {
23  if (categoryListener == nullptr)
24  {
25  throw ctkInvalidArgumentException("Category listener cannot be null");
26  }
27 
28  categoryEvents.AddListener(categoryListener);
29 }
30 
31 void CommandCategory::Define(const QString& name, const QString& description)
32 {
33  if (name.isEmpty())
34  {
35  throw Poco::InvalidArgumentException(
36  "The name of a command cannot be empty"); //$NON-NLS-1$
37  }
38 
39  const bool definedChanged = !this->defined;
40  this->defined = true;
41 
42  const bool nameChanged = !(this->name == name);
43  this->name = name;
44 
45  const bool descriptionChanged = !(this->description == description);
46  this->description = description;
47 
48  const CommandCategoryEvent::Pointer categoryEvent(new CommandCategoryEvent(CommandCategory::Pointer(this), definedChanged,
49  descriptionChanged, nameChanged));
50  this->FireCategoryChanged(categoryEvent);
51 }
52 
54 {
55  if (categoryListener == nullptr)
56  {
57  throw ctkInvalidArgumentException("CommandCategory listener cannot be null");
58  }
59 
60  categoryEvents.RemoveListener(categoryListener);
61 }
62 
64 {
65  if (str.isEmpty())
66  {
67  QTextStream stringBuffer(&str);
68  stringBuffer << "Category(" << id << "," << name << "," << description << "," << defined << ")";
69  }
70  return str;
71 }
72 
74  str = "";
75 
76  const bool definedChanged = defined;
77  defined = false;
78 
79  const bool nameChanged = !name.isEmpty();
80  name = "";
81 
82  const bool descriptionChanged = !description.isEmpty();
83  description = "";
84 
85  const CommandCategoryEvent::Pointer categoryEvent(new CommandCategoryEvent(CommandCategory::Pointer(this), definedChanged,
86  descriptionChanged, nameChanged));
87  this->FireCategoryChanged(categoryEvent);
88 }
89 
92 {
93 
94 }
95 
96 void CommandCategory::FireCategoryChanged(const CommandCategoryEvent::Pointer categoryEvent) {
97  if (!categoryEvent) {
98  throw ctkInvalidArgumentException("Command category event cannot be null");
99  }
100  categoryEvents.categoryChanged(categoryEvent);
101 }
102 
103 }
void RemoveListener(ICommandCategoryListener *listener)
void AddListener(ICommandCategoryListener *listener)
QString ToString() const override
CommandCategory(const QString &id)
void Define(const QString &name, const QString &description)
void AddCategoryListener(ICommandCategoryListener *categoryListener)
void RemoveCategoryListener(ICommandCategoryListener *categoryListener)