GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericEventNotify.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2015 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifndef __GenericEventNotify_h__
24 #define __GenericEventNotify_h__ 1
25 
26 #include <QSet>
27 
28 class QEvent;
29 class QObject;
30 class QWidget;
31 
32 namespace QtHandles
33 {
34 
35 class GenericEventNotifyReceiver;
36 
38 {
39 public:
41  virtual ~GenericEventNotifySender (void) { }
42 
44  { m_receivers.insert (r); }
45 
47  { m_receivers.remove (r); }
48 
49 protected:
50  bool notifyReceiversBefore (QObject* obj, QEvent* evt);
51  void notifyReceiversAfter (QObject* obj, QEvent* evt);
52 
53 private:
54  QSet<GenericEventNotifyReceiver*> m_receivers;
55 };
56 
58 {
59 public:
61  virtual ~GenericEventNotifyReceiver (void) { }
62 
63  virtual bool eventNotifyBefore (QObject* obj, QEvent* evt) = 0;
64  virtual void eventNotifyAfter (QObject* obj, QEvent* evt) = 0;
65 };
66 
67 inline
69  QEvent* evt)
70 {
72  if (r->eventNotifyBefore (obj, evt))
73  return true;
74  return false;
75 }
76 
77 inline
79  QEvent* evt)
80 {
82  r->eventNotifyAfter (obj, evt);
83 }
84 
85 #define DECLARE_GENERICEVENTNOTIFY_SENDER(T,B) \
86 class T : public B, public GenericEventNotifySender \
87 { \
88 public: \
89  T (QWidget* xparent) : B (xparent), GenericEventNotifySender () { } \
90  ~ T (void) { } \
91 \
92  bool event (QEvent* evt) \
93  { \
94  bool result = true; \
95  if (! notifyReceiversBefore (this, evt)) \
96  result = B::event (evt); \
97  notifyReceiversAfter (this, evt); \
98  return result; \
99  } \
100 }
101 
102 };
103 
104 #endif
QSet< GenericEventNotifyReceiver * > m_receivers
virtual void eventNotifyAfter(QObject *obj, QEvent *evt)=0
void notifyReceiversAfter(QObject *obj, QEvent *evt)
bool notifyReceiversBefore(QObject *obj, QEvent *evt)
void removeReceiver(GenericEventNotifyReceiver *r)
void addReceiver(GenericEventNotifyReceiver *r)
virtual bool eventNotifyBefore(QObject *obj, QEvent *evt)=0