20 #ifndef LIBREPCB_CORE_SIGNALSLOT_H 21 #define LIBREPCB_CORE_SIGNALSLOT_H 35 template <
typename Tsender,
typename... Args>
64 template <
typename Tsender,
typename... Args>
66 friend class Slot<Tsender, Args...>;
87 slot->mSignals.remove(
this);
104 slot.mSignals.insert(
this);
114 slot.mSignals.remove(
this);
130 foreach (
const auto& slot,
mSlots) {
133 if (
mSlots.contains(slot)) {
134 slot->mCallback(
mSender, args...);
169 template <
typename Tsender,
typename... Args>
186 const std::function<
void(
const Tsender&, Args...)>& callback) noexcept
187 : mCallback(callback) {}
197 template <
typename T>
198 explicit Slot(T& obj,
void (T::*func)(
const Tsender&, Args...)) noexcept
199 : mCallback([=, &obj](const Tsender& s, Args... args) {
200 (obj.*func)(s, args...);
221 for (
auto signal : mSignals) {
222 signal->mSlots.remove(
this);
Slot(const std::function< void(const Tsender &, Args...)> &callback) noexcept
Constructor.
Definition: signalslot.h:185
std::function< void(const Tsender &, Args...)> mCallback
The registered callback function.
Definition: signalslot.h:235
~Signal() noexcept
Destructor.
Definition: signalslot.h:85
int getSlotCount() const noexcept
Get the count of registered slots.
Definition: signalslot.h:96
Slot(T &obj, void(T::*func)(const Tsender &, Args...)) noexcept
Constructor.
Definition: signalslot.h:198
Definition: occmodel.cpp:77
void detachAll() noexcept
Detach from all signals.
Definition: signalslot.h:220
void detach(Slot< Tsender, Args... > &slot) const noexcept
Detach a slot.
Definition: signalslot.h:113
QSet< const Signal< Tsender, Args... > * > mSignals
All signals this slot is attached to.
Definition: signalslot.h:232
void attach(Slot< Tsender, Args... > &slot) const noexcept
Attach a slot.
Definition: signalslot.h:103
QSet< Slot< Tsender, Args... > * > mSlots
All attached slots.
Definition: signalslot.h:144
void notify(Args... args) noexcept
Notify all attached slots.
Definition: signalslot.h:123
Signal & operator=(Signal const &other)=delete
~Slot() noexcept
Destructor.
Definition: signalslot.h:208
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
int getSignalCount() const noexcept
Get the count of registered signals.
Definition: signalslot.h:215
const Tsender & mSender
Reference to the sender object.
Definition: signalslot.h:143
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
Signal(const Tsender &sender) noexcept
Constructor.
Definition: signalslot.h:78