tbx  0.7.6
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
tbx::view::Selection Class Referenceabstract

Base class for selections of one or more indices from a zero based range. More...

#include <selection.h>

Inheritance diagram for tbx::view::Selection:
tbx::view::MultiSelection tbx::view::SingleSelection

Classes

class  Iterator
 Class to iterate through all the selected indices. More...
 
class  IteratorImpl
 Class derived from in subclasses to actually provided the iterator implementation. More...
 

Public Types

enum  Type { NONE, SINGLE, MULTIPLE }
 Type of selection.
 

Public Member Functions

void add_listener (SelectionListener *listener)
 Add listeners. More...
 
void remove_listener (SelectionListener *listener)
 Remove listener for selection changes.
 
virtual Type type () const =0
 Override to return the type of this selection class.
 
virtual bool selected (unsigned int index) const =0
 Override to return true if an item is selected. More...
 
virtual unsigned int first () const =0
 Override to return first selected item. More...
 
virtual unsigned int last () const =0
 Override to return last selected item.
 
virtual bool empty () const =0
 Override to return true if selection is empty.
 
virtual unsigned int count () const =0
 Override to return the number of selected items. More...
 
virtual bool any () const =0
 Override to return true if one or more items are selected.
 
virtual bool one () const =0
 Override to return true if only one item is selected.
 
virtual bool many () const =0
 Override to return true if more than one item is selected.
 
virtual void inserted (unsigned int index, unsigned int count)=0
 Override called by the object selection is on when new items have been inserted and selected items need to be moved. More...
 
virtual void removed (unsigned int index, unsigned int count)=0
 Override called by the object selection is on when items have been removed and selected items to be deleted or moved. More...
 
virtual void clear ()=0
 Override to clear the current selection.
 
virtual void set (unsigned int index)=0
 Override to change selection to given item. More...
 
virtual void select (unsigned int index)=0
 Override to select an item. More...
 
virtual void deselect (unsigned int index)=0
 Override to clear the selection for an item. More...
 
virtual void toggle (unsigned int index)=0
 Override to toggle the selection for an item. More...
 
virtual void set (unsigned int from, unsigned int to)=0
 Override to change selection to given item. More...
 
virtual void select (unsigned int from, unsigned int to)=0
 Override to selection a range of items. More...
 
virtual void deselect (unsigned int from, unsigned int to)=0
 Override to deselect a range of items. More...
 
virtual void toggle (unsigned int from, unsigned int to)=0
 Override to toggle the selection of a range of items. More...
 
Iterator begin () const
 Get iterator to first selected item. More...
 
Iterator end () const
 Get iterator to end of selection. More...
 

Static Public Attributes

static const unsigned int NO_SELECTION = -1
 Constant for indices when there is no selection.
 

Protected Member Functions

 Selection ()
 Protected constructor, must always use a subclass.
 
void fire_event (const SelectionChangedEvent &event)
 Helper for subclasses to fire Selection Changed Events.
 
void fire_event (unsigned int index, bool selected, bool final)
 Helper for subclasses to fire Selection Changed Events.
 
void fire_event (unsigned int from, unsigned int to, bool selected, bool final)
 Helper for subclasses to fire Selection Changed Events.
 
virtual IteratorImplget_iterator_impl () const =0
 Override to return the iterator implementation for the selection iterator to used. More...
 

Detailed Description

Base class for selections of one or more indices from a zero based range.

Member Function Documentation

◆ add_listener()

void tbx::view::Selection::add_listener ( SelectionListener listener)

Add listeners.

Add listener for selection changes.

◆ begin()

Selection::Iterator tbx::view::Selection::begin ( ) const

Get iterator to first selected item.

Returns
iterator to first selected item or end() if none.

◆ count()

virtual unsigned int tbx::view::Selection::count ( ) const
pure virtual

Override to return the number of selected items.

Note: If the exact number is not needed it is usually quicker to use empty(), any(), one() or many(),

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ deselect() [1/2]

virtual void tbx::view::Selection::deselect ( unsigned int  from,
unsigned int  to 
)
pure virtual

Override to deselect a range of items.

Parameters
fromfirst index to deselect
tolast index to deselect

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ deselect() [2/2]

virtual void tbx::view::Selection::deselect ( unsigned int  index)
pure virtual

Override to clear the selection for an item.

Parameters
indexto deselect

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ end()

Selection::Iterator tbx::view::Selection::end ( ) const

Get iterator to end of selection.

Returns
iterator to item after last item in the selection.

◆ first()

virtual unsigned int tbx::view::Selection::first ( ) const
pure virtual

Override to return first selected item.

Note not all items between the first and last are necessarily selected.

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ get_iterator_impl()

virtual IteratorImpl* tbx::view::Selection::get_iterator_impl ( ) const
protectedpure virtual

Override to return the iterator implementation for the selection iterator to used.

Returns
Iterator implementation for this selection type.

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ inserted()

virtual void tbx::view::Selection::inserted ( unsigned int  index,
unsigned int  count 
)
pure virtual

Override called by the object selection is on when new items have been inserted and selected items need to be moved.

Parameters
indexof the insertion
countof items inserted

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ removed()

virtual void tbx::view::Selection::removed ( unsigned int  index,
unsigned int  count 
)
pure virtual

Override called by the object selection is on when items have been removed and selected items to be deleted or moved.

Parameters
indexof the insertion
countof items inserted

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ select() [1/2]

virtual void tbx::view::Selection::select ( unsigned int  from,
unsigned int  to 
)
pure virtual

Override to selection a range of items.

Parameters
fromfirst index to select
tolast index to select

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ select() [2/2]

virtual void tbx::view::Selection::select ( unsigned int  index)
pure virtual

Override to select an item.

Parameters
indexto select

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ selected()

virtual bool tbx::view::Selection::selected ( unsigned int  index) const
pure virtual

Override to return true if an item is selected.

Parameters
indexof item to text

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ set() [1/2]

virtual void tbx::view::Selection::set ( unsigned int  from,
unsigned int  to 
)
pure virtual

Override to change selection to given item.

This will automatically deselect any existing selection outside the range

Parameters
fromfirst index to select
tolast index to select

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ set() [2/2]

virtual void tbx::view::Selection::set ( unsigned int  index)
pure virtual

Override to change selection to given item.

This will automatically deselect any existing selection

Parameters
indexto select

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ toggle() [1/2]

virtual void tbx::view::Selection::toggle ( unsigned int  from,
unsigned int  to 
)
pure virtual

Override to toggle the selection of a range of items.

Parameters
fromfirst index to toggle
tolast index to toggle

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.

◆ toggle() [2/2]

virtual void tbx::view::Selection::toggle ( unsigned int  index)
pure virtual

Override to toggle the selection for an item.

Parameters
indexto toggle

Implemented in tbx::view::MultiSelection, and tbx::view::SingleSelection.


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