CFx SDK Documentation  2022 SP0
FxUISignal.h
Go to the documentation of this file.
1 //
2 // (C) Copyright 2005-2021 by Graebert GmbH.
3 //
4 // Permission to use, copy, modify, and distribute this software in
5 // object code form for any purpose and without fee is hereby granted,
6 // provided that the above copyright notice appears in all copies and
7 // that both that copyright notice and the limited warranty and
8 // restricted rights notice below appear in all supporting
9 // documentation.
10 //
11 // GRAEBERT PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
12 // GRAEBERT SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
13 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. GRAEBERT GMBH
14 // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
15 // UNINTERRUPTED OR ERROR FREE.
16 
17 #pragma once
18 
19 #include "../FxCommonFramework.h"
20 
21 #include "FxUIObject.h"
22 
28 {
29 public:
33  explicit CFxUIEmitScope( CFxUIObject* slot, CFxUIObject* pSender );
34 
39 
40 private:
41  CFxUIObject* m_pSlot;
42 
43  //..
44 };
45 
46 #include <QtCore/QObject>
47 
48 #ifdef emit
49 #undef emit
50 #define FX_REDEFINE_EMIT
51 #endif
52 #ifdef slots
53 #undef slots
54 #define FX_REDEFINE_SLOTS
55 #endif
56 
57 #ifdef max
58 #undef max
59 #endif
60 
61 #ifdef min
62 #undef min
63 #endif
64 
65 #include "slimsig/slimsig.h"
66 #include "slimsig/connection.h"
67 
68 #ifdef XENON
69 #include "XeThreadHelper.h"
70 #endif
71 
72 using namespace slimsig;
73 
74 template <class> class CFxUISignal;
75 
76 template <class R, class ... Args>
77 
83 class COMMONUI_API CFxUISignal<R(Args...)> : public slimsig::signal<R(Args...)>
84 {
85 public:
86  using base = slimsig::signal<R(Args...)>;
87  using connection_type = typename base::Connection;
88  using base::connect;
89 
93  CFxUISignal() = delete;
94 
100  explicit CFxUISignal( CFxUIObject* sender )
101  {
102  m_pSender = sender;
103  }
104 
110  template <class TReciver>
111  connection_type connect( CFxUIObject* reciver, void (TReciver::*method)() )
112  {
113  auto slot = [reciver, method, this](Args&&... args)
114  {
115  TReciver* r = dynamic_cast<TReciver*>( reciver );
116  if ( r )
117  {
118  CFxUIEmitScope scope( r, m_pSender );
119  (r->*method)();
120  }
121  };
122  return slimsig::signal<R(Args...)>::connect( slot );
123  }
124 
131  template <class TReciver>
132  connection_type connect( TReciver* reciver, R (TReciver::*method)( Args... args ) )
133  {
134  auto slot = [reciver, method, this](Args&&... args) -> R
135  {
136  CFxUIEmitScope scope( dynamic_cast<CFxUIObject*>( reciver ), m_pSender );
137  return (reciver->*method)( args... );
138  };
139  return slimsig::signal<R(Args...)>::connect( slot );
140  }
141 
147  connection_type connect( std::function<void( Args... )> function )
148  {
149  return slimsig::signal<R( Args... )>::connect( function );
150  }
151 
159  void Emit(Args... args)
160  {
161  if ( m_pSender->signalsBlocked() )
162  return;
163 #ifdef XENON
164  XeThreadHelper::PostToThread(XE_THREAD_EVENT, [&, args ...]() { slimsig::signal<R(Args...)>::emit(args...); });
165 #else
166  slimsig::signal<R( Args... )>::emit( std::forward<Args&&>( args )... );
167 #endif
168  }
169 
170 private:
171  CFxUIObject* m_pSender;
172 
173  //..
174 };
175 
176 #ifdef FX_REDEFINE_EMIT
177 #define emit
178 #endif
179 #ifdef FX_REDEFINE_SLOTS
180 #define slots
181 #endif
182 
#define COMMONUI_API
CFxUIEmitScope(CFxUIObject *slot, CFxUIObject *pSender)
connection_type connect(TReciver *reciver, R(TReciver::*method)(Args... args))
Definition: FxUISignal.h:132
void Emit(Args... args)
Definition: FxUISignal.h:159
connection_type connect(CFxUIObject *reciver, void(TReciver::*method)())
Definition: FxUISignal.h:111
connection_type connect(std::function< void(Args...)> function)
Definition: FxUISignal.h:147
CFxUISignal(CFxUIObject *sender)
Definition: FxUISignal.h:100
typename base::Connection connection_type
Definition: FxUISignal.h:87