Base object for promeki. More...
#include <objectbase.h>


Classes | |
| class | MetaInfo |
| Captures all the metadata about this object. More... | |
| class | SignalMeta |
| Metadata entry describing a signal on an ObjectBase-derived class. More... | |
| class | SlotMeta |
| Metadata entry describing a slot on an ObjectBase-derived class. More... | |
Public Types | |
| using | SlotVariantFunc = std::function< void(const VariantList &)> |
| Function type for invoking a slot with a list of Variants. | |
Public Member Functions | |
| ObjectBase (ObjectBase *p=nullptr) | |
| Default ObjectBase constructor. | |
| virtual | ~ObjectBase () |
| Destructor. Emits aboutToDestroy, detaches from parent, and destroys children. | |
| ObjectBase * | parent () const |
| Returns the parent object, if one. nullptr if none. | |
| void | setParent (ObjectBase *p) |
| Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one. | |
| const ObjectBaseList & | childList () const |
| Returns a list of children of this object. | |
| template<typename... Args> | |
| int | registerSlot (Slot< Args... > *slot) |
| Registers a slot with this object and assigns it an ID. | |
| EventLoop * | eventLoop () const |
| Returns the EventLoop this object is affiliated with. | |
| void | moveToThread (EventLoop *loop) |
| Changes the EventLoop affinity of this object. | |
| int | startTimer (unsigned int intervalMs, bool singleShot=false) |
| Starts a timer on this object's EventLoop. | |
| void | stopTimer (int timerId) |
| Stops a timer previously started with startTimer(). | |
| template<typename... Args> | |
| PROMEKI_NAMESPACE_BEGIN void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
Static Public Member Functions | |
| static const MetaInfo & | metaInfo () |
| Returns the MetaInfo for the ObjectBase class. | |
| template<typename... Args> | |
| static void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
| connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object | |
Public Attributes | |
| Signal< ObjectBase * > | aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName) |
Static Public Attributes | |
| static constexpr const char * | aboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")" |
| static SignalMeta | aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName) |
Protected Member Functions | |
| ObjectBase * | signalSender () |
| Returns the ObjectBase that emitted the signal currently being handled. | |
| virtual void | event (Event *e) |
| Called by EventLoop to deliver events to this object. | |
| virtual void | timerEvent (TimerEvent *e) |
| Called when a timer fires for this object. | |
Friends | |
| class | ObjectBasePtr |
| class | EventLoop |
Base object for promeki.
This object is used by promeki to provide certain objects with a base level of funtionality which include:
The object was modeled from the Qt QObject, although isn't quite as versitle but it trades off that versatility for not needing an external meta object compiler.
| ObjectBase::ObjectBase | ( | ObjectBase * | p = nullptr | ) |
Default ObjectBase constructor.
| [in] | p | Parent object |
This is the default constructor you'll normally use to construct the ObjectBase object in your derived class constructor. If your class is meant to have a parent object, you should pass it in. This will ensure that this object is destroyed if the parent is destroyed.
|
inline |
Returns a list of children of this object.
Called by EventLoop to deliver events to this object.
The default implementation dispatches TimerEvent to timerEvent() and accepts it.
| e | The event to handle. |
Reimplemented in TuiWidget.
|
inline |
|
inline |
Returns the parent object, if one. nullptr if none.
|
inline |
Registers a slot with this object and assigns it an ID.
| Args | The slot's parameter types. |
| slot | Pointer to the Slot to register. |
Starts a timer on this object's EventLoop.
TimerEvent will be delivered to this object's timerEvent() method each time the timer fires.
| intervalMs | The timer interval in milliseconds. |
| singleShot | If true, the timer fires once and is removed. |
| void ObjectBase::stopTimer | ( | int | timerId | ) |
Stops a timer previously started with startTimer().
| timerId | The timer ID returned by startTimer(). |
|
protectedvirtual |
Called when a timer fires for this object.
Override this in derived classes to handle timer events. The default implementation does nothing.
| e | The timer event. |
Reimplemented in TuiStatusBar.
|
staticconstexpr |
Object is about to be destroyed This signal is emitted when the object is about to be destroyed.
NOTE: when this is emitted the object has mostly already been torn down so you'll not be able to cast it to a derived object.