Manages a list of selectable items. More...
#include <juce_SelectedItemSet.h>
Public Types | |
using | ItemArray = Array< SelectableItemType > |
using | ItemType = SelectableItemType |
using | ParameterType = typename TypeHelpers::ParameterType< SelectableItemType >::type |
Public Member Functions | |
SelectedItemSet ()=default | |
Creates an empty set. More... | |
SelectedItemSet (const ItemArray &items) | |
Creates a set based on an array of items. More... | |
SelectedItemSet (const SelectedItemSet &other) | |
Creates a copy of another set. More... | |
void | addChangeListener (ChangeListener *listener) |
Registers a listener to receive change callbacks from this broadcaster. More... | |
void | addToSelection (ParameterType item) |
Selects an item. More... | |
void | addToSelectionBasedOnModifiers (ParameterType item, ModifierKeys modifiers) |
Selects or deselects an item. More... | |
bool | addToSelectionOnMouseDown (ParameterType item, ModifierKeys modifiers) |
Selects or deselects items that can also be dragged, based on a mouse-down event. More... | |
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. More... | |
SelectableItemType * | begin () const noexcept |
Provides iterator access to the array of items. More... | |
void | changed () |
Used internally, but can be called to force a change message to be sent to the ChangeListeners. More... | |
void | changed (const bool synchronous) |
Used internally, but can be called to force a change message to be sent to the ChangeListeners. More... | |
void | deselect (ParameterType item) |
Deselects an item. More... | |
void | deselectAll () |
Deselects all items. More... | |
void | dispatchPendingMessages () |
If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately. More... | |
SelectableItemType * | end () const noexcept |
Provides iterator access to the array of items. More... | |
const ItemArray & | getItemArray () const noexcept |
Provides access to the array of items. More... | |
int | getNumSelected () const noexcept |
Returns the number of currently selected items. More... | |
SelectableItemType | getSelectedItem (const int index) const |
Returns one of the currently selected items. More... | |
bool | isSelected (ParameterType item) const noexcept |
True if this item is currently selected. More... | |
virtual void | itemDeselected (SelectableItemType) |
Can be overridden to do special handling when an item is deselected. More... | |
virtual void | itemSelected (SelectableItemType) |
Can be overridden to do special handling when an item is selected. More... | |
SelectedItemSet & | operator= (const SelectedItemSet &other) |
Creates a copy of another set. More... | |
void | removeAllChangeListeners () |
Removes all listeners from the list. More... | |
void | removeChangeListener (ChangeListener *listener) |
Unregisters a listener from the list. More... | |
void | selectOnly (ParameterType item) |
Clears any other currently selected items, and selects this item. More... | |
void | sendChangeMessage () |
Causes an asynchronous change message to be sent to all the registered listeners. More... | |
void | sendSynchronousChangeMessage () |
Sends a synchronous change message to all the registered listeners. More... | |
Private Attributes | |
ItemArray | selectedItems |
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.
{GUI}
using juce::SelectedItemSet< SelectableItemType >::ItemArray = Array<SelectableItemType> |
using juce::SelectedItemSet< SelectableItemType >::ItemType = SelectableItemType |
using juce::SelectedItemSet< SelectableItemType >::ParameterType = typename TypeHelpers::ParameterType<SelectableItemType>::type |
|
default |
Creates an empty set.
|
inlineexplicit |
Creates a set based on an array of items.
|
inline |
Creates a copy of another set.
|
inherited |
Registers a listener to receive change callbacks from this broadcaster.
Trying to add a listener that's already on the list will have no effect.
|
inline |
Selects an item.
If the item is already selected, no change notification will be sent out.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::add(), juce::SelectedItemSet< SelectableItemType >::changed(), juce::SelectedItemSet< SelectableItemType >::isSelected(), juce::SelectedItemSet< SelectableItemType >::itemSelected(), and juce::SelectedItemSet< SelectableItemType >::selectedItems.
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers().
|
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.
References juce::SelectedItemSet< SelectableItemType >::addToSelection(), juce::SelectedItemSet< SelectableItemType >::deselect(), juce::ModifierKeys::isCommandDown(), juce::SelectedItemSet< SelectableItemType >::isSelected(), juce::ModifierKeys::isShiftDown(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionOnMouseDown(), and juce::SelectedItemSet< SelectableItemType >::addToSelectionOnMouseUp().
|
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.
References juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers(), juce::ModifierKeys::isPopupMenu(), and juce::SelectedItemSet< SelectableItemType >::isSelected().
|
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
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 juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers().
|
inlinenoexcept |
Provides iterator access to the array of items.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::begin(), and juce::SelectedItemSet< SelectableItemType >::selectedItems.
|
inline |
Used internally, but can be called to force a change message to be sent to the ChangeListeners.
References juce::ChangeBroadcaster::sendChangeMessage().
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelection(), juce::SelectedItemSet< SelectableItemType >::deselect(), juce::SelectedItemSet< SelectableItemType >::deselectAll(), juce::SelectedItemSet< SelectableItemType >::operator=(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().
|
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().
|
inline |
Deselects an item.
References juce::SelectedItemSet< SelectableItemType >::changed(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::indexOf(), juce::SelectedItemSet< SelectableItemType >::itemDeselected(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeAndReturn(), and juce::SelectedItemSet< SelectableItemType >::selectedItems.
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().
|
inline |
Deselects all items.
References juce::SelectedItemSet< SelectableItemType >::changed(), juce::SelectedItemSet< SelectableItemType >::itemDeselected(), juce::jmin(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeAndReturn(), juce::SelectedItemSet< SelectableItemType >::selectedItems, and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::size().
Referenced by juce::SelectedItemSet< SelectableItemType >::selectOnly().
|
inherited |
If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately.
For thread-safety reasons, you must only call this method on the main message thread.
|
inlinenoexcept |
Provides iterator access to the array of items.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::end(), and juce::SelectedItemSet< SelectableItemType >::selectedItems.
|
inlinenoexcept |
Provides access to the array of items.
References juce::SelectedItemSet< SelectableItemType >::selectedItems.
|
inlinenoexcept |
Returns the number of currently selected items.
References juce::SelectedItemSet< SelectableItemType >::selectedItems, and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::size().
|
inline |
Returns one of the currently selected items.
If the index is out-of-range, this returns a default-constructed SelectableItemType.
References juce::SelectedItemSet< SelectableItemType >::selectedItems.
|
inlinenoexcept |
True if this item is currently selected.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::contains(), and juce::SelectedItemSet< SelectableItemType >::selectedItems.
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelection(), juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers(), juce::SelectedItemSet< SelectableItemType >::addToSelectionOnMouseDown(), juce::SelectedItemSet< SelectableItemType >::operator=(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().
|
inlinevirtual |
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 juce::SelectedItemSet< SelectableItemType >::deselect(), juce::SelectedItemSet< SelectableItemType >::deselectAll(), and juce::SelectedItemSet< SelectableItemType >::operator=().
|
inlinevirtual |
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 juce::SelectedItemSet< SelectableItemType >::addToSelection(), juce::SelectedItemSet< SelectableItemType >::operator=(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().
|
inline |
Creates a copy of another set.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::add(), juce::SelectedItemSet< SelectableItemType >::changed(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getReference(), juce::SelectedItemSet< SelectableItemType >::isSelected(), juce::SelectedItemSet< SelectableItemType >::itemDeselected(), juce::SelectedItemSet< SelectableItemType >::itemSelected(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeAndReturn(), juce::SelectedItemSet< SelectableItemType >::selectedItems, and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::size().
|
inherited |
Removes all listeners from the list.
|
inherited |
Unregisters a listener from the list.
If the listener isn't on the list, this won't have any effect.
|
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.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::add(), juce::SelectedItemSet< SelectableItemType >::changed(), juce::SelectedItemSet< SelectableItemType >::deselect(), juce::SelectedItemSet< SelectableItemType >::deselectAll(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getUnchecked(), juce::SelectedItemSet< SelectableItemType >::isSelected(), juce::SelectedItemSet< SelectableItemType >::itemSelected(), juce::jmin(), juce::SelectedItemSet< SelectableItemType >::selectedItems, and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::size().
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelectionBasedOnModifiers().
|
inherited |
Causes an asynchronous change message to be sent to all the registered listeners.
The message will be delivered asynchronously by the main message thread, so this method will return immediately. To call the listeners synchronously use sendSynchronousChangeMessage().
Referenced by juce::SelectedItemSet< SelectableItemType >::changed().
|
inherited |
Sends a synchronous change message to all the registered listeners.
This will immediately call all the listeners that are registered. For thread-safety reasons, you must only call this method on the main message thread.
Referenced by juce::SelectedItemSet< SelectableItemType >::changed().
|
private |
Referenced by juce::SelectedItemSet< SelectableItemType >::addToSelection(), juce::SelectedItemSet< SelectableItemType >::begin(), juce::SelectedItemSet< SelectableItemType >::deselect(), juce::SelectedItemSet< SelectableItemType >::deselectAll(), juce::SelectedItemSet< SelectableItemType >::end(), juce::SelectedItemSet< SelectableItemType >::getItemArray(), juce::SelectedItemSet< SelectableItemType >::getNumSelected(), juce::SelectedItemSet< SelectableItemType >::getSelectedItem(), juce::SelectedItemSet< SelectableItemType >::isSelected(), juce::SelectedItemSet< SelectableItemType >::operator=(), and juce::SelectedItemSet< SelectableItemType >::selectOnly().