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