Option

Since: BlackBerry 10.0.0

#include <bb/cascades/Option>

An option that can be used in a list of selectable items.

The text, description, and image properties are displayed on the screen with the intention to give visual feedback to the user regarding the option. The value property is not visible and is intended as a utility for associating the option with a certain value.

An Option is intended to be used by any control that needs to display options as selectable items in some sort of list (e.g. the DropDown control).

Not all properties in the Option control need to be visually represented by a certain control. It is up to the control that uses it to implement whatever properties it needs to and determine how they are presented.

Here's a simple QML example demonstrating how a DropDown uses options:
DropDown {
    title: "Reminder"
    enabled: true

    // image + text + description
    Option {
        imageSource: "asset:///alarm.png"
        text: "5 min"
        description: "Sets the alarm to 5 minutes"
        value: "5min"
        selected: true

        onSelectedChanged: {
            if (selected) {
                console.log("Setting alarm to 5 minutes.");
            }
        }
    }

    // text + description
    Option {
        text: "10 min"
        description: "Sets the alarm to 10 minutes"
        value: "10min"
    }

    // text only
    Option {
        text: "15 min"
        value: "15min"
    }
}
And another example in C++:
DropDown* dropDown = DropDown::create().title("DropDown");
dropDown->add(Option::create().text("Option 1"));
dropDown->add(Option::create().text("Option 2"));
dropDown->add(Option::create().text("Option 3"));

rootContainer->add(dropDown);


Overview

Inheritance

QML properties

description: QString
enabled: bool
focused: bool [read-only]
image: bb::cascades::Image
imageSource: QUrl
selected: bool
text: QString
value: QVariant
attachedObjects: QDeclarativeListProperty< QObject > [read-only]Inherited
objectName: QStringInherited
parent: QObject [read-only]Inherited
ui: bb::cascades::UIConfig [read-only]Inherited

Properties Index

QStringdescription
boolenabled
boolfocused [read-only]
QVariantimage
QUrlimageSource
boolselected
QStringtext
QVariantvalue
QDeclarativeListProperty< QObject >attachedObjects [read-only]Inherited
QStringobjectNameInherited
QObjectparent [read-only]Inherited
bb::cascades::UIConfigui [read-only]Inherited

Public Functions Index

Option (Control *parent=0)
virtual ~Option ()
const QStringdescription () const
Imageimage () const
QUrlimageSource () const
boolisEnabled () const
boolisFocused () const
boolisSelected () const
Q_SLOT voidloseFocus ()
Q_SLOT voidrequestFocus ()
Q_SLOT voidresetDescription ()
Q_SLOT voidresetEnabled ()
Q_SLOT voidresetImage ()
Q_SLOT voidresetImageSource ()
Q_SLOT voidresetSelected ()
Q_SLOT voidresetText ()
Q_SLOT voidresetValue ()
Q_SLOT voidsetDescription (const QString &description)
Q_SLOT voidsetEnabled (bool enabled)
Q_SLOT voidsetImage (const Image &image)
Q_SLOT voidsetImageSource (const QUrl &source)
Q_SLOT voidsetSelected (bool selected)
Q_SLOT voidsetText (const QString &text)
Q_SLOT voidsetValue (const QVariant &value)
const QStringtext () const
const QVariantvalue () const
virtual boolevent (QEvent *event)Inherited
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited
Q_INVOKABLE bb::cascades::UIConfig *ui () const Inherited

Static Public Functions Index

Buildercreate ()

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited
virtual voidconnectNotify (const char *signal)Inherited
virtual voiddisconnectNotify (const char *signal)Inherited

Signals Index

voiddescriptionChanged (QString description)
voidenabledChanged (bool enabled)
voidfocusedChanged (bool focused)
voidimageChanged (const bb::cascades::Image &image)
voidimageSourceChanged (const QUrl &imageSource)
voidselectedChanged (bool selected)
voidtextChanged (QString text)
voidvalueChanged (QVariant value)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

QString description

A description text set on this option.

Since:

BlackBerry 10.0.0

bool enabled

Indicates whether the option is enabled.

When the option is disabled, it cannot be selected by interaction. However, the programmatic API allows selection updates even for disabled options.

If true the option is enabled, if false it is disabled. The default value is true (enabled). The enabledChanged() signal is emitted when the enabled state changes.

Since:

BlackBerry 10.0.0

bool focused[read-only]

Indicates the focused state of the option.

true if the option is focused, false otherwise. The default value is false (not focused). The focusedChanged() signal is emitted when the focused state changes.

Since:

BlackBerry 10.3.1

QVariant image

An image set on this option.

This image can be used for giving the user additional information on this option (e.g. a contact image). The default value is a null image, indicating that no image is set. The imageChanged() signal is emitted when the image changes.

Since:

BlackBerry 10.0.0

QUrl imageSource

An image to display on the option.

If no image is set, an invalid QUrl will be returned. When changing the image source the imageSourceChanged() signal will be emitted.

Since:

BlackBerry 10.0.0

bool selected

Indicates the selected state of the option.

true if the option is selected, false otherwise. The default value is false (not selected). The selectedChanged() signal is emitted when the selected state changes.

Since:

BlackBerry 10.0.0

QString text

A title text set on this option.

This is the primary textual representation of the option and should reflect what this option is. The default value is QString::null, indicating that no title text is set. The textChanged() signal is emitted when the text changes.

Since:

BlackBerry 10.0.0

QVariant value

A value set on this option.

The value is intended to associate the option with a value and thus isn't visually represented. The value in question can be anything application specific, such as a pointer to a record set in a database. The default value is QVariant::Invalid, indicating that no value is set. The valueChanged() signal is emitted when the value changes.

Since:

BlackBerry 10.0.0

QDeclarativeListProperty< QObject > attachedObjectsInherited[read-only]

A hierarchical list of the UIObject's attached objects.

Since:

BlackBerry 10.0.0

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

bb::cascades::UIConfig uiInherited[read-only]

An object that gives access to unit conversion routines.

QML use:
        // Size using design units
        Container {
            preferredWidth: ui.du(12)
            preferredHeight: ui.du(5)
        }

        // Size using design units, snap to whole pixels
        Container {
            preferredWidth: ui.sdu(13.5)
            preferredHeight: ui.sdu(7.5)
        }

        // Size using absolute pixel values
        Container {
            preferredWidth: ui.px(150)
            preferredHeight: ui.px(50)
        }
C++ use:
Container *container1 = Container::create().background(Color::Red);
UIConfig *ui = container1->ui();
container1->setPreferredWidth(ui->du(12));
container1->setPreferredHeight(ui->du(5));

Container *container2 = Container::create().background(Color::Green);
container2->setPreferredWidth(ui->sdu(13.5));
container2->setPreferredHeight(ui->sdu(7.5));

Container *container3 = Container::create().background(Color::Blue);
container3->setPreferredWidth(ui->px(150));
container3->setPreferredHeight(ui->sdu(50));
Since:

Blackberry 10.3.0

Public Functions

Option (

Constructs an Option.

Parameters
parent

The parent Control of this Option. The default is 0 if you don't specify a parent. If not 0, the ownership of the constructed option will be transferred to the parent.

Since:

BlackBerry 10.0.0

virtual~Option ()

Destructor.

Since:

BlackBerry 10.0.0

const QString description ()

Returns the description text set on this option.

QString::null is returned when description text was not set.

Return:

The description text set on this option.

Since:

BlackBerry 10.0.0

Image image ()

Returns the image set on this option.

A null Image is returned when an image is not set.

Return:

The image set on this option.

Since:

BlackBerry 10.0.0

QUrl imageSource ()

Returns the image source.

Return:

The source of the displayed image.

Since:

BlackBerry 10.0.0

bool isEnabled ()

Returns the enabled state of the option (i.e.

if it is enabled or not).

Return:

true if the option is enabled, false otherwise.

Since:

BlackBerry 10.0.0

bool isFocused ()

Returns the focused state of the option.

Return:

true if this option is focused, false otherwise.

Since:

BlackBerry 10.3.1

bool isSelected ()

Returns the selected state for the option.

Return:

true if this option is selected, false if it is not selected.

Since:

BlackBerry 10.0.0

Q_SLOT void loseFocus ()

Resets the option to the default state (not focused).

Since:

BlackBerry 10.3.1

Q_SLOT void requestFocus ()

Requests focus for the option.

Since:

BlackBerry 10.3.1

Q_SLOT void resetDescription ()

Resets the description text on this option to a default value of QString::null.

The descriptionChanged() signal is emitted if the description text is changed.

Since:

BlackBerry 10.0.0

Q_SLOT void resetEnabled ()

Resets the enabled state of the option to true.

Since:

BlackBerry 10.0.0

Q_SLOT void resetImage ()

Resets the image on this option to a default value of a null Image.

The imageChanged() signal is emitted if the image is reset.

Since:

BlackBerry 10.0.0

Q_SLOT void resetImageSource ()

Resets the Image on the option to its default, meaning that no image is set.

This function emits an imageSourceChanged() signal if the currently set image source changes.

Since:

BlackBerry 10.0.0

Q_SLOT void resetSelected ()

Resets the option to the default state (not selected).

Since:

BlackBerry 10.0.0

Q_SLOT void resetText ()

Resets the text on this option to a default value of QString::null.

The textChanged() signal is emitted if the text is reset.

Since:

BlackBerry 10.0.0

Q_SLOT void resetValue ()

Resets the value of this option.

The valueChanged() signal is emitted if the value is changed.

Since:

BlackBerry 10.0.0

Q_SLOT void setDescription (

Sets the description text on this option.

The descriptionChanged() signal is emitted if the description text is changed.

Parameters
description

The new description text for this option.

Since:

BlackBerry 10.0.0

Q_SLOT void setEnabled (
  • boolenabled)

Sets the enabled state of the option (i.e.

if it is enabled or not).

Parameters
enabled

If true the option is enabled, if false the option is disabled.

Since:

BlackBerry 10.0.0

Q_SLOT void setImage (

Sets the image on this option.

The imageChanged() signal is emitted if the image is changed.

Parameters
image

The new image for this option.

Since:

BlackBerry 10.0.0

Q_SLOT void setImageSource (

Sets the Image for the option.

An invalid QUrl indicates no image. This function emits an imageSourceChanged() signal if the currently set image source changes.

Parameters
source

The image url.

Since:

BlackBerry 10.0.0

Q_SLOT void setSelected (
  • boolselected)

Sets the selected state for the option.

Parameters
selected

If true this option is selected, if false this option is not selected.

Since:

BlackBerry 10.0.0

Q_SLOT void setText (

Sets the new text on this option.

The textChanged() signal is emitted if the text is changed.

Parameters
text

The new text for this option.

Since:

BlackBerry 10.0.0

Q_SLOT void setValue (

Sets the value on this option.

The valueChanged() signal is emitted if the value is changed.

Parameters
value

The new value for this option.

Since:

BlackBerry 10.0.0

const QString text ()

Returns the text set on this option.

QString::null is returned when text was not set.

Return:

The text set on this option.

Since:

BlackBerry 10.0.0

const QVariant value ()

Returns the value set on this option.

Return:

The value set on this option.

Since:

BlackBerry 10.0.0

virtual bool event (Inherited

Overloaded to implement the event mechanism in Cascades.

Warning!

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
event

The received event.

Return:

True if the received event was recognized and processed, false otherwise.

Since:

BlackBerry 10.0.0

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

Q_INVOKABLE bb::cascades::UIConfig * ui ()Inherited

Returns the UIConfig for this ui object.

The UIConfig can be used to perform unit conversions from design units (du) and snapped design units (sdu) to pixels.

Ownership remains with Cascades.

C++ use:
Container *container1 = Container::create().background(Color::Red);
UIConfig *ui = container1->ui();
container1->setPreferredWidth(ui->du(12));
container1->setPreferredHeight(ui->du(5));

Container *container2 = Container::create().background(Color::Green);
container2->setPreferredWidth(ui->sdu(13.5));
container2->setPreferredHeight(ui->sdu(7.5));

Container *container3 = Container::create().background(Color::Blue);
container3->setPreferredWidth(ui->px(150));
container3->setPreferredHeight(ui->sdu(50));
Return:

The UIConfig for this ui object.

Since:

BlackBerry 10.3.0

Static Public Functions

Builder create ()

Creates and returns a builder for constructing a Option.

Using the builder to create a Option:

Option* option5 = Option::create()
    .text("option 5")
    .selected(true);
Return:

A builder used for constructing an Option.

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

virtual void connectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The connected signal.

Since:

BlackBerry 10.0.0

virtual void disconnectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The disconnected signal.

Since:

BlackBerry 10.0.0

Signals

void descriptionChanged (

Emitted when this option's description text changes.

Parameters
description

The new description string, or QString::null if changed to an empty description.

Since:

BlackBerry 10.0.0

void enabledChanged (
  • boolenabled)

Emitted when the enabled property on the option changes.

Parameters
enabled

If true the option is enabled, if false the option is disabled.

Since:

BlackBerry 10.0.0

void focusedChanged (
  • boolfocused)

Emitted when the focused state changes.

Parameters
focused

The new focused state. If true this option is focused, if false this option is not focused.

Since:

BlackBerry 10.3.1

void imageChanged (

Emitted when this option's image changes.

Parameters
image

The new image, or a null image if no image is shown.

Since:

BlackBerry 10.0.0

void imageSourceChanged (
  • const QUrl &imageSource)

Emitted when the image source changes.

Parameters
imageSource

The new image source, or an invalid QUrl if no source is set.

Since:

BlackBerry 10.0.0

void selectedChanged (
  • boolselected)

Emitted when the selected state changes.

Parameters
selected

The new selected state. If true this option is selected, if false this option is not selected.

Since:

BlackBerry 10.0.0

void textChanged (

Emitted when this option's title text changes.

Parameters
text

The new text string, or QString::null if changed to an empty text.

Since:

BlackBerry 10.0.0

void valueChanged (

Emitted when this option's value changes.

Parameters
value

The new value, or QString::null if changed to an empty value.

Since:

BlackBerry 10.0.0

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-09-30



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

comments powered by Disqus