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
berryParameterType.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 "berryParameterType.h"
18 #include "internal/berryCommandUtils.h"
20 
23 
24 #include <sstream>
25 
26 namespace berry
27 {
28 
30 {
31  parameterTypeEvents.AddListener(listener);
32 }
33 
34 bool ParameterType::operator<(const Object* object) const
35 {
36  const ParameterType* castedObject = dynamic_cast<const ParameterType*>(object);
37  int compareTo = CommandUtils::Compare(defined, castedObject->defined);
38  if (compareTo == 0)
39  {
40  compareTo = CommandUtils::Compare(id, castedObject->id);
41  }
42  return compareTo < 0;
43 }
44 
45 void ParameterType::Define(const QString& type,
46  const QSharedPointer<IParameterValueConverter>& parameterTypeConverter)
47 {
48  const bool definedChanged = !this->defined;
49  this->defined = true;
50 
51  this->type = type.isNull() ? QObject::staticMetaObject.className() : type;
52  this->parameterTypeConverter = parameterTypeConverter;
53 
55  new ParameterTypeEvent(ParameterType::Pointer(this), definedChanged));
56  this->FireParameterTypeChanged(event);
57 }
58 
60 {
61  if (!this->IsDefined())
62  {
63  throw NotDefinedException(
64  "Cannot use GetValueConverter() with an undefined ParameterType"); //$NON-NLS-1$
65  }
66 
67  return parameterTypeConverter.data();
68 }
69 
70 bool ParameterType::IsCompatible(const QObject* const value) const
71 {
72  if (!this->IsDefined())
73  {
74  throw NotDefinedException(
75  "Cannot use IsCompatible() with an undefined ParameterType");
76  }
77  return value->inherits(qPrintable(type));
78 }
79 
81 {
82  parameterTypeEvents.RemoveListener(listener);
83 }
84 
85 QString ParameterType::ToString() const
86 {
87  if (str.isEmpty())
88  {
89  QTextStream stringBuffer(&str);
90  stringBuffer << "ParameterType(" << id << "," << defined << ")";
91  }
92  return str;
93 }
94 
96 {
97  str = "";
98 
99  const bool definedChanged = defined;
100  defined = false;
101 
102  parameterTypeConverter.clear();
103 
105  new ParameterTypeEvent(ParameterType::Pointer(this), definedChanged));
106  this->FireParameterTypeChanged(event);
107 }
108 
109 ParameterType::ParameterType(const QString& id) :
110  HandleObject(id)
111 {
112 
113 }
114 
115 void ParameterType::FireParameterTypeChanged(const SmartPointer<
116  ParameterTypeEvent> event)
117 {
118  if (!event)
119  {
120  throw ctkInvalidArgumentException("Cannot send a null event to listeners.");
121  }
122 
123  parameterTypeEvents.parameterTypeChanged(event);
124 }
125 
126 }
QString ToString() const override
ParameterType(const QString &id)
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
void RemoveListener(IParameterTypeListener *listener)
void Define(const QString &type, const QSharedPointer< IParameterValueConverter > &parameterTypeConverter)
void RemoveListener(IParameterTypeListener *listener)
void AddListener(IParameterTypeListener *listener)
bool operator<(const Object *object) const override
bool IsCompatible(const QObject *const value) const
void AddListener(IParameterTypeListener *listener)
IParameterValueConverter * GetValueConverter() const