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