NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkQtSignalCollector.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkQtSignalCollector_h
16 #define niftkQtSignalCollector_h
17 
18 #include <QObject>
19 
20 #include <mitkCommon.h>
21 #include <itkObject.h>
22 #include <itkObjectFactory.h>
23 
24 #include <vector>
25 
26 namespace niftk
27 {
28 
33 {
34 public:
35  virtual void OnQtSignalReceived(const QObject* object, const char* signal) = 0;
36 };
37 
38 
42 class QtSignalNotifier : public QObject
43 {
44  Q_OBJECT
45 
46 public:
47 
48  QtSignalNotifier(QtSignalListener* signalListener, const QObject* object, const char* signal);
49 
50  virtual ~QtSignalNotifier();
51 
52 private slots:
53 
54  virtual void OnQtSignalReceived();
55 
56 private:
57 
58  QtSignalListener* m_QtSignalListener;
59  const QObject* m_Object;
60  QByteArray m_Signal;
61 };
62 
63 
67 class QtSignalCollector : public QObject, public itk::Object, private QtSignalListener
68 {
69  Q_OBJECT
70 
71 public:
73  itkNewMacro(QtSignalCollector)
74 
75  typedef std::pair<const QObject*, QByteArray> Signal;
76  typedef std::vector<Signal> Signals;
77 
80  void Connect(const QObject* object, const char* signal = 0);
81 
83  void AddListener(QtSignalListener* listener);
84 
87  void RemoveListener(QtSignalListener* listener);
88 
90  const Signals& GetSignals() const;
91 
93  Signals GetSignals(const char* signal) const;
94 
97  Signals GetSignals(const QObject* object, const char* signal = 0) const;
98 
100  virtual void Clear();
101 
102 protected:
103 
106 
108  virtual ~QtSignalCollector();
109 
111  virtual void PrintSelf(std::ostream & os, itk::Indent indent) const override;
112 
114  virtual void OnQtSignalReceived(const QObject* object, const char* signal) override;
115 
116 private:
117 
119  Signals m_Signals;
120 
122  std::vector<QtSignalNotifier*> m_SignalNotifiers;
123 
125  std::vector<QtSignalListener*> m_Listeners;
126 
127 };
128 
129 }
130 
131 #endif
std::vector< Signal > Signals
Definition: niftkQtSignalCollector.h:76
virtual void Clear()
Clears all the signals collected by now.
Definition: niftkQtSignalCollector.cxx:151
Abstract class to be implemented by Qt signal listeners.
Definition: niftkQtSignalCollector.h:32
void AddListener(QtSignalListener *listener)
Adds a listener that will get notified of the Qt signals that this object is connected to...
Definition: niftkQtSignalCollector.cxx:79
Definition: niftkMeshSmoother.cxx:19
Definition: niftkITKAffineResampleImage.cxx:74
virtual void OnQtSignalReceived(const QObject *object, const char *signal) override
Adds the object-signal pair to the list of collected signals.
Definition: niftkQtSignalCollector.cxx:127
const Signals & GetSignals() const
Gets the signals collected by this object.
Definition: niftkQtSignalCollector.cxx:144
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the collected signals to the given stream or to the standard output if no stream is given...
Definition: niftkQtSignalCollector.cxx:158
Class for collecting Qt signals and sending notifications of them to registered listeners.
Definition: niftkQtSignalCollector.h:67
std::pair< const QObject *, QByteArray > Signal
Definition: niftkQtSignalCollector.h:75
void RemoveListener(QtSignalListener *listener)
Removes a listener. The listener will not get notified about the Qt signals observed by the current o...
Definition: niftkQtSignalCollector.cxx:90
virtual ~QtSignalNotifier()
Definition: niftkQtSignalCollector.cxx:35
QtSignalNotifier(QtSignalListener *signalListener, const QObject *object, const char *signal)
Definition: niftkQtSignalCollector.cxx:24
Helper class that implements a call back mechanism for Qt signals.
Definition: niftkQtSignalCollector.h:42
mitkClassMacroItkParent(QtSignalCollector, QObject) static Pointer New()
Definition: niftkExceptionObject.h:21
virtual void OnQtSignalReceived(const QObject *object, const char *signal)=0
void Connect(const QObject *object, const char *signal=0)
Connects this object to the signals of the given object. The current object will collect the given si...
Definition: niftkQtSignalCollector.cxx:71