Loading...
Searching...
No Matches
juce::SelectedItemSet< SelectableItemType > Class Template Reference

## Detailed Description

template<class SelectableItemType>
class juce::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.

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

- juce_gui_basics/mouse/juce_SelectedItemSet.h

Inheritance diagram for juce::SelectedItemSet< SelectableItemType >:

## Public Types

using | ItemType = SelectableItemType
using | ItemArray = Array<SelectableItemType>
using | ParameterType = typename TypeHelpers::ParameterType<SelectableItemType>::type

## Public Member Functions

| SelectedItemSet ()=default
| Creates an empty set.
| SelectedItemSet (const ItemArray &items)
| Creates a set based on an array of items.
| SelectedItemSet (const SelectedItemSet &other)
| Creates a copy of another set.
SelectedItemSet & | operator= (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, ModifierKeys modifiers)
| Selects or deselects an item.
bool | addToSelectionOnMouseDown (ParameterType item, ModifierKeys modifiers)
| Selects or deselects items that can also be dragged, based on a mouse-down event.
void | addToSelectionOnMouseUp (ParameterType item, 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
| Returns one of the currently selected items.
bool | isSelected (ParameterType item) const noexcept
| True if this item is currently selected.
const ItemArray & | getItemArray () const noexcept
| Provides access to the array of items.
SelectableItemType * | begin () noexcept
| Provides iterator access to the array of items.
const SelectableItemType * | begin () const noexcept
SelectableItemType * | end () noexcept
| Provides iterator access to the array of items.
const SelectableItemType * | end () const noexcept
| Provides iterator access to the array of items.
virtual void | itemSelected (SelectableItemType)
| Can be overridden to do special handling when an item is selected.
virtual void | itemDeselected (SelectableItemType)
| Can be overridden to do special handling when an item is deselected.
void | changed ()
| Used internally, but can be called to force a change message to be sent to the ChangeListeners.
void | changed (const bool synchronous)
| Used internally, but can be called to force a change message to be sent to the ChangeListeners.
Public Member Functions inherited from juce::ChangeBroadcaster
| ChangeBroadcaster () noexcept
| Creates an ChangeBroadcaster.
virtual | ~ChangeBroadcaster ()
| Destructor.
void | addChangeListener (ChangeListener *listener)
| Registers a listener to receive change callbacks from this broadcaster.
void | removeChangeListener (ChangeListener *listener)
| Unregisters a listener from the list.
void | removeAllChangeListeners ()
| Removes all listeners from the list.
void | sendChangeMessage ()
| Causes an asynchronous change message to be sent to all the registered listeners.
void | sendSynchronousChangeMessage ()
| Sends a synchronous change message to all the registered listeners.
void | dispatchPendingMessages ()
| If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately.

## Member Typedef Documentation

## ItemType

template<class SelectableItemType>

using juce::SelectedItemSet< SelectableItemType >::ItemType = SelectableItemType

## ItemArray

template<class SelectableItemType>

using juce::SelectedItemSet< SelectableItemType >::ItemArray = Array<SelectableItemType>

## ParameterType

template<class SelectableItemType>

using juce::SelectedItemSet< SelectableItemType >::ParameterType = typename TypeHelpers::ParameterType<SelectableItemType>::type

## Constructors and Destructors

## SelectedItemSet() [1/3]

template<class SelectableItemType>

juce::SelectedItemSet< SelectableItemType >::SelectedItemSet | ( |  | ) |

default

Creates an empty set.

Referenced by operator=(), and SelectedItemSet().

## SelectedItemSet() [2/3]

template<class SelectableItemType>

juce::SelectedItemSet< SelectableItemType >::SelectedItemSet | ( | const ItemArray & | items | ) |

inline explicit

Creates a set based on an array of items.

## SelectedItemSet() [3/3]

template<class SelectableItemType>

juce::SelectedItemSet< SelectableItemType >::SelectedItemSet | ( | const SelectedItemSet< SelectableItemType > & | other | ) |

inline

Creates a copy of another set.

References juce::ChangeBroadcaster::ChangeBroadcaster(), and SelectedItemSet().

## Member Functions

## operator=()

template<class SelectableItemType>

SelectedItemSet & juce::SelectedItemSet< SelectableItemType >::operator= | ( | const SelectedItemSet< SelectableItemType > & | other | ) |

inline

Creates a copy of another set.

References changed(), isSelected(), itemDeselected(), itemSelected(), and SelectedItemSet().

## selectOnly()

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::selectOnly | ( | ParameterType | item | ) |

inline

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 changed(), deselect(), deselectAll(), isSelected(), itemSelected(), and juce::jmin().

Referenced by addToSelectionBasedOnModifiers().

## addToSelection()

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::addToSelection | ( | ParameterType | item | ) |

inline

Selects an item.

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

See also
  selectOnly, addToSelectionBasedOnModifiers

References changed(), isSelected(), and itemSelected().

Referenced by addToSelectionBasedOnModifiers().

## addToSelectionBasedOnModifiers()

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers | ( | ParameterType | item,
|  | ModifierKeys | modifiers )

inline

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 addToSelection(), deselect(), juce::ModifierKeys::isCommandDown(), isSelected(), juce::ModifierKeys::isShiftDown(), and selectOnly().

Referenced by addToSelectionOnMouseDown(), and addToSelectionOnMouseUp().

## addToSelectionOnMouseDown()

template<class SelectableItemType>

bool juce::SelectedItemSet< SelectableItemType >::addToSelectionOnMouseDown | ( | ParameterType | item,
|  | ModifierKeys | modifiers )

inline

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 addToSelectionBasedOnModifiers(), juce::ModifierKeys::isPopupMenu(), and isSelected().

## addToSelectionOnMouseUp()

template<class SelectableItemType>

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

inline

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

  item | the item to select (or deselect)
  modifiers | the modifiers from the mouse-up event
  wasItemDragged | true if your item was dragged during the mouse click
  resultOfMouseDownSelectMethod | this is the boolean return value that came back from the addToSelectionOnMouseDown() call that you should have made during the matching mouseDown event

References addToSelectionBasedOnModifiers().

## deselect()

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::deselect | ( | ParameterType | item | ) |

inline

Deselects an item.

References changed(), and itemDeselected().

Referenced by addToSelectionBasedOnModifiers(), and selectOnly().

## deselectAll()

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::deselectAll | ( |  | ) |

inline

Deselects all items.

References changed(), itemDeselected(), and juce::jmin().

Referenced by selectOnly().

## getNumSelected()

template<class SelectableItemType>

int juce::SelectedItemSet< SelectableItemType >::getNumSelected | ( |  | ) | const

inline noexcept

Returns the number of currently selected items.

See also
  getSelectedItem

## getSelectedItem()

template<class SelectableItemType>

SelectableItemType juce::SelectedItemSet< SelectableItemType >::getSelectedItem | ( | const int | index | ) | const

inline

Returns one of the currently selected items.

If the index is out-of-range, this returns a default-constructed SelectableItemType.

See also
  getNumSelected

## isSelected()

template<class SelectableItemType>

bool juce::SelectedItemSet< SelectableItemType >::isSelected | ( | ParameterType | item | ) | const

inline noexcept

True if this item is currently selected.

Referenced by addToSelection(), addToSelectionBasedOnModifiers(), addToSelectionOnMouseDown(), operator=(), and selectOnly().

## getItemArray()

template<class SelectableItemType>

const ItemArray & juce::SelectedItemSet< SelectableItemType >::getItemArray | ( |  | ) | const

inline noexcept

Provides access to the array of items.

## begin() [1/2]

template<class SelectableItemType>

SelectableItemType * juce::SelectedItemSet< SelectableItemType >::begin | ( |  | ) |

inline noexcept

Provides iterator access to the array of items.

## begin() [2/2]

template<class SelectableItemType>

const SelectableItemType * juce::SelectedItemSet< SelectableItemType >::begin | ( |  | ) | const

inline noexcept

## end() [1/2]

template<class SelectableItemType>

SelectableItemType * juce::SelectedItemSet< SelectableItemType >::end | ( |  | ) |

inline noexcept

Provides iterator access to the array of items.

## end() [2/2]

template<class SelectableItemType>

const SelectableItemType * juce::SelectedItemSet< SelectableItemType >::end | ( |  | ) | const

inline noexcept

Provides iterator access to the array of items.

## itemSelected()

template<class SelectableItemType>

virtual void juce::SelectedItemSet< SelectableItemType >::itemSelected | ( | SelectableItemType |  | ) |

inline 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.

Referenced by addToSelection(), operator=(), and selectOnly().

## itemDeselected()

template<class SelectableItemType>

virtual void juce::SelectedItemSet< SelectableItemType >::itemDeselected | ( | SelectableItemType |  | ) |

inline 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.

Referenced by deselect(), deselectAll(), and operator=().

## changed() [1/2]

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::changed | ( |  | ) |

inline

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

References juce::ChangeBroadcaster::sendChangeMessage().

Referenced by addToSelection(), deselect(), deselectAll(), operator=(), and selectOnly().

## changed() [2/2]

template<class SelectableItemType>

void juce::SelectedItemSet< SelectableItemType >::changed | ( | const bool | synchronous | ) |

inline

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

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

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited