Base class for all GCF components. More...
#include <GCF3/Component>
Public Member Functions | |
Component (QObject *parent=0) | |
virtual QString | name () const |
virtual QString | organization () const |
virtual GCF::Version | version () const |
virtual QString | buildTimestamp () const |
const QSettings * | settings () const |
bool | isLoaded () const |
bool | isActive () const |
void | load () |
void | unload () |
void | activate () |
void | deactivate () |
void | addContentObject (const QString &name, QObject *object, const QVariantMap &info=QVariantMap()) |
void | addContentObject (QObject *object, const QVariantMap &info=QVariantMap()) |
void | removeContentObject (QObject *object) |
void | removeContentObject (const QString &name) |
Protected Member Functions | |
~Component () | |
virtual void | finalizeEvent (GCF::FinalizeEvent *e) |
virtual void | initializeEvent (GCF::InitializeEvent *e) |
virtual void | activationEvent (GCF::ActivationEvent *e) |
virtual void | contentLoadEvent (GCF::ContentLoadEvent *e) |
virtual void | deactivationEvent (GCF::DeactivationEvent *e) |
virtual void | settingsLoadEvent (GCF::SettingsLoadEvent *e) |
virtual void | contentUnloadEvent (GCF::ContentUnloadEvent *e) |
virtual void | settingsUnloadEvent (GCF::SettingsUnloadEvent *e) |
virtual void | contentObjectLoadEvent (GCF::ContentObjectLoadEvent *e) |
virtual void | contentObjectMergeEvent (GCF::ContentObjectMergeEvent *e) |
virtual void | contentObjectUnloadEvent (GCF::ContentObjectUnloadEvent *e) |
virtual void | contentObjectUnmergeEvent (GCF::ContentObjectUnmergeEvent *e) |
virtual void | activateContentObjectEvent (GCF::ActivateContentObjectEvent *e) |
virtual void | deactivateContentObjectEvent (GCF::DeactivateContentObjectEvent *e) |
virtual QObject * | loadObject (const QString &name, const QVariantMap &info) |
virtual bool | unloadObject (const QString &name, QObject *object, const QVariantMap &info) |
virtual bool | mergeObject (QObject *parent, QObject *child, const QVariantMap &parentInfo, const QVariantMap &childInfo) |
virtual bool | unmergeObject (QObject *parent, QObject *child, const QVariantMap &parentInfo, const QVariantMap &childInfo) |
virtual bool | activateObject (QObject *parent, QObject *child, const QVariantMap &parentInfo, const QVariantMap &childInfo) |
virtual bool | deactivateObject (QObject *parent, QObject *child, const QVariantMap &parentInfo, const QVariantMap &childInfo) |
Detailed Description
This class is at the heart of GCF's component model. A component, in GCF, is an entity that makes available one or more objects that can work in tandem with objects offered by other components in the application. Components are generally written for reusability. They can be written once and used in several different application contexts.
The GCF::Component class offers a unified way to represent components, initialize (or load) and uninitialize (or unload) them in an application. Objects offered by components are registered with the application's object-tree ( GCF::ApplicationServices::objectTree() ). This way, any component in the application can easily search for objects (and services) offered by any other component in the application.
To create your own component, you can subclass from GCF::Component and implement your component's behavior. Example:
A couple of key points must be noticed from the code snippet above
- Constructor must be public, destructor must be protected. This is to ensure that the component can only be created on the heap and never on the stack.
GCF_EXPORT_COMPONENT
macro can be used to export the component class across shared-library boundaries. This should be done in a source file, and not in a header file.
Instantiating components
A component is said to be instantiated if an instance of the component is created in memory. An instantiated component is however not useful and not included into the application. For that you will need to load the compoent. A loaded component is initialized and its objects are included in the application. Read the following sections to know more about this.
Components can be instantiated using any of the following means
- By loading the component from a shared library
- By creating an instance of a component class
To load a component from shared library, you can make use of the GCF::ApplicationServices::loadComponent() function. Example:
If you want to instantiate the component from a shared library and load it later (explicitly); then you can use the GCF::ApplicationServices::instantiateComponent() function. Example:
If you have access to the constructor of any subclass of GCF::Component, then you can instantiate the component using the new
operator of C++ and then call the load() method on the component to load the component.
Component loading (or initialization)
One of the ways to load a component is by making use of the load() method. Example:
While a component is being loaded, it receives one or more events. These events are handled by the event() method. As a component developer you can reimplement event handlers from this class and offer your own code. Following is the order in which events are despatched to the component (upon load)
Once the post-initialization event has been handled; the component is considered to have been initialized. |
|
- See Also
- How component loading works
Component unloading (or uninitialization)
One of the ways to unload a component is to make use of the unload() method. Example:
When a component is being to unloading, it receives one or more events. These events are handled by the event() method. As a component developer you can reimplement event handlers from this class and offer your own code. Following is the order in which events are despatched to the component (upon unload)
After the post-finalize event is handled, the component object is deleted. |
|
- See Also
- How component unloading works
Content File
Each component can (optionally) provide a content file listing the content-objects offered by it.
A component specifies the content-file that it uses via the GCF::ContentLoadEvent class when its GCF::Component::contentLoadEvent() is called. A typical implementation of this event handler would be
A content file is written in XML. At the most basic level, a content file has a root content
XML element and one or more object
XML elements under it. Example:
Whenever an object
element is parsed by GCF, it sends a GCF::ContentObjectLoadEvent event to the component. Whatever object is created and reported via the event is associated with that name. Example:
You could also optionally do away with implementation of contentObjectLoadEvent()
and simply implement the GCF::Component::loadObject() to behave like a factory method to create QObject
instances based on the name. This is because the default implementation of GCF::Component::contentObjectLoadEvent() calls the GCF::Component::loadObject()
The info
parameter passed to the loadObject()
method or accessed via the GCF::ContentObjectLoadEvent::info() method on the event-object, contains all key=value pairs provided in the object
XML element.
You can also configure object properties and create signal/slot connections in the content-xml file. Read GCF Content XML File Specification for more information.
Activation
Components can be activated by calling the activate() method. When this method is called GCF sends a GCF::ActivationEvent event to the component, which can be handled by reimplementing the activationEvent() virtual function. The activation event is actually sent twice to the component. GCF first sends a pre-activation event to the component. After this event is handled, it sends a GCF::ActivateContentObjectEvent event to the component against each of its content objects. This event can be handled by reimplementing the activateContentObjectEvent() function. Finally, GCF sends a post-activtion event to the component.
By default components are activated at the end of load().
Deactivation
Just as with component activation, a component can be deactivated by calling the deactivate() method. When this method is called, GCF sends a GCF::DeactivationEvent event to the component, which can be handled by reimplementing the deactiationEvent() virtual function. The deactivation is sent twice to the component. GCF first sends a pre-deactivation event. After that it sends a GCF::DeactivateContentObjectEvent event to the component against each of its content objects. This event can be handled by reimplementing the deactivateContentObjectEvent() function. Finally, GCF sends a post-deactivtion event to the component.
By default components are deactivated at the start of unload().
Application Object Tree
Objects loaded from the parsing of a content-file is registered with the application's object tree accessible via gAppService->objectTree()
. This part is explained in the following video
There are more ways in which objects can be registered with the application and included in the application object tree. Please read the section on Registering objects to know more about this.
Constructor & Destructor Documentation
GCF::Component::Component | ( | QObject * | parent = 0 | ) |
Constructor for instantiating the component.
- See Also
- Instantiating components
|
protected |
Destructor.
- Note
- If you are subclassing from GCF::Component, it is recommended that you declare destructor as protected. This will ensure that your component can only be created on the heap, never on the stack.
Member Function Documentation
|
virtual |
Reimplement this function to return a name for your component. By default this function returns the name of the component-class.
- Note
- If you are reimplementing this function, return a string name that confirms to class-naming conventions of C++. [No spaces, first letter should be character, no special characters apart from _]
|
virtual |
Reimplement this function to return the name of your organization. By default this function returns qApp->organizationName()
|
virtual |
Reimplement this function to return a version number for your component. By default this function return GCF::Version(1,0,0);
|
virtual |
Reimplement this function to return a build-timestamp. This should be the date and time of the last time the component was built. By default this function returns __TIMESTAMP__
const QSettings * GCF::Component::settings | ( | ) | const |
Returns settings of this component. The function will return a NULL pointer until a Post-SettingsLoad event (GCF::SettingsLoadEvent) is delivered. It will return a valid pointer to QSettings
after that.
bool GCF::Component::isLoaded | ( | ) | const |
This function returns true if the component has been loaded completely. False otherwise. A component is considered loaded if it has received the Post-Initialize event (GCF::InitializeEvent).
bool GCF::Component::isActive | ( | ) | const |
Returns true if the component has been loaded and activated. False otherwise.
- See Also
- Activation
void GCF::Component::load | ( | ) |
Loads the component.
- Note
- If the component has already been loaded, then this function is a no-op.
void GCF::Component::unload | ( | ) |
Unloads the component. The component is deleted by the time it returns.
void GCF::Component::activate | ( | ) |
Activates the component.
- Note
- If the component is already active, then this function is a no-op.
- See Also
- Activation, isActive()
void GCF::Component::deactivate | ( | ) |
Deactivates the component.
- Note
- If the component is already inactive, then this function is a no-op.
- See Also
- Deactivation, isActive()
void GCF::Component::addContentObject | ( | const QString & | name, |
QObject * | object, | ||
const QVariantMap & | info = QVariantMap() |
||
) |
This function allows you to programmatically add a content-object to the component's object tree, which makes it possible for other components in the application to search for and reference the added object.
Read Application Object Tree for more information about object-trees.
- Parameters
-
name a string name for the added object. Names should following C++ object-naming convention. object pointer to the QObject
that is being added. If NULL, then this function is a no-op.info optional key=value map that contains additional information about the content object.
- Note
- This function cannot be called within contentObjectLoadEvent() and contentObjectUnloadEvent()
void GCF::Component::addContentObject | ( | QObject * | object, |
const QVariantMap & | info = QVariantMap() |
||
) |
This function allows you to programmatically add a content-object to the component's object tree, which makes it possible for other components in the application to search for and reference the added object.
Read Application Object Tree for more information about object-trees.
- Parameters
-
object pointer to the QObject
that is being added. TheobjectName()
of the object is considered to be thename
of the object in the object tree.info optional key=value map that contains additional information about the content object.
- Note
- This function cannot be called within contentObjectLoadEvent() and contentObjectUnloadEvent()
void GCF::Component::removeContentObject | ( | QObject * | object | ) |
This function removes a content-object from the component's object tree.
- Parameters
-
object pointer to the QObject
that needs to be removed
- Note
- The
QObject
refererred to byobject
will not be deleted by this function.
void GCF::Component::removeContentObject | ( | const QString & | name | ) |
This function removes a content-object from the component's object tree.
- Parameters
-
name name of the object that needs to be removed
- Note
- The
QObject
refererred to byname
will not be deleted by this function.
|
protectedvirtual |
Reimplement this event handler to handle pre and post finalization events. This function is called as a part of the unload() process. The function can be reimplemented to
- Prepare the component for finalization during Pre-Finalize
- Clean up memory and prepare for deletion during Post-Finalize
The default implementation does nothing.
- Parameters
-
e pointer to GCF::FinalizeEvent object that describes this event
|
protectedvirtual |
Reimplement this event handler to handle pre and post initialization events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::InitializeEvent object that describes the event.
This is the first event that gets delivered to a component during load. Typically this function is reimplemented to handle
Pre-Initialzation
time to initialize component's objects and variables (or examine system environment) before the component's settings and content get loaded.Post-Initialization
time to do some work after the component is completely loaded, but before it is activated.
Example:
Reimplemented in GCF::QmlComponent.
|
protectedvirtual |
Reimplement this event handler to handle pre and post activation events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::ActivationEvent object that describes this event.
This event gets delivered during activate() process. The event handler can be reimplemented to perform some tasks just before and just after activation.
Reimplemented in GCF::QmlComponent.
|
protectedvirtual |
Reimplement this event handler to handle pre and post content-load events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::ContentLoadEvent object that describes the event.
This event is delivered to the component during its load() process. Typically this function is implemented to
- Offer name of the content file to load during Pre-ContentLoad
- Initialize loaded content objects during Post-ContentLoad
Example:
|
protectedvirtual |
Reimplement this event handler to handle pre and post deactivation events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::DeactivationEvent object that describes this event.
This event gets delivered during deactivate() process. The event handler can be reimplemented to perform some tasks just before and just after deactivation.
Reimplemented in GCF::QmlComponent.
|
protectedvirtual |
Reimplement this event handler to handle pre and post settings-load events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::SettingsLoadEvent object that describes the event.
This is the second event that gets delivered to a component during load. Typically this function is implemented to
- Offer name of the settings file to load in
Pre-SettingsLoad
. - Process the loaded settings in
Post-SettingsLoad
Example:
|
protectedvirtual |
Reimplement this event handler to handle pre and post content-unload events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::ContentUnloadEvent object that describes the event
This event is called during the unload() process. Typically this function is implemented to
- Prepare the component and its content-objects for unloading during Pre-ContentUnload
- Release any additional memory occupied for managing the content of the component during Post-ContentUnload
Example:
|
protectedvirtual |
Reimplement this event handler to handle pre and post settings-unload events. The default implementation does nothing.
- Parameters
-
e pointer to a GCF::SettingsUnloadEvent object that describes the event.
This event is delivered to the component during its unload() process. Typically this function is implemented to
- Add/remove/alter keys and/or values in settings() in
Pre-SettingsUnload
. - Release any memory occupied for handling component settings in
Post-SettingsUnload
Example:
|
protectedvirtual |
Reimplement this event handler to handle content object load events. This event handler is called whenever an object
XML element is encountered in the content file.
- Parameters
-
e pointer to a GCF::ContentObjectLoadEvent object that describes the event.
The default implementation of this event-handler calls the loadObject() method and sets the object returned from it into GCF::ContentObjectLoadEvent::setObject(). It is recommended that you implement loadObject() instead of this event handler for loading content objects.
- See Also
- Content File
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
Reimplement this event handler to handle content-object merge events. This event handler is called if a content-object that is currently being loaded by GCF needs to be merged with a content-object belonging to this component.
- Parameters
-
e pointer to a GCF::ContentObjectMergeEvent object that describes the event.
A merge happens when the parent
attribute of object
XML element (that caused creation of a content-object) refers to a content object belonging to this component.
Example: Suppose that this component (by name MyComponent) is offering an object by name 'container'. Also suppose that another component has a content XML file as shown below
After the other component has finished handling GCF::ContentObjectLoadEvent for object
, a GCF::ContentObjectMergeEvent is sent to this component with
- pointer to 'container'
- pointer to 'object'
- key=value information map of 'container'
- key=value information map of 'object'
This event handler can then customize the way in which parenting (or merging) happens for 'container' and 'object'. For example, in a real world scenario, implementations of this event handler could add a child-widget into a tab of the parent-widget.
- Note
- The default implementation of this event handler calls mergeObject(). It is recommended that you implement mergeObject() instead of this event handler.
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
Reimplement this event handler to handle content object load events. This event handler is called whenever a object XML element is encountered in the content file.
- Parameters
-
e pointer to a GCF::ContentObjectUnloadEvent object that describes the event.
The default implementation of this event-handler calls the unloadObject() method. It is recommended that you implement unloadObject() instead of this event handler for unloading objects.
- Note
- Content-object that is being unloaded will be automatically deleted by GCF, unless you reimplement the event handler to explicitly delete the object here itself.
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
Reimplement this event handler to handle content object unmerge events. This event handler is called if a content-object that is currently being unloaded by GCF needs to be unmerged from a content-object belonging to this component.
- Parameters
-
e pointer to a GCF::ContentObjectUnmergeEvent object that describes the event.
An unmerge happens when a component, whose object was merged with an object from this component, is being unloaded. This event handler can customize the process of unmerging. The default implementation calls unmergeObject() function. It is recommended that you implement unmergeObject() instead of this event handler.
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
Reimplement this handler to handle content-object activation. The event is sent as a part of activate() process. The default event handler calls activateObject(). It is recommended that you implement activateObject() than handling this event.
- Parameters
-
e pointer to a GCF::ActivateContentObjectEvent object that describes this event
- See Also
- Activation
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
Reimplement this handler to handle content-object deactivation. The event is sent as a part of deactivate() process. The default event handler calls deactivateObject(). It is recommended that you implement deactivateObject() than handling this event.
- Parameters
-
e pointer to a GCF::DeactivateContentObjectEvent object that describes this event
- See Also
- Deactivation
Reimplemented in GCF::QmlComponent, and GCF::GuiComponent.
|
protectedvirtual |
This function is called from GCF::Component::contentObjectLoadEvent(). You can reimplement this function to return a QObject
pointer based on the name and information map given.
- Parameters
-
name name of the object that needs to be loaded info key=value information map provided against the object that needs loading
- Returns
- pointer to a
QObject
that was loaded.
|
protectedvirtual |
This function is called from GCF::Component::contentObjectUnloadEvent(). You can reimplement this function to unload the given object. GCF will delete the object immediately after return from this function, unless it was deleted explicitly by you in the reimplementation of this function.
- Parameters
-
name name of the object that needs to be unloaded object pointer to the QObject
that needs to be unloadedinfo key=value information map against the object that needs unloading
- Returns
- true on success, false otherwise. [Note: The return value is currently ignored]
|
protectedvirtual |
This function is called from GCF::Component::contentObjectMergeEvent(). You can reimplement this function to merge child
into parent
. Here parent
belongs to this component.
- Parameters
-
parent pointer to a QObject
added by this component.child pointer to a QObject
that needs to be merged (or parented) intoparent
parentInfo key=value information map associated with the parent
childInfo key=value information map associated with the child
- Returns
- true on success, false otherwise. [Note: The return value is currently ignored]
Reimplemented in GCF::GuiComponent.
|
protectedvirtual |
This function is called from GCF::Component::contentObjectUnmergeEvent(). You can reimplement this function to unmerge child
into parent
. Here parent
belongs to this component.
- Parameters
-
parent pointer to a QObject
added by this component.child pointer to a QObject
that needs to be unmerged (or parented) intoparent
parentInfo key=value information map associated with the parent
childInfo key=value information map associated with the child
- Returns
- true on success, false otherwise. [Note: The return value is currently ignored]
Reimplemented in GCF::GuiComponent.
|
protectedvirtual |
This function is called from GCF::Component::activateContentObjectEvent(). You can reimplement this function to activate the child
in a way suitable for parent
.
- Parameters
-
parent pointer to a QObject
added by this component.child pointer to a QObject
that needs to be activated inparent
parentInfo key=value information map associated with the parent
childInfo key=value information map associated with the child
- Returns
- true on success, false otherwise. [Note: The return value is currently ignored]
Reimplemented in GCF::GuiComponent.
|
protectedvirtual |
This function is called from GCF::Component::deactivateContentObjectEvent(). You can reimplement this function to deactivate the child
in a way suitable for parent
.
- Parameters
-
parent pointer to a QObject
added by this component.child pointer to a QObject
that needs to be deactivated inparent
parentInfo key=value information map associated with the parent
childInfo key=value information map associated with the child
- Returns
- true on success, false otherwise. [Note: The return value is currently ignored]
Reimplemented in GCF::GuiComponent.