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.
- GCF::Component::activationEvent() and GCF::Component::deactivationEvent() - to gather changes to component activation and update the active property.
- GCF::Component::contentObjectLoadEvent() - to identify qml object kinds and support loading / instantiation of QML objects from
.qml files.
- GCF::Component::contentObjectMergeEvent() - to ignore merge events for QML objects
- GCF::Component::contentObjectUnloadEvent() - to unload QML objects effectively
- GCF::Component::contentObjectUnmergeEvent() - to ignore unmerge events for QML objects
- GCF::Component::activateContentObjectEvent() - to ignore activation events for QML objects
- GCF::Component::deactivateContentObjectEvent() - to ignore deactivation events for QML objects
Content files for QML components can make use of type=qml
and url=
attributes in object
XML element to load QML objects. Example
- 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 referencethis
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.
|
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
-
name name to be set on QML object loaded from url
.url location of the .qml file from which the QML object should be loaded.
http
,file
,ftp
andqrc
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.
QObject * GCF::QmlComponent::addQml | ( | const QUrl & | url | ) |
This function adds a QML object from url
.
- Parameters
-
url location of the .qml file from which the QML object should be loaded.
http
,file
,ftp
andqrc
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
-
name name of the QML object object pointer 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
-
object pointer 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
-
name name 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
-
name name 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)
|
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.
|
protectedvirtual |
Updates the active
property and calls the base class implementation of this event handler
Reimplemented from GCF::Component.
|
protectedvirtual |
Updates the active
property and calls the base class implementation of this event handler
Reimplemented from GCF::Component.
|
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.
|
protectedvirtual |
This event hanlder is implemented to ignore merge events for QML objects
Reimplemented from GCF::Component.
|
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.
|
protectedvirtual |
This event hanlder is implemented to ignore unmerge events for QML objects
Reimplemented from GCF::Component.
|
protectedvirtual |
This event hanlder is implemented to ignore activation events for QML objects
Reimplemented from GCF::Component.
|
protectedvirtual |
This event hanlder is implemented to ignore deactivation events for QML objects
Reimplemented from GCF::Component.
|
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
-
name name of the QML object that needs to be loaded url URL from which the QML file needs to be loaded. If you reimplement this function you must ensure that http
,ftp
,qrc
andfile
URL schemes are fully supported.info key=value information map associated with the QML object that needs to be loaded
- Returns
- pointer to the QML object that was loaded.
|
protectedvirtual |
This function can be implemented to customize the unloading of a QML object. The default implementation simply deletes the QML object.
- Parameters
-
name name of the QML object that needs to be unloaded qmlObject pointer to the QMl object that needs to be unloaded info key=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.