GCF LOGO VCL LOGO

Extends GCF::Component to ease creation of QML components. More...

#include <GCF3/QmlComponent>

Public Member Functions

 QmlComponent (QObject *parent=0)
 
bool isActive () const
 
Q_SIGNAL void activeChanged (bool val)
 
QObject * addQml (const QString &name, const QUrl &url)
 
QObject * addQml (const QUrl &url)
 
Q_INVOKABLE void addQmlItem (const QString &name, QObject *object)
 
Q_INVOKABLE void removeQmlItem (QObject *object)
 
Q_INVOKABLE void removeQmlItem (const QString &name)
 
Q_INVOKABLE QObject * qmlItem (const QString &name) const
 
- Public Member Functions inherited from GCF::Component
 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

 ~QmlComponent ()
 
void initializeEvent (GCF::InitializeEvent *e)
 
void activationEvent (GCF::ActivationEvent *e)
 
void deactivationEvent (GCF::DeactivationEvent *e)
 
void contentObjectLoadEvent (GCF::ContentObjectLoadEvent *e)
 
void contentObjectMergeEvent (GCF::ContentObjectMergeEvent *e)
 
void contentObjectUnloadEvent (GCF::ContentObjectUnloadEvent *e)
 
void contentObjectUnmergeEvent (GCF::ContentObjectUnmergeEvent *e)
 
void activateContentObjectEvent (GCF::ActivateContentObjectEvent *e)
 
void deactivateContentObjectEvent (GCF::DeactivateContentObjectEvent *e)
 
virtual QObject * loadQmlObject (const QString &name, const QUrl &url, const QVariantMap &info)
 
virtual bool unloadQmlObject (const QString &name, QObject *qmlObject, const QVariantMap &info)
 
- Protected Member Functions inherited from GCF::Component
 ~Component ()
 
virtual void finalizeEvent (GCF::FinalizeEvent *e)
 
virtual void contentLoadEvent (GCF::ContentLoadEvent *e)
 
virtual void settingsLoadEvent (GCF::SettingsLoadEvent *e)
 
virtual void contentUnloadEvent (GCF::ContentUnloadEvent *e)
 
virtual void settingsUnloadEvent (GCF::SettingsUnloadEvent *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 offers QML friendly methods to make creation of QML components in GCF applications really simple. Please note that there is a difference in the meaning of the term QML-Component when used in Qt 5 context and when used in GCF context. Unless otherwise stated the term QML-Component in this class document refers to an instance of GCF::QmlComponent class.

This class reimplements

  • GCF::Component::initializeEvent() - to check whether the component is being loaded in a GCF QML application or not. The component asserts a failure and crashes the application otherwise.

Content files for QML components can make use of type=qml and url= attributes in object XML element to load QML objects. Example

<content>
<object name="root" type="qml" url="qrc:///RootItem.qml" >
<object name="sample" type="qml" url="http://www.something.com/Sample.qml" >
<object name="another" type="qml" url="file:///Users/jaggesh/Another.qml" >
</content>
Note
QML files loaded using this class, either through content-files or by calling the addQml() function, can make use of a gComponent object in their code to reference this component.

This class also offers a specialized virtual function called loadQmlObject(), whose default implementation eases out loading of QML objects from .qml files. Subclasses can reimplement this function to customize the loading of QML objects.

The addQml() methods may be used to add QML objects from .qml files - without loading them from the content-file. Custom QML items can be added using addQmlItem() method. QML items added using addQml() or addQmlItem() methods are included in the object list.

Note
This class is available only if GCF is compiled and linked against Qt 5.

Constructor & Destructor Documentation

GCF::QmlComponent::QmlComponent ( QObject *  parent = 0)

Constructor. Creates an instance of this class and inserts it as a child under parent.

Note
It is recommended that subclasses of GCF::GuiComponent declare their constructor as public and destructor as protected. This will ensure that the components are created on the heap always.
GCF::QmlComponent::~QmlComponent ( )
protected

Destructor.

Note
It is recommended that subclasses of GCF::GuiComponent declare their constructor as public and destructor as protected. This will ensure that the components are created on the heap always.

Member Function Documentation

bool GCF::QmlComponent::isActive ( ) const

Returns true if the component has been activated. False otherwise.

This function is called when the active property is READ. The active property is notified as changed whenever this component receives a activationEvent() or deactivationEvent(). Change notifications to this property are signaled using the activeChanged() signal.

void GCF::QmlComponent::activeChanged ( bool  val)

This signal is emitted whenever the active property changes.

QObject * GCF::QmlComponent::addQml ( const QString &  name,
const QUrl &  url 
)

This function can be used to create a QML object from url and add it as a content-object of this component.

Parameters
namename to be set on QML object loaded from url.
urllocation of the .qml file from which the QML object should be loaded. http, file, ftp and qrc schemes are supported.
Returns
pointer to the loaded QML object upon success, null upon failure.
Note
QML objects added using this function can access a gComponent object in their code to access methods on this component.
See Also
GCF::Component::addContentObject()
QObject * GCF::QmlComponent::addQml ( const QUrl &  url)

This function adds a QML object from url.

Parameters
urllocation of the .qml file from which the QML object should be loaded. http, file, ftp and qrc schemes are supported.
Returns
pointer to the loaded QML object upon success, null upon failure.

Name of the QML object is inferred from the file-name of the .qml file specified in url.

Note
QML objects added using this function can access a gComponent object in their code to access methods on this component.
void GCF::QmlComponent::addQmlItem ( const QString &  name,
QObject *  object 
)

Adds a QML item as content object to this component

Parameters
namename of the QML object
objectpointer to the QML object
Note
This function can be called from within QML code using gComponent.addQmlItem(string,object)
void GCF::QmlComponent::removeQmlItem ( QObject *  object)

Removes a QML item as content object from this component

Parameters
objectpointer to the QML object that needs to be removed
Note
This function can be called from within QML code using gComponent.removeQmlItem(object)
void GCF::QmlComponent::removeQmlItem ( const QString &  name)

Removes a QML item as content object from this component

Parameters
namename of the QML object that needs to be removed
Note
This function can be called from within QML code using gComponent.removeQmlItem(string)
QObject * GCF::QmlComponent::qmlItem ( const QString &  name) const

Returns pointer to a QML object (or item) whose name is name. For this function to work a QML object should have been added using addQmlItem() for the same name before.

Parameters
namename of the QML item/object to return
Returns
pointer to the QML object. NULL if no such object was found.
Note
This function can be called from within QML code using gComponent.qmlItem(string)
void GCF::QmlComponent::initializeEvent ( GCF::InitializeEvent e)
protectedvirtual

This event handler is implemented to ASSERT crash the application, if the component is attempted for loading within a non QML application. It calls the base class implementation of the event handler otherwise.

Reimplemented from GCF::Component.

void GCF::QmlComponent::activationEvent ( GCF::ActivationEvent e)
protectedvirtual

Updates the active property and calls the base class implementation of this event handler

Reimplemented from GCF::Component.

void GCF::QmlComponent::deactivationEvent ( GCF::DeactivationEvent e)
protectedvirtual

Updates the active property and calls the base class implementation of this event handler

Reimplemented from GCF::Component.

void GCF::QmlComponent::contentObjectLoadEvent ( GCF::ContentObjectLoadEvent e)
protectedvirtual

This event handler is implemented to look for a type key in the information map (GCF::ContentObjectLoadEvent::info()) provided by the event-object. If the type is qml, then it looks for a url key in the information map and loads the .qml file specified in url using the loadQmlObject() method.

If the type key is not qml, then the base class implementation of this event handler is called; which in turn calls the loadObject() method.

Reimplemented from GCF::Component.

void GCF::QmlComponent::contentObjectMergeEvent ( GCF::ContentObjectMergeEvent e)
protectedvirtual

This event hanlder is implemented to ignore merge events for QML objects

Reimplemented from GCF::Component.

void GCF::QmlComponent::contentObjectUnloadEvent ( GCF::ContentObjectUnloadEvent e)
protectedvirtual

This event handler is implemented to look for a type key in the information map (GCF::ContentObjectLoadEvent::info()) provided by the event-object. If the type is qml, then it calls the unloadQmlObject() method to unload the QML object.

If the type key is not qml, then the base class implementation of this event handler is called; which in turn calls the unloadObject() method.

Reimplemented from GCF::Component.

void GCF::QmlComponent::contentObjectUnmergeEvent ( GCF::ContentObjectUnmergeEvent e)
protectedvirtual

This event hanlder is implemented to ignore unmerge events for QML objects

Reimplemented from GCF::Component.

void GCF::QmlComponent::activateContentObjectEvent ( GCF::ActivateContentObjectEvent e)
protectedvirtual

This event hanlder is implemented to ignore activation events for QML objects

Reimplemented from GCF::Component.

void GCF::QmlComponent::deactivateContentObjectEvent ( GCF::DeactivateContentObjectEvent e)
protectedvirtual

This event hanlder is implemented to ignore deactivation events for QML objects

Reimplemented from GCF::Component.

QObject * GCF::QmlComponent::loadQmlObject ( const QString &  name,
const QUrl &  url,
const QVariantMap &  info 
)
protectedvirtual

This function can be implemented to customize the loading a QML object from url. The default implementation loads the QML file at URL and returns a pointer to it. The default implementation also ensures that a gComponent object is available in the QML code that offers access to this component class.

Parameters
namename of the QML object that needs to be loaded
urlURL from which the QML file needs to be loaded. If you reimplement this function you must ensure that http, ftp, qrc and file URL schemes are fully supported.
infokey=value information map associated with the QML object that needs to be loaded
Returns
pointer to the QML object that was loaded.
bool GCF::QmlComponent::unloadQmlObject ( const QString &  name,
QObject *  qmlObject,
const QVariantMap &  info 
)
protectedvirtual

This function can be implemented to customize the unloading of a QML object. The default implementation simply deletes the QML object.

Parameters
namename of the QML object that needs to be unloaded
qmlObjectpointer to the QMl object that needs to be unloaded
infokey=value information map associated with the QML object that needs to be unloaded
Returns
true on successful unloading of the object, false otherwise. The default implemnetation always returns true.