Delegate

Since: BlackBerry 10.2.0

Provides a generic delegate that instantiate an object when active and deletes it when it is not active.

Delegate is used for dynamically creating and deleting an object from QML.

The Delegate exposes an active property which can be used for explicitly loading and unloading the qml components. When the components have been loaded object will be set. Should the components fail to load object will be null and errorMessage will be set.

Here's an example of how to use Delegate. In this example the page of a sheet is loaded when the sheet is opened and deleted when the sheet is closed.
Page { 
    attachedObjects: [
        Delegate {
            id: sheetPageDelegate
            Page {
                Container {
                    Button { 
                        text: "Close"
                        onClicked: {
                            sheet.close();
                        }
                    }
                }
            }
        },
        Sheet {
            id: sheet
            content: sheetPageDelegate.object
            onOpenedChanged: {
                if (opened)
                    sheetPageDelegate.active = true;
            }
            onClosed: {
                sheetPageDelegate.active = false;
            }
        }
    ]
    Container {
        Button { 
            text: "Open sheet" 
            onClicked: {
                sheet.open();
            }
        }
    }
}


Overview

Inheritance

bb::cascades::BaseObject
bb::cascades::Delegate

QML properties

active: bool
component: QDeclarativeComponent
errorMessage: QString [read-only]
object: QObject [read-only]
source: QUrl
sourceComponent: bb::cascades::QmlComponentDefinition
objectName: QStringInherited
parent: QObject [read-only]Inherited

Properties Index

Public Functions Index

Only has inherited public functions

voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited

Signals Index

voidactiveChanged (bool active)
voidcomponentChanged (QDeclarativeComponent *component)
voiderrorMessageChanged (const QString &errorMessage)
voidobjectChanged (QObject *object)
voidsourceChanged (const QUrl &source)
voidsourceComponentChanged (bb::cascades::QmlComponentDefinition *sourceComponent)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

bool active

property controlling whether the object should be loaded or not

When active is true Delegate will try to create object. When active is false Delegate will delete object if object is not null.

The default value of this property is false

QDeclarativeComponent component

A definition of inline component.

Defines the actual component which can be created from this delegate

By default this property is null

QString errorMessage[read-only]

returns an error message in case something goes wrong with loading and parsing the component defined by the source property or the inlined component

In case there are no errors, an empty string is returned.

Return:

string with the error message

QObject object[read-only]

Read only property with the actual object created from the source or component definition.

The returned object is a regular object instance, so it is possible to set properties, call functions or register for signals of the concrete class this object represents.

In case creating object from a source or sourceComponent fails, this property returns null.

Default value of this property (when no sourceComponent or source is set) is null

QUrl source

Source loaded when active is true.

Currently supported URLs are relative, file:// or asset://. Loading files from network ( http://, ftp://) or other schemas is not supported.

Default value of is this property is empty
See also:

QUrl

bb::cascades::QmlComponentDefinition sourceComponent

ComponentDefinition loaded when active is true.

The default value of this property is null

QString objectNameInherited

This property is overridden from QObject.

See also:

QObject::objectName().

Since:

BlackBerry 10.0.0

QObject parentInherited[read-only]

A read-only property that represents this object's parent.

The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.

This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.

The default value of this property is 0.

Since:

BlackBerry 10.0.0

Public Functions

(Only has inherited public functions)

void setObjectName (Inherited

Sets the objectName property.

Parameters
name

The new name for the object.

Since:

BlackBerry 10.0.0

virtual Q_INVOKABLE QString toDebugString ()Inherited

Returns a debug string representing this object.

Return:

A debug string for the object.

Since:

BlackBerry 10.0.0

Protected Functions

(Only has inherited protected functions)

BaseObject (Inherited

Constructs an instance of BaseObject's subclass.

Parameters
parent

An optional parent, defaults to 0.

Since:

BlackBerry 10.0.0

Signals

void activeChanged (
  • boolactive)

Emitted when a component is activated or deactivated.

Parameters
active

true when the created control is active (created) or false when inactive (deleted)

void componentChanged (
  • QDeclarativeComponent *component)

Emitted when component property is changed.

Parameters
component

The component used for creating the object

void errorMessageChanged (

Emitted when loading component from specified source fails.

Parameters
errorMessage

The error messages returned by the QmlDocument loader

void objectChanged (

Emitted when a new object is created or if the object is deleted.

Parameters
object

The actual created object if successfully created or null if deleted

void sourceChanged (

Emitted when source property is changed.

Parameters
source

The QUrl from which the component should be loaded

void sourceComponentChanged (

Emitted when sourceComponent property is changed.

Parameters
sourceComponent

The new sourceComponent

void creationCompleted ()Inherited

Emitted when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class.

This signal indicates that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.

This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.

This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.

See also:

QmlDocument

Since:

BlackBerry 10.0.0

void objectNameChanged (Inherited

This signal is emitted when the objectName property is changed.

Since:

BlackBerry 10.0.0

Last modified: 2014-08-07



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus