MultiSelectHandler
#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!");
}
}
]
}
}
BlackBerry 10.0.0
Inheritance
| bb::cascades::BaseObject | |||
| bb::cascades::UIObject | |||
| bb::cascades::MultiSelectHandler | |||
QML properties
| active | : bool |
| actions | : QDeclarativeListProperty< bb::cascades::AbstractActionItem > [read-only] |
| status | : QString |
| attachedObjects | : QDeclarativeListProperty< QObject > [read-only] |
| objectName | : QString |
| parent | : QObject [read-only] |
QML signals
| onActiveChanged | : {} |
| onActionAdded | : {} |
| onActionRemoved | : {} |
| onStatusChanged | : {} |
| onCanceled | : {} |
| onCreationCompleted | |
| onObjectNameChanged |
Properties Index
| bool | active |
| QDeclarativeListProperty< bb::cascades::AbstractActionItem > | actions [read-only] |
| QString | status |
| QDeclarativeListProperty< QObject > | attachedObjects [read-only] |
| QString | objectName |
| QObject | parent [read-only] |
Public Functions Index
| MultiSelectHandler (VisualNode *parent=0) | |
| virtual | ~MultiSelectHandler () |
| bool | isActive () const |
| Q_SLOT void | setActive (bool active) |
| Q_SLOT void | resetActive () |
| Q_INVOKABLE int | actionCount () const |
| Q_INVOKABLE bb::cascades::AbstractActionItem * | actionAt (int index) const |
| Q_INVOKABLE void | addAction (bb::cascades::AbstractActionItem *action) |
| Q_INVOKABLE bool | removeAction (bb::cascades::AbstractActionItem *action) |
| Q_INVOKABLE void | removeAllActions () |
| QString | status () const |
| Q_SLOT void | setStatus (const QString &status) |
| Q_SLOT void | resetStatus () |
| virtual bool | event (QEvent *event) |
| void | setObjectName (const QString &name) |
| virtual Q_INVOKABLE QString | toDebugString () const |
Static Public Functions Index
| Builder | create (VisualNode *target) |
Protected Functions Index
Only has inherited protected functions
| BaseObject (QObject *parent=0) | |
| virtual void | connectNotify (const char *signal) |
| virtual void | disconnectNotify (const char *signal) |
Signals Index
| void | activeChanged (bool active) |
| void | actionAdded (bb::cascades::AbstractActionItem *action) |
| void | actionRemoved (bb::cascades::AbstractActionItem *action) |
| void | statusChanged (const QString &status) |
| void | canceled () |
| void | creationCompleted () |
| void | objectNameChanged (const QString &objectName) |
Properties
bool
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.
BlackBerry 10.0.0
QDeclarativeListProperty< bb::cascades::AbstractActionItem >
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.
BlackBerry 10.0.0
QString
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.
BlackBerry 10.0.0
QDeclarativeListProperty< QObject >
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"
}
]
}
BlackBerry 10.0.0
QString
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.
QObject::objectName().
BlackBerry 10.0.0
QObject
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.
BlackBerry 10.0.0
Public Functions
Constructs a MultiSelectHandler.
BlackBerry 10.0.0
virtual
Destructor.
BlackBerry 10.0.0
bool
Returns whether the multi-select handler is currently active.
true if the handler is active, false otherwise.
BlackBerry 10.0.0
Q_SLOT void
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. |
BlackBerry 10.0.0
Q_SLOT void
Deactivates the multi-select handler.
BlackBerry 10.0.0
Q_INVOKABLE int
Returns the number of added actions.
Q_INVOKABLE bb::cascades::AbstractActionItem *
Returns a action at the specified index.
| Parameters | |
|---|---|
| index |
The index of the action. |
The requested action if the index was valid, 0 otherwise.
BlackBerry 10.0.0
Q_INVOKABLE void
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.
removeAction(), removeAllAction()
| Parameters | |
|---|---|
| action |
The action to add. |
BlackBerry 10.0.0
Q_INVOKABLE bool
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. |
true if the action was owned by the MultiSelectHandler, false otherwise.
BlackBerry 10.0.0
Q_INVOKABLE void
Removes and deletes all the added actions.
Once completed, the actionRemoved() signal is emitted with 0 as its parameter.
BlackBerry 10.0.0
QString
Returns the status text set for this handler.
The status text set for this handler, or QString::null of no text was set.
BlackBerry 10.0.0
Q_SLOT void
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. |
BlackBerry 10.0.0
Q_SLOT void
Removes the status text by setting it to String::null.
Once completed, the statusChanged() is emitted with String::null.
BlackBerry 10.0.0
virtual bool 
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 | |
|---|---|
| event |
The received event. |
True if the received event was recognized and processed, false otherwise.
BlackBerry 10.0.0
void 
Sets the objectName property.
| Parameters | |
|---|---|
| name |
The new name for the object. |
BlackBerry 10.0.0
virtual Q_INVOKABLE QString 
Returns a debug string representing this object.
A debug string for the object.
BlackBerry 10.0.0
Static Public Functions
Builder
Creates and returns a builder for constructing an MultiSelectHandler.
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.
A Builder for constructing an MultiSelectHandler.
BlackBerry 10.0.0
Protected Functions
(Only has inherited protected functions)
Constructs an instance of BaseObject's subclass.
| Parameters | |
|---|---|
| parent |
An optional parent, defaults to 0. |
BlackBerry 10.0.0
virtual void 
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. |
BlackBerry 10.0.0
virtual void 
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. |
BlackBerry 10.0.0
Signals
void
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. |
BlackBerry 10.0.0
void
Emitted when an action has been added to the MultiSelectHandler.
| Parameters | |
|---|---|
| action |
The action that has been added. |
BlackBerry 10.0.0
void
Emitted when an action has been removed from the MultiSelectHandler.
| Parameters | |
|---|---|
| action |
The action that has been removed. 0 if emitted by removeAll(). |
BlackBerry 10.0.0
void
Emitted when the status text is changed or removed.
| Parameters | |
|---|---|
| status |
The new status text or QString::null if it was removed. |
BlackBerry 10.0.0
void
Emitted when the multi select is canceled.
BlackBerry 10.0.0
void 
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.
BlackBerry 10.0.0
void 
This signal is emitted when the objectName property is changed.
BlackBerry 10.0.0