GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_GenericEventNotify_h)
27 #define octave_GenericEventNotify_h 1
28 
29 #include <QSet>
30 
31 class QEvent;
32 class QObject;
33 class QWidget;
34 
35 namespace QtHandles
36 {
37 
38  class GenericEventNotifyReceiver;
39 
41  {
42  public:
44  virtual ~GenericEventNotifySender (void) = default;
45 
47  { m_receivers.insert (r); }
48 
50  { m_receivers.remove (r); }
51 
52  protected:
53  bool notifyReceiversBefore (QObject *obj, QEvent *evt);
54  void notifyReceiversAfter (QObject *obj, QEvent *evt);
55 
56  private:
57  QSet<GenericEventNotifyReceiver*> m_receivers;
58  };
59 
61  {
62  public:
64  virtual ~GenericEventNotifyReceiver (void) = default;
65 
66  virtual bool eventNotifyBefore (QObject *obj, QEvent *evt) = 0;
67  virtual void eventNotifyAfter (QObject *obj, QEvent *evt) = 0;
68  };
69 
70  inline
72  QEvent *evt)
73  {
74  for (auto *r : m_receivers)
75  if (r->eventNotifyBefore (obj, evt))
76  return true;
77 
78  return false;
79  }
80 
81  inline
83  QEvent *evt)
84  {
85  for (auto *r : m_receivers)
86  r->eventNotifyAfter (obj, evt);
87  }
88 
89 #define DECLARE_GENERICEVENTNOTIFY_SENDER(T,B) \
90 class T : public B, public GenericEventNotifySender \
91 { \
92 public: \
93  T (QWidget *xparent) : B (xparent), GenericEventNotifySender () { } \
94  ~ T (void) = default; \
95 \
96  bool event (QEvent *evt) \
97  { \
98  bool result = true; \
99  if (! notifyReceiversBefore (this, evt)) \
100  result = B::event (evt); \
101  notifyReceiversAfter (this, evt); \
102  return result; \
103  } \
104 }
105 
106 };
107 
108 #endif
virtual void eventNotifyAfter(QObject *obj, QEvent *evt)=0
virtual bool eventNotifyBefore(QObject *obj, QEvent *evt)=0
virtual ~GenericEventNotifyReceiver(void)=default
void removeReceiver(GenericEventNotifyReceiver *r)
virtual ~GenericEventNotifySender(void)=default
void addReceiver(GenericEventNotifyReceiver *r)
QSet< GenericEventNotifyReceiver * > m_receivers
bool notifyReceiversBefore(QObject *obj, QEvent *evt)
void notifyReceiversAfter(QObject *obj, QEvent *evt)
T * r
Definition: mx-inlines.cc:773