GNU Octave  8.1.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-2023 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 
36 
38 
40 {
41 public:
43  virtual ~GenericEventNotifySender (void) = default;
44 
46  { m_receivers.insert (r); }
47 
49  { m_receivers.remove (r); }
50 
51 protected:
52  bool notifyReceiversBefore (QObject *obj, QEvent *evt);
53  void notifyReceiversAfter (QObject *obj, QEvent *evt);
54 
55 private:
56  QSet<GenericEventNotifyReceiver *> m_receivers;
57 };
58 
60 {
61 public:
63  virtual ~GenericEventNotifyReceiver (void) = default;
64 
65  virtual bool eventNotifyBefore (QObject *obj, QEvent *evt) = 0;
66  virtual void eventNotifyAfter (QObject *obj, QEvent *evt) = 0;
67 };
68 
69 inline
71  QEvent *evt)
72 {
73  for (auto *r : m_receivers)
74  if (r->eventNotifyBefore (obj, evt))
75  return true;
76 
77  return false;
78 }
79 
80 inline
82  QEvent *evt)
83 {
84  for (auto *r : m_receivers)
85  r->eventNotifyAfter (obj, evt);
86 }
87 
89 
90 #define DECLARE_GENERICEVENTNOTIFY_SENDER(T,B) \
91 class T : public B, public GenericEventNotifySender \
92 { \
93 public: \
94  T (QWidget *xparent) : B (xparent), GenericEventNotifySender () { } \
95  ~ T (void) = default; \
96 \
97  bool event (QEvent *evt) \
98  { \
99  bool result = true; \
100  if (! notifyReceiversBefore (this, evt)) \
101  result = B::event (evt); \
102  notifyReceiversAfter (this, evt); \
103  return result; \
104  } \
105 }
106 
107 #endif
OCTAVE_END_NAMESPACE(octave)
virtual ~GenericEventNotifyReceiver(void)=default
virtual bool eventNotifyBefore(QObject *obj, QEvent *evt)=0
virtual void eventNotifyAfter(QObject *obj, QEvent *evt)=0
void notifyReceiversAfter(QObject *obj, QEvent *evt)
virtual ~GenericEventNotifySender(void)=default
void addReceiver(GenericEventNotifyReceiver *r)
void removeReceiver(GenericEventNotifyReceiver *r)
bool notifyReceiversBefore(QObject *obj, QEvent *evt)
QSet< GenericEventNotifyReceiver * > m_receivers
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
T * r
Definition: mx-inlines.cc:773