JUCE
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Types | Public Member Functions
SelectedItemSet< SelectableItemType > Class Template Reference

Manages a list of selectable items. More...

Inherits ChangeBroadcaster.

List of all members.

Public Types

typedef SelectableItemType ItemType

Public Member Functions

typedef PARAMETER_TYPE (SelectableItemType) ParameterType
 SelectedItemSet ()
 Creates an empty set.
 SelectedItemSet (const Array< SelectableItemType > &items)
 Creates a set based on an array of items.
 SelectedItemSet (const SelectedItemSet &other)
 Creates a copy of another set.
SelectedItemSetoperator= (const SelectedItemSet &other)
 Creates a copy of another set.
void selectOnly (ParameterType item)
 Clears any other currently selected items, and selects this item.
void addToSelection (ParameterType item)
 Selects an item.
void addToSelectionBasedOnModifiers (ParameterType item, const ModifierKeys &modifiers)
 Selects or deselects an item.
bool addToSelectionOnMouseDown (ParameterType item, const ModifierKeys &modifiers)
 Selects or deselects items that can also be dragged, based on a mouse-down event.
void addToSelectionOnMouseUp (ParameterType item, const ModifierKeys &modifiers, const bool wasItemDragged, const bool resultOfMouseDownSelectMethod)
 Selects or deselects items that can also be dragged, based on a mouse-up event.
void deselect (ParameterType item)
 Deselects an item.
void deselectAll ()
 Deselects all items.
int getNumSelected () const noexcept
 Returns the number of currently selected items.
SelectableItemType getSelectedItem (const int index) const noexcept
 Returns one of the currently selected items.
bool isSelected (ParameterType item) const noexcept
 True if this item is currently selected.
const Array< SelectableItemType > & getItemArray () const noexcept
virtual void itemSelected (SelectableItemType item)
 Can be overridden to do special handling when an item is selected.
virtual void itemDeselected (SelectableItemType item)
 Can be overridden to do special handling when an item is deselected.
void changed (const bool synchronous=false)
 Used internally, but can be called to force a change message to be sent to the ChangeListeners.

Detailed Description

template<class SelectableItemType>
class SelectedItemSet< SelectableItemType >

Manages a list of selectable items.

Use one of these to keep a track of things that the user has highlighted, like icons or things in a list.

The class is templated so that you can use it to hold either a set of pointers to objects, or a set of ID numbers or handles, for cases where each item may not always have a corresponding object.

To be informed when items are selected/deselected, register a ChangeListener with this object.

See also:
SelectableObject

Member Typedef Documentation

template<class SelectableItemType >
typedef SelectableItemType SelectedItemSet< SelectableItemType >::ItemType

Constructor & Destructor Documentation

template<class SelectableItemType >
SelectedItemSet< SelectableItemType >::SelectedItemSet ( )

Creates an empty set.

template<class SelectableItemType >
SelectedItemSet< SelectableItemType >::SelectedItemSet ( const Array< SelectableItemType > &  items) [explicit]

Creates a set based on an array of items.

template<class SelectableItemType >
SelectedItemSet< SelectableItemType >::SelectedItemSet ( const SelectedItemSet< SelectableItemType > &  other)

Creates a copy of another set.


Member Function Documentation

template<class SelectableItemType >
typedef SelectedItemSet< SelectableItemType >::PARAMETER_TYPE ( SelectableItemType  )
template<class SelectableItemType >
SelectedItemSet& SelectedItemSet< SelectableItemType >::operator= ( const SelectedItemSet< SelectableItemType > &  other)

Creates a copy of another set.

template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::selectOnly ( ParameterType  item)

Clears any other currently selected items, and selects this item.

If this item is already the only thing selected, no change notification will be sent out.

See also:
addToSelection, addToSelectionBasedOnModifiers

References jmin().

template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::addToSelection ( ParameterType  item)

Selects an item.

If the item is already selected, no change notification will be sent out.

See also:
selectOnly, addToSelectionBasedOnModifiers
template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers ( ParameterType  item,
const ModifierKeys modifiers 
)

Selects or deselects an item.

This will use the modifier keys to decide whether to deselect other items first.

So if the shift key is held down, the item will be added without deselecting anything (same as calling addToSelection() )

If no modifiers are down, the current selection will be cleared first (same as calling selectOnly() )

If the ctrl (or command on the Mac) key is held down, the item will be toggled - so it'll be added to the set unless it's already there, in which case it'll be deselected.

If the items that you're selecting can also be dragged, you may need to use the addToSelectionOnMouseDown() and addToSelectionOnMouseUp() calls to handle the subtleties of this kind of usage.

See also:
selectOnly, addToSelection, addToSelectionOnMouseDown, addToSelectionOnMouseUp

References ModifierKeys::isCommandDown(), and ModifierKeys::isShiftDown().

template<class SelectableItemType >
bool SelectedItemSet< SelectableItemType >::addToSelectionOnMouseDown ( ParameterType  item,
const ModifierKeys modifiers 
)

Selects or deselects items that can also be dragged, based on a mouse-down event.

If you call addToSelectionOnMouseDown() at the start of your mouseDown event, and then call addToSelectionOnMouseUp() at the end of your mouseUp event, this makes it easy to handle multiple-selection of sets of objects that can also be dragged.

For example, if you have several items already selected, and you click on one of them (without dragging), then you'd expect this to deselect the other, and just select the item you clicked on. But if you had clicked on this item and dragged it, you'd have expected them all to stay selected.

When you call this method, you'll need to store the boolean result, because the addToSelectionOnMouseUp() method will need to be know this value.

See also:
addToSelectionOnMouseUp, addToSelectionBasedOnModifiers

References ModifierKeys::isPopupMenu().

template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::addToSelectionOnMouseUp ( ParameterType  item,
const ModifierKeys modifiers,
const bool  wasItemDragged,
const bool  resultOfMouseDownSelectMethod 
)

Selects or deselects items that can also be dragged, based on a mouse-up event.

Call this during a mouseUp callback, when you have previously called the addToSelectionOnMouseDown() method during your mouseDown event.

See addToSelectionOnMouseDown() for more info

Parameters:
itemthe item to select (or deselect)
modifiersthe modifiers from the mouse-up event
wasItemDraggedtrue if your item was dragged during the mouse click
resultOfMouseDownSelectMethodthis is the boolean return value that came back from the addToSelectionOnMouseDown() call that you should have made during the matching mouseDown event
template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::deselect ( ParameterType  item)

Deselects an item.

template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::deselectAll ( )

Deselects all items.

References jmin().

template<class SelectableItemType >
int SelectedItemSet< SelectableItemType >::getNumSelected ( ) const

Returns the number of currently selected items.

See also:
getSelectedItem
template<class SelectableItemType >
SelectableItemType SelectedItemSet< SelectableItemType >::getSelectedItem ( const int  index) const

Returns one of the currently selected items.

Returns 0 if the index is out-of-range.

See also:
getNumSelected
template<class SelectableItemType >
bool SelectedItemSet< SelectableItemType >::isSelected ( ParameterType  item) const

True if this item is currently selected.

template<class SelectableItemType >
const Array<SelectableItemType>& SelectedItemSet< SelectableItemType >::getItemArray ( ) const
template<class SelectableItemType >
virtual void SelectedItemSet< SelectableItemType >::itemSelected ( SelectableItemType  item) [virtual]

Can be overridden to do special handling when an item is selected.

For example, if the item is an object, you might want to call it and tell it that it's being selected.

template<class SelectableItemType >
virtual void SelectedItemSet< SelectableItemType >::itemDeselected ( SelectableItemType  item) [virtual]

Can be overridden to do special handling when an item is deselected.

For example, if the item is an object, you might want to call it and tell it that it's being deselected.

template<class SelectableItemType >
void SelectedItemSet< SelectableItemType >::changed ( const bool  synchronous = false)

Used internally, but can be called to force a change message to be sent to the ChangeListeners.

References ChangeBroadcaster::sendChangeMessage(), and ChangeBroadcaster::sendSynchronousChangeMessage().


The documentation for this class was generated from the following file: