20#ifndef LIBREPCB_CORE_SIGNALSLOT_H
21#define LIBREPCB_CORE_SIGNALSLOT_H
35template <
typename Tsender,
typename... Args>
64template <
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...);
169template <
typename Tsender,
typename... Args>
171 friend class Signal<Tsender, Args...>;
186 const std::function<
void(
const Tsender&, Args...)>& callback) noexcept
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...);
222 signal->mSlots.remove(
this);
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
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
void detach(Slot< Tsender, Args... > &slot) const noexcept
Detach a slot.
Definition: signalslot.h:113
void attach(Slot< Tsender, Args... > &slot) const noexcept
Attach a slot.
Definition: signalslot.h:103
Signal & operator=(Signal const &other)=delete
const Tsender & mSender
Reference to the sender object.
Definition: signalslot.h:143
Signal(const Signal &other)=delete
~Signal() noexcept
Destructor.
Definition: signalslot.h:85
Signal(const Tsender &sender) noexcept
Constructor.
Definition: signalslot.h:78
int getSlotCount() const noexcept
Get the count of registered slots.
Definition: signalslot.h:96
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:170
int getSignalCount() const noexcept
Get the count of registered signals.
Definition: signalslot.h:215
QSet< const Signal< Tsender, Args... > * > mSignals
All signals this slot is attached to.
Definition: signalslot.h:232
std::function< void(const Tsender &, Args...)> mCallback
The registered callback function.
Definition: signalslot.h:235
void detachAll() noexcept
Detach from all signals.
Definition: signalslot.h:220
Slot(const Slot &other)=delete
~Slot() noexcept
Destructor.
Definition: signalslot.h:208
Slot(T &obj, void(T::*func)(const Tsender &, Args...)) noexcept
Constructor.
Definition: signalslot.h:198
Slot & operator=(Slot const &other)=delete
Slot(const std::function< void(const Tsender &, Args...)> &callback) noexcept
Constructor.
Definition: signalslot.h:185
Definition: occmodel.cpp:77