From: André Pönitz Date: Sun, 25 Nov 2007 19:46:22 +0000 (+0000) Subject: add signal/slot implementation 'framework' X-Git-Tag: 1.6.10~7209 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=65f9f3c22b29450fbae459f4371a6b1212e28681;p=lyx.git add signal/slot implementation 'framework' git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21781 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 0d506dfaec..2e9a663725 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -77,6 +77,9 @@ liblyxsupport_la_SOURCES = \ strfwd.h \ Systemcall.cpp \ Systemcall.h \ + SignalSlot.cpp \ + SignalSlot.h \ + SignalSlotPrivate.h \ tempname.cpp \ textutils.h \ Translator.h \ diff --git a/src/support/SignalSlot.cpp b/src/support/SignalSlot.cpp new file mode 100644 index 0000000000..27a62d2b83 --- /dev/null +++ b/src/support/SignalSlot.cpp @@ -0,0 +1,72 @@ +// -*- C++ -*- +/** + * \file SignalSlot.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#include "SignalSlot.h" +#include "SignalSlotPrivate.h" + +namespace lyx { + +///////////////////////////////////////////////////////////////////// +// +// Signal +// +///////////////////////////////////////////////////////////////////// + +Signal::Signal() + : impl(new SignalImpl) +{} + + +Signal::~Signal() +{ + delete impl; +} + + +void Signal::fire() +{ + impl->fire(); +} + + +///////////////////////////////////////////////////////////////////// +// +// Slot +// +///////////////////////////////////////////////////////////////////// + +void SlotImpl::called() +{ + owner_.called(); +} + +Slot::Slot() + : impl(new SlotImpl(*this)) +{} + +Slot::~Slot() +{ + delete impl; +} + + +///////////////////////////////////////////////////////////////////// +// +// Connect +// +///////////////////////////////////////////////////////////////////// + +void connect(Signal & sig, Slot & slot) +{ + QObject::connect(sig.impl, SIGNAL(fire()), slot.impl, SLOT(called())); +} + +} // namespace lyx diff --git a/src/support/SignalSlot.h b/src/support/SignalSlot.h new file mode 100644 index 0000000000..4290a40770 --- /dev/null +++ b/src/support/SignalSlot.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +/** + * \file SignalSlot.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SIGNALSLOT_H +#define SIGNALSLOT_H + +namespace lyx { + +class Slot; +class SlotImpl; +class SignalImpl; + +class Signal +{ +public: + Signal(); + ~Signal(); + void fire(); +private: + Signal(Signal const &); + void operator=(Signal const &); + SignalImpl * impl; + friend void connect(Signal & sig, Slot & slot); +}; + +class Slot +{ +public: + Slot(); + virtual ~Slot(); + virtual void called() {} +private: + Slot(Slot const &); + void operator=(Slot const &); + SlotImpl * impl; + friend void connect(Signal & sig, Slot & slot); +}; + +void connect(Signal & sig, Slot & slot); + +} // namespace lyx + +#endif diff --git a/src/support/SignalSlotPrivate.h b/src/support/SignalSlotPrivate.h new file mode 100644 index 0000000000..555005454d --- /dev/null +++ b/src/support/SignalSlotPrivate.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +/** + * \file SignalSlotPrivate.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef SIGNALSLOTPRIVATE_H +#define SIGNALSLOTPRIVATE_H + +#include + +namespace lyx { + +class SignalImpl : public QObject +{ + Q_OBJECT +public: + SignalImpl() {} + virtual ~SignalImpl() {} + +Q_SIGNALS: + void fire(); + friend class Signal; +}; + + +class Slot; +class SlotImpl : public QObject +{ + Q_OBJECT +public: + SlotImpl(Slot & owner) : owner_(owner) {} + virtual ~SlotImpl() {} +public Q_SLOTS: + void called(); +private: + Slot & owner_; +}; + +} // namespace lyx + +#endif // SIGNALSLOTPRIVATE_H