StanfordCPPLib
Public Member Functions | Protected Member Functions | List of all members
GObservable Class Referenceabstract

A GObservable object is one that is able to send out events. More...

#include "gobservable.h"

Inheritance diagram for GObservable:
GInteractor GWindow GBrowserPane GButton GCanvas GCheckBox GChooser GContainer GLabel GRadioButton GScrollBar GScrollPane GSlider GSpacer GTable GTextArea GTextField

Public Member Functions

 GObservable()
 Initializes a newly created observable object. More...
 
~GObservable()
 Frees any memory used internally by the observable object. More...
 
bool eventsEnabled() const
 Returns true if the object is currently allowing itself to fire events. More...
 
string getType() const =0
 Returns the concrete type of the object as a string, such as "GButton" or "GWindow". More...
 
void setEventsEnabled(bool eventsEnabled)
 Sets whether the object is currently allowing itself to fire events. More...
 
string toString() const
 Returns a string representation of this observable object's state. More...
 

Protected Member Functions

void clearEventListeners()
 Removes all event listeners from this object. More...
 
void ensureThreadSafety(string memberName="")
 Ensures that we are currently in the Qt GUI thread. More...
 
void fireEvent(GEvent &event)
 Sends out the given event to any attached listeners. More...
 
void fireGEvent(QEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QCloseEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QKeyEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QMouseEvent *event, EventType eventType, string eventName, string actionCommand="")
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QResizeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QTimerEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWheelEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWindowStateChangeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
bool hasEventListener(string eventName) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(int eventMask) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(const GEvent &event) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(string eventType) const
 Returns true if the observable object has a listener for the given type of event. More...
 
void removeEventListener(string eventName)
 Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown". More...
 
void removeEventListeners(std::initializer_list< string > eventNames)
 Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListener func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListener func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 

Detailed Description

A GObservable object is one that is able to send out events.

Listeners can register themselves to be notified when events occur. This serves as a base class for the various GInteractor subclasses, as well as for the GWindow class, so that clients can attach listeners to them.

Constructor & Destructor Documentation

◆ GObservable()

Initializes a newly created observable object.

◆ ~GObservable()

~GObservable ( )
virtual

Frees any memory used internally by the observable object.

Member Function Documentation

◆ clearEventListeners()

void clearEventListeners ( )
protectedvirtual

Removes all event listeners from this object.

◆ ensureThreadSafety()

void ensureThreadSafety ( string   memberName = "")
protectedvirtual

Ensures that we are currently in the Qt GUI thread.

◆ eventsEnabled()

bool eventsEnabled ( ) const
virtual

Returns true if the object is currently allowing itself to fire events.

Initially this is true unless the client has called setEventsEnabled(false) or the object is not visible.

Reimplemented in GInteractor.

◆ fireEvent()

void fireEvent ( GEvent event)
protectedvirtual

Sends out the given event to any attached listeners.

◆ fireGEvent() [1/8]

void fireGEvent ( QEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [2/8]

void fireGEvent ( QCloseEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [3/8]

void fireGEvent ( QKeyEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [4/8]

void fireGEvent ( QMouseEvent *  event,
EventType  eventType,
string   eventName,
string   actionCommand = "" 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [5/8]

void fireGEvent ( QResizeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [6/8]

void fireGEvent ( QTimerEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [7/8]

void fireGEvent ( QWheelEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [8/8]

void fireGEvent ( QWindowStateChangeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtual

Creates an event of the given type, then sends it out to any attached listeners.

◆ getType()

virtual string getType ( ) const
pure virtual

Returns the concrete type of the object as a string, such as "GButton" or "GWindow".

Each GObservable subtype must override this method.

Implemented in GWindow, GCanvas, GContainer, GInteractor, GTable, GTextArea, GBrowserPane, GSlider, GTextField, GChooser, GLabel, GScrollBar, GRadioButton, GButton, GScrollPane, GCheckBox, and GSpacer.

◆ hasEventListener()

bool hasEventListener ( string   eventName) const
protectedvirtual

Returns true if the observable object has a listener for the given type of event.

◆ isAcceptingEvent() [1/3]

bool isAcceptingEvent ( int  eventMask) const
protectedvirtual

Returns true if the observable object has a listener for the given type of event.

See gevent.h for event types and masks.

◆ isAcceptingEvent() [2/3]

bool isAcceptingEvent ( const GEvent event) const
protectedvirtual

Returns true if the observable object has a listener for the given type of event.

◆ isAcceptingEvent() [3/3]

bool isAcceptingEvent ( string   eventType) const
protectedvirtual

Returns true if the observable object has a listener for the given type of event.

◆ removeEventListener()

void removeEventListener ( string   eventName)
protectedvirtual

Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown".

◆ removeEventListeners()

void removeEventListeners ( std::initializer_list< string >  eventNames)
protectedvirtual

Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown".

◆ setEventListener() [1/2]

void setEventListener ( string   eventName,
GEventListener  func 
)
protectedvirtual

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListener() [2/2]

void setEventListener ( string   eventName,
GEventListenerVoid  func 
)
protectedvirtual

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListeners() [1/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListener  func 
)
protectedvirtual

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventListeners() [2/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListenerVoid  func 
)
protectedvirtual

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventsEnabled()

void setEventsEnabled ( bool  eventsEnabled)
virtual

Sets whether the object is currently allowing itself to fire events.

Initially this is true.

◆ toString()

string toString ( ) const
virtual

Returns a string representation of this observable object's state.

Primarily used for debugging purposes.

Friends And Related Function Documentation

◆ GInteractor

friend class GInteractor
friend