GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
itkQtAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkQtAdaptor.h,v $
5  Language: C++
6  Date: $Date: 2002-09-13 14:32:40 $
7  Version: $Revision: 1.4 $
8 
9  Copyright (c) 2002 Insight Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 /*=========================================================================
19  Modifications were made by the GoFigure Dev. Team.
20  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
21 
22  Copyright (c) 2009-11, President and Fellows of Harvard College.
23  All rights reserved.
24 
25  Redistribution and use in source and binary forms, with or without
26  modification, are permitted provided that the following conditions are met:
27 
28  Redistributions of source code must retain the above copyright notice,
29  this list of conditions and the following disclaimer.
30  Redistributions in binary form must reproduce the above copyright notice,
31  this list of conditions and the following disclaimer in the documentation
32  and/or other materials provided with the distribution.
33  Neither the name of the President and Fellows of Harvard College
34  nor the names of its contributors may be used to endorse or promote
35  products derived from this software without specific prior written
36  permission.
37 
38  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
40  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
42  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
43  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
44  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
45  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
48  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 
50 =========================================================================*/
51 
52 #ifndef __itkQtAdaptor_h
53 #define __itkQtAdaptor_h
54 
55 #include <QObject>
56 #include "itkObject.h"
57 #include "itkObjectFactory.h"
58 #include "itkCommand.h"
59 
60 #include "itkQtConfigure.h"
61 
62 namespace itk
63 {
65 class IKTQT_EXPORT QtTranslator:public QObject
66 {
67  Q_OBJECT
68 public:
70  virtual ~QtTranslator() {}
71 signals:
72  void Signal();
73 
74 public slots:
75  virtual void Slot() {}
76  virtual void Slot(int) {}
77  virtual void Slot(double) {}
78 };
79 
81 template< typename T >
82 class IKTQT_EXPORT QtSlotAdaptor:public QtTranslator
83 {
84  typedef void ( T::*TMemberFunctionVoidPointer )();
85  typedef void ( T::*TMemberFunctionIntPointer )(int);
86  typedef void ( T::*TMemberFunctionDoublePointer )(double);
87 public:
88  QtSlotAdaptor():m_MemberFunctionVoid(0),
89  m_MemberFunctionInt(0),
90  m_MemberFunctionDouble(0) {}
91 
92  virtual ~QtSlotAdaptor() {}
93 
95  void SetCallbackFunction(T *object,
96  TMemberFunctionVoidPointer memberFunction)
97  {
98  m_This = object;
99  m_MemberFunctionVoid = memberFunction;
100  }
101 
103  void SetCallbackFunction(T *object,
104  TMemberFunctionIntPointer memberFunction)
105  {
106  m_This = object;
107  m_MemberFunctionInt = memberFunction;
108  }
109 
111  void SetCallbackFunction(T *object,
112  TMemberFunctionDoublePointer memberFunction)
113  {
114  m_This = object;
115  m_MemberFunctionDouble = memberFunction;
116  }
117 
119  void Slot()
120  {
121  if ( m_MemberFunctionVoid )
122  {
123  ( ( *m_This ).*( m_MemberFunctionVoid ) )( );
124  }
125  }
126 
128  void Slot(int value)
129  {
130  if ( m_MemberFunctionInt )
131  {
132  ( ( *m_This ).*( m_MemberFunctionInt ) )( value );
133  }
134  }
135 
137  void Slot(double value)
138  {
139  if ( m_MemberFunctionDouble )
140  {
141  ( ( *m_This ).*( m_MemberFunctionDouble ) )( value );
142  }
143  }
144 
145 protected:
146  T * m_This;
147  TMemberFunctionVoidPointer m_MemberFunctionVoid;
148  TMemberFunctionIntPointer m_MemberFunctionInt;
149  TMemberFunctionDoublePointer m_MemberFunctionDouble;
150 };
151 
153 class IKTQT_EXPORT QtSignalAdaptor:public QtTranslator
154 {
155  typedef SimpleMemberCommand< QtSignalAdaptor > CommandType;
156 public:
158  {
159  m_Command = CommandType::New();
160  m_Command->SetCallbackFunction(this, &QtSignalAdaptor::EmitSignal);
161  }
162 
163  virtual ~QtSignalAdaptor() {}
164 
166  {
167  return m_Command;
168  }
169 
170  void EmitSignal()
171  {
172  emit Signal();
173  }
174 
175 private:
176  CommandType::Pointer m_Command;
177 };
178 } // end namespace
179 
180 #endif
void Slot(int value)
Definition: itkQtAdaptor.h:128
void SetCallbackFunction(T *object, TMemberFunctionDoublePointer memberFunction)
Definition: itkQtAdaptor.h:111
TMemberFunctionDoublePointer m_MemberFunctionDouble
Definition: itkQtAdaptor.h:149
virtual ~QtSlotAdaptor()
Definition: itkQtAdaptor.h:92
virtual void Slot(double)
Definition: itkQtAdaptor.h:77
virtual void Slot()
Definition: itkQtAdaptor.h:75
CommandType::Pointer m_Command
Definition: itkQtAdaptor.h:176
CommandType * GetCommand()
Definition: itkQtAdaptor.h:165
SimpleMemberCommand< QtSignalAdaptor > CommandType
Definition: itkQtAdaptor.h:155
void SetCallbackFunction(T *object, TMemberFunctionVoidPointer memberFunction)
Definition: itkQtAdaptor.h:95
TMemberFunctionVoidPointer m_MemberFunctionVoid
Definition: itkQtAdaptor.h:147
void SetCallbackFunction(T *object, TMemberFunctionIntPointer memberFunction)
Definition: itkQtAdaptor.h:103
virtual ~QtSignalAdaptor()
Definition: itkQtAdaptor.h:163
virtual void Slot(int)
Definition: itkQtAdaptor.h:76
TMemberFunctionIntPointer m_MemberFunctionInt
Definition: itkQtAdaptor.h:148
void Slot(double value)
Definition: itkQtAdaptor.h:137
virtual ~QtTranslator()
Definition: itkQtAdaptor.h:70