Torc
0.1
|
A general purpose event object. More...
#include <torcevent.h>
Public Member Functions | |
TorcEvent (int Event, const QVariantMap &Data=QVariantMap()) | |
The default implementation contains no data. More... | |
virtual | ~TorcEvent ()=default |
int | GetEvent (void) |
Return the Torc action associated with this event. More... | |
QVariantMap & | Data (void) |
Return a reference to the Data contained within this event. More... | |
TorcEvent * | Copy (void) const |
Copy this event. More... | |
Static Public Attributes | |
static Type | TorcEventType = (QEvent::Type) QEvent::registerEventType() |
Register TorcEventType with QEvent. More... | |
A general purpose event object.
TorcEvent is used to send Torc::Actions events to other objects. For a simple event message, the constructor requires only a Torc event type. For more complicated events, add additional data with a QVariantMap.
To listen for Torc events, an object must be a QObject subclass and reimplement QObject::event. It can then call gLocalContext->AddObserver(this) and remember to call gLocalContext->RemoveObserver(this) when event notification is no longer required.
(N.B. Take care to return an appropriate value from event() and be wary of implementing other QObject event handlers (such as timerEvent) as they can interact in unexpected ways).
For specific functionality for which there are a known and/or limited number of 'listeners', consider sending events directly with QCoreApplication::postEvent (or alternatively, use the signal/slot mechanism, which is also thread safe).
Definition at line 9 of file torcevent.h.
TorcEvent::TorcEvent | ( | int | Event, |
const QVariantMap & | Data = QVariantMap() |
||
) |
The default implementation contains no data.
Definition at line 57 of file torcevent.cpp.
|
virtualdefault |
TorcEvent * TorcEvent::Copy | ( | void | ) | const |
Copy this event.
TorcObservable will iterate over the list of 'listening' objects and send events to each using QCoreApplication::postEvent. postEvent will however take ownership of the event object, hence we need to create a copy for each message.
Definition at line 82 of file torcevent.cpp.
QVariantMap & TorcEvent::Data | ( | void | ) |
Return a reference to the Data contained within this event.
Definition at line 71 of file torcevent.cpp.
int TorcEvent::GetEvent | ( | void | ) |
Return the Torc action associated with this event.
Definition at line 65 of file torcevent.cpp.
|
static |
Register TorcEventType with QEvent.
Definition at line 19 of file torcevent.h.