Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
berryIPropertyChangeListener.h
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 #ifndef BERRYIPROPERTYCHANGELISTENER_H_
14 #define BERRYIPROPERTYCHANGELISTENER_H_
15 
16 #include <berryMacros.h>
17 #include <berryMessage.h>
18 
21 
22 namespace berry
23 {
24 
43 {
44 
45  virtual ~IPropertyChangeListener();
46 
48 
50 
51  EventType propertyChange;
52 
53  void AddListener(IPropertyChangeListener* listener);
54  void RemoveListener(IPropertyChangeListener* listener);
55 
56  private:
57 
59  };
60 
71  virtual void PropertyChange(const PropertyChangeEvent::Pointer& event);
72 
73  virtual void PropertyChange(const Object::Pointer& /*source*/, int /*propId*/) {}
74 };
75 
76 template<typename R>
78 {
79 
80  typedef R Listener;
81  typedef void
82  (R::*Callback)(const PropertyChangeEvent::Pointer&);
83 
84  PropertyChangeAdapter(R* l, Callback c) :
85  listener(l), callback(c)
86  {
87  poco_assert(listener);
88  poco_assert(callback);
89  }
90 
92 
93  void PropertyChange(const PropertyChangeEvent::Pointer& event) override
94  {
95  (listener->*callback)(event);
96  }
97 
98 private:
99 
100  Listener* listener;
101  Callback callback;
102 };
103 
104 template<typename R>
106 {
107 
108  typedef R Listener;
109  typedef void
110  (R::*Callback)(const Object::Pointer&, int);
111 
112  PropertyChangeIntAdapter(R* l, Callback c) :
113  listener(l), callback(c)
114  {
115  poco_assert(listener);
116  poco_assert(callback);
117  }
118 
120 
121  void PropertyChange(const Object::Pointer& source, int propId) override
122  {
123  (listener->*callback)(source, propId);
124  }
125 
126 private:
127 
128  Listener* listener;
129  Callback callback;
130 };
131 
132 }
133 
134 #endif /* BERRYIPROPERTYCHANGELISTENER_H_ */
Message1< const PropertyChangeEvent::Pointer & > EventType
virtual void PropertyChange(const Object::Pointer &, int)
virtual void PropertyChange(const PropertyChangeEvent::Pointer &event)
void PropertyChange(const PropertyChangeEvent::Pointer &event) override
void PropertyChange(const Object::Pointer &source, int propId) override
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:82
#define BERRY_UI_QT