MultiSelectHandler

Since: BlackBerry 10.0.0

#include <bb/cascades/MultiSelectHandler>

A handler used during multiple selection to populate the Context Menu.

The multi-select handler represents a multiple selection session involving the Context Menu. Only one multi-select handler can be active at at time. The active property tells whether the handler is active or not. Setting the active property to true will start multiple selection with this handler and cancel any other handler that was active. During multiple selection the Context Menu is shown populated with the actions from the current handler.

The MultiSelectHandler can be specified as an attached object in any control or specified in the ListView as a multiSelectHandler property.

There are some special cases where you will get a lot for free from the MultiSelectHandler:

If you add the MultiSelectHandler to a ListView and that MultiSelectHandler has the multiSelectAction property set, the ListItems will automatically have a MultiSelectActionItem in their context menu. If One of the ListItems have the multiSelectAction property set that MultiSelectActionItem will override the one set in the MultiSelectHandler, but just for that specific ListItem type.

If you have a MultiSelectActionItem connected to your MultiSelectHandler that item will activate the handler automatically. However, if you add a MultiSelectActionItem to a control, then you must connect the signals and activate the desired MultiSelectHandler manually.

Container {
    background: Color.Black

    attachedObjects: [
        MultiSelectHandler {
            id: theFirstSelectHandler
            actions: [
                 ActionItem { title: "Create Album" },
                 ActionItem { title: "Mark as read" },
                 ActionItem { title: "Mark as unread" },
                 DeleteActionItem { title: "Delete" }
            ]
            deleteAction:  DeleteActionItem { title: "Delete" }

            status: "This is the status text"

            onActiveChanged: {
                 console.log("First handler active!");
            }
            
            onCanceled: {
                 console.log("Multi selection canceled!");
            }
        }
    ]
}
ListView {
    id: theListView

    // This multi-select action will be placed inside the ActionSets of each 
    // list item that doesn't have a MultiSelectActionItem of its own.
    multiSelectAction: MultiSelectActionItem {}

    multiSelectHandler {
        // These actions will be shown during multiple selection, while this 
        // multiSelectHandler is active
        actions: [
            ActionItem {title: "Multi-select action"},
            DeleteActionItem {}
        ]

        status: "None selected"

        onActiveChanged: {
            if (active == true) {
                console.log("Multiple selection is activated");
            }
            else {
                console.log("Multiple selection is deactivated");
            }
        }

        onCanceled: {
            console.log("Multi selection canceled!");
        }
    }

    listItemComponents: [
        ListItemComponent {
            id: friend
            // This MultiSelectActionItem set on the ListView will automatically show up here.
            ActionSet {
            }
        },

        ListItemComponent {
            id: colleague
            // This MultiSelectActionItem set on the ListView will not show up here, since
            // it already has a MultiSelectActionItem in the ActionSet.
            ActionSet {
                MultiSelectActionItem { title: "Special Select"}
            }
        }
    ]
}

Here is an example of multiple handlers. Since only one handler can be active at time, activating one will deactivate the other and switch the content in the Context Menu.

Page {
  actions:  [
    MultiSelectActionItem { 
      multiSelectHandler: theFirstSelectHandler 
      onTriggered: {
        multiSelectHandler.active = true;
      }
    }
  ]

  Container {
    background: Color.Black

    attachedObjects: [
      MultiSelectHandler {
        id: theFirstSelectHandler
        actions: [
          ActionItem {
            title: "Create Album"
          },
          ActionItem {
            title: "Mark as read"
          },
          ActionItem {
            title: "Mark as unread"
          },
          DeleteActionItem { title: "Delete" }
        ]

        status: "This is the status text"
      
        onActiveChanged: {
          console.log("First handler active!");
        }

        onCanceled: {
            console.log("Multi selection canceled!");
        }
      },
      
      MultiSelectHandler {
        id: theSecondSelectHandler
        actions: [
          ActionItem {
            title: "Copy"
          },
          ActionItem {
            title: "Paste"
          },
          DeleteActionItem { title: "Delete" }
        ]
       
        status: "This is the status text"
       
        onActiveChanged: {
          console.log("Second handler active!");
        }

        onCanceled: {
            console.log("Multi selection canceled!");
        }
      }  
    ]  
  }  
} 


Overview

Inheritance

bb::cascades::BaseObject
bb::cascades::UIObject
bb::cascades::MultiSelectHandler

QML properties

actions: QDeclarativeListProperty< bb::cascades::AbstractActionItem > [read-only]
active: bool
status: QString
attachedObjects: QDeclarativeListProperty< QObject > [read-only]Inherited
objectName: QStringInherited
parent: QObject [read-only]Inherited

Properties Index

QDeclarativeListProperty< bb::cascades::AbstractActionItem >actions [read-only]
boolactive
QStringstatus
QDeclarativeListProperty< QObject >attachedObjects [read-only]Inherited
QStringobjectNameInherited
QObjectparent [read-only]Inherited

Public Functions Index

MultiSelectHandler (VisualNode *parent=0)
virtual ~MultiSelectHandler ()
Q_INVOKABLE bb::cascades::AbstractActionItem *actionAt (int index) const
Q_INVOKABLE intactionCount () const
Q_INVOKABLE voidaddAction (bb::cascades::AbstractActionItem *action)
boolisActive () const
Q_INVOKABLE boolremoveAction (bb::cascades::AbstractActionItem *action)
Q_INVOKABLE voidremoveAllActions ()
Q_SLOT voidresetActive ()
Q_SLOT voidresetStatus ()
Q_SLOT voidsetActive (bool active)
Q_SLOT voidsetStatus (const QString &status)
QStringstatus () const
virtual boolevent (QEvent *event)Inherited
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited

Static Public Functions Index

Buildercreate (VisualNode *target)

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

voidactionAdded (bb::cascades::AbstractActionItem *action)
voidactionRemoved (bb::cascades::AbstractActionItem *action)
voidactiveChanged (bool active)
voidcanceled ()
voidstatusChanged (const QString &status)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

QDeclarativeListProperty< bb::cascades::AbstractActionItem > actions[read-only]

Actions to display during multiple selection when the handler is active.

These actions are displayed in the Context Menu during multiple selection when the multi-select handler is active.

Only one DeleteActionItem can be shown in the Context Menu. If more than one is added, only the first one is used and the rest are ignored. It is placed at a fixed position in the Context Menu along with the other actions.

Since:

BlackBerry 10.0.0

bool active

Indicates whether the handler is activated for multiple selection.

When a multi-select handler is active, the Context Menu is shown for multiple selection and it is populated using the content of the active handler. Only one multi-select handler can be active at at time, so activating one handler will deactivate any previously active handler.

The default value is false, indicating that the handler is not active.

Since:

BlackBerry 10.0.0

QString status

The status text to show during multiple selection.

The selection status text is shown on the Action Bar at a fixed position during multiple selection when this handler is active. According to general guidelines this should be a short sentence telling how many items are selected, e.g. "3 emails selected".

The default value is QString::null, indicating no status text is shown.

Since:

BlackBerry 10.0.0

QDeclarativeListProperty< QObject > attachedObjectsInherited[read-only]

A hierarchical list of the UIObject's attached objects.

This QDeclarativeListProperty can contain any QObject. When a QObject is added to property, the UIObject takes ownership of the attached object.

This feature is typically used from QML to specify business logic object or any other shared objects for the subnodes of this UIObject. In C++ the same functionality can be achived by setting a parent of a QObject to be attached to the QObject which is going to own it.

QML usage example (MyObject is a custom class registered for QML using the qmlRegisterType() function):

Container {
    Label { text: "Title: " + myObject.title } 
    Label { text: "Subject: " + myObject.subject }
    attachedObjects: [
        MyObject { id: myObject
            title: "Hello World"
            subject: "Nice Day"
        }
    ]
}

Since:

BlackBerry 10.0.0

QString objectNameInherited

This property is overridden from QObject.

As the objectName property is overridden from the QObject class, this signal will not be emitted if setObjectName() function is called directly on QObject.

The default value of this property is QString::null.

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

MultiSelectHandler (

Constructs a MultiSelectHandler.

Since:

BlackBerry 10.0.0

virtual~MultiSelectHandler ()

Destructor.

Since:

BlackBerry 10.0.0

Q_INVOKABLE bb::cascades::AbstractActionItem * actionAt (
  • intindex)

Returns a action at the specified index.

The ownership of the action remains with the handler.
See also:

actionCount()

Parameters
index

The index of the action.

Return:

The requested action if the index was valid, 0 otherwise.

Since:

BlackBerry 10.0.0

Q_INVOKABLE int actionCount ()

Returns the number of added actions.

See also:

actionAt()

Return:

The number of actions.

Since:

BlackBerry 10.0.0

Q_INVOKABLE void addAction (

Adds an action to show during multiple selection.

The actions are shown in the Context Menu during multiple selection when this handler is active.

The multi-select handler takes ownership of the action, so actions cannot be shared. If the action already has a parent or if it is 0, nothing will happen. Once completed, the actionAdded() signal is emitted.

See also:

removeAction(), removeAllAction()

Parameters
action

The action to add.

Since:

BlackBerry 10.0.0

bool isActive ()

Returns whether the multi-select handler is currently active.

Return:

true if the handler is active, false otherwise.

Since:

BlackBerry 10.0.0

Q_INVOKABLE bool removeAction (

Removes a previously added action.

Once the action is removed, the handler no longer references it, but it is still owned by the handler. It is up to the application to either delete the removed action, transfer its ownership (by setting its parent) to another object or leave it as a child of the handler (in which case it will be deleted with the handler).

Once completed, the actionRemoved() signal is emitted.

Parameters
action

The actionItem to remove.

Return:

true if the action was owned by the MultiSelectHandler, false otherwise.

Since:

BlackBerry 10.0.0

Q_INVOKABLE void removeAllActions ()

Removes and deletes all the added actions.

Once completed, the actionRemoved() signal is emitted with 0 as its parameter.

Since:

BlackBerry 10.0.0

Q_SLOT void resetActive ()

Deactivates the multi-select handler.

Since:

BlackBerry 10.0.0

Q_SLOT void resetStatus ()

Removes the status text by setting it to String::null.

Once completed, the statusChanged() is emitted with String::null.

Since:

BlackBerry 10.0.0

Q_SLOT void setActive (
  • boolactive)

Activates or deactivates the multi-select handler.

Parameters
active

If true the handler will be activated for multiple selection, and if false the handler will deactivated.

Since:

BlackBerry 10.0.0

Q_SLOT void setStatus (

Sets the status text to show during multiple selection.

The selection status text is shown on the Action Bar at a fixed position during multiple selection when this handler is active. According to general guidelines this should be a short sentence telling how many items are selected, e.g. "3 emails selected".

Once completed, the statusChanged() is emitted with the new text.

Parameters
status

The new status text for this list item.

Since:

BlackBerry 10.0.0

QString status ()

Returns the status text set for this handler.

Return:

The status text set for this handler, or QString::null of no text was set.

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

Static Public Functions

Builder create (

Creates and returns a builder for constructing an MultiSelectHandler.

Using the builder to create a multi-select handler:
Container* targetContainer = Container::create()
MultiSelectHandler* handler = MultiSelectHandler::create(targetContainer)
           .addAction(ActionItem::create().title("Reply")
           .addAction(ActionItem::create().title("Forward");

The user needs to specify what VisualNode this MultiSelectHandler will target, this is done automatically if you use QML but must be provided if it is created in C++. The target parameter is allowed to be 0 but then the MultiSelectHandler will do nothing.

Return:

A Builder for constructing an MultiSelectHandler.

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 actionAdded (

Emitted when an action has been added to the MultiSelectHandler.

Parameters
action

The action that has been added.

Since:

BlackBerry 10.0.0

void actionRemoved (

Emitted when an action has been removed from the MultiSelectHandler.

Parameters
action

The action that has been removed. 0 if emitted by removeAll().

Since:

BlackBerry 10.0.0

void activeChanged (
  • boolactive)

Emitted when the multi-select handler is activated or deactivated.

Parameters
active

If true the handler was activated for multiple selection, and if false the handler was deactivated.

Since:

BlackBerry 10.0.0

void canceled ()

Emitted when the multi select is canceled.

Since:

BlackBerry 10.0.0

void statusChanged (

Emitted when the status text is changed or removed.

Parameters
status

The new status text or QString::null if it was removed.

Since:

BlackBerry 10.0.0

void creationCompleted ()Inherited

This signal is emitted only when this object is instantiated as a result of loading a QML document and creating the root node, or when an object is being constructed using its builder class.

This signal is emitted only 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 is emitted to indicate 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-03-13

comments powered by Disqus