GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
GenericEventNotify.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_GenericEventNotify_h)
24 #define octave_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) = default;
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) = default;
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 
75  return false;
76  }
77 
78  inline
80  QEvent *evt)
81  {
83  r->eventNotifyAfter (obj, evt);
84  }
85 
86 #define DECLARE_GENERICEVENTNOTIFY_SENDER(T,B) \
87 class T : public B, public GenericEventNotifySender \
88 { \
89 public: \
90  T (QWidget *xparent) : B (xparent), GenericEventNotifySender () { } \
91  ~ T (void) = default; \
92 \
93  bool event (QEvent *evt) \
94  { \
95  bool result = true; \
96  if (! notifyReceiversBefore (this, evt)) \
97  result = B::event (evt); \
98  notifyReceiversAfter (this, evt); \
99  return result; \
100  } \
101 }
102 
103 };
104 
105 #endif
virtual ~GenericEventNotifySender(void)=default
virtual ~GenericEventNotifyReceiver(void)=default
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