36 #include "../listener.h"
56 _first(first), _last(last), _selected(selected), _final(
final) {}
72 unsigned int first()
const {
return _first;}
77 void first(
unsigned int value) {_first = value;}
82 unsigned int last()
const {
return _last;}
87 void last(
unsigned int value) {_last = value;}
117 bool final()
const {
return _final;}
122 void final(
bool value) {_final = value;}
148 std::vector<SelectionListener *> _listeners;
172 enum Type {NONE, SINGLE, MULTIPLE};
189 virtual bool selected(
unsigned int index)
const = 0;
197 virtual unsigned int first()
const = 0;
201 virtual unsigned int last()
const = 0;
206 virtual bool empty()
const = 0;
214 virtual unsigned int count()
const = 0;
219 virtual bool any()
const = 0;
224 virtual bool one()
const = 0;
229 virtual bool many()
const = 0;
238 virtual void inserted(
unsigned int index,
unsigned int count) = 0;
247 virtual void removed(
unsigned int index,
unsigned int count) = 0;
252 virtual void clear() = 0;
261 virtual void set(
unsigned int index) = 0;
268 virtual void select(
unsigned int index) = 0;
275 virtual void deselect(
unsigned int index) = 0;
282 virtual void toggle(
unsigned int index) = 0;
293 virtual void set(
unsigned int from,
unsigned int to) = 0;
301 virtual void select(
unsigned int from,
unsigned int to) = 0;
309 virtual void deselect(
unsigned int from,
unsigned int to) = 0;
317 virtual void toggle(
unsigned int from,
unsigned int to) = 0;
326 unsigned int _refcount;
344 void release() {
if (--_refcount == 0)
delete this;}
351 bool shared()
const {
return _refcount > 1;}
365 virtual unsigned int index()
const = 0;
370 virtual void next() = 0;
414 unsigned int _selected;
429 virtual bool selected(
unsigned int index)
const {
return _selected == index;}
436 virtual unsigned int first()
const {
return _selected;}
440 virtual unsigned int last()
const {
return _selected;}
465 virtual bool many()
const {
return false;}
468 virtual void inserted(
unsigned int index,
unsigned int count);
469 virtual void removed(
unsigned int index,
unsigned int count);
472 virtual void clear();
473 virtual void set(
unsigned int index);
474 virtual void select(
unsigned int index);
475 virtual void deselect(
unsigned int index);
476 virtual void toggle(
unsigned int index);
477 virtual void set(
unsigned int from,
unsigned int to);
478 virtual void select(
unsigned int from,
unsigned int to);
479 virtual void deselect(
unsigned int from,
unsigned int to);
480 virtual void toggle(
unsigned int from,
unsigned int to);
501 virtual IteratorImpl *
clone() {add_ref();
return this;}
507 virtual unsigned int index()
const {
return _index;}
524 typedef std::pair<unsigned int, unsigned int> Range;
527 std::vector<Range> _selected;
528 typedef std::vector<Range>::iterator RangeIterator;
529 typedef std::vector<Range>::const_iterator ConstRangeIterator;
544 virtual bool selected(
unsigned int index)
const;
551 virtual unsigned int first()
const {
return _first;}
555 virtual unsigned int last()
const {
return _last;}
565 virtual unsigned int count()
const;
583 virtual void inserted(
unsigned int index,
unsigned int count);
584 virtual void removed(
unsigned int index,
unsigned int count);
587 virtual void clear();
588 virtual void set(
unsigned int index);
589 virtual void select(
unsigned int index);
590 virtual void deselect(
unsigned int index);
591 virtual void toggle(
unsigned int index);
592 virtual void set(
unsigned int from,
unsigned int to);
593 virtual void select(
unsigned int from,
unsigned int to);
594 virtual void deselect(
unsigned int from,
unsigned int to);
595 virtual void toggle(
unsigned int from,
unsigned int to);
603 ConstRangeIterator _current;
604 ConstRangeIterator _end;
612 virtual unsigned int index()
const {
return _index;}
620 RangeIterator find_last_ge(
unsigned int index);
621 void fire_changes(std::vector<SelectionChangedEvent> &changes);
virtual IteratorImpl * clone()=0
Override this method to return a copy of the iterator implementation.
virtual IteratorImpl * clone()
Make a copy of the current iterator.
Definition: selection.cc:1043
SelectionChangedEvent(unsigned int first, unsigned int last, bool selected, bool final=true)
Construct a selection changed event.
Definition: selection.h:55
Iterator & operator++()
Prefix operator.
Definition: selection.cc:173
virtual void clear()
Clear the selection.
Definition: selection.cc:509
virtual void removed(unsigned int index, unsigned int count)
Called by the object selection is on when items have been removed and selected item to be deleted or ...
Definition: selection.cc:224
virtual bool selected(unsigned int index) const =0
Override to return true if an item is selected.
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:560
virtual IteratorImpl * clone()
Get copy of this iterator implentation.
Definition: selection.h:501
virtual unsigned int count() const
Return the number of selected items.
Definition: selection.h:450
IteratorImpl()
Construct iterator implementation.
Definition: selection.h:331
virtual unsigned int count() const
Return the number of selected items.
Definition: selection.cc:428
Class derived to implement iterator.
Definition: selection.h:601
unsigned int first() const
Returns the first selected/deselected item in the range.
Definition: selection.h:72
SingleIteratorImpl(unsigned int index)
Construct iterator for item with given index.
Definition: selection.h:495
virtual void select(unsigned int index)
Select an item.
Definition: selection.cc:259
void add_listener(SelectionListener *listener)
Add listeners.
Definition: selection.cc:72
unsigned int operator*() const
Get index for iterator.
Definition: selection.cc:165
bool operator==(const Iterator &other) const
Compare two iterators.
Definition: selection.cc:144
Class derived from in subclasses to actually provided the iterator implementation.
Definition: selection.h:324
Selection()
Protected constructor, must always use a subclass.
Definition: selection.h:154
virtual void deselect(unsigned int index)
Remove selection from given index.
Definition: selection.cc:650
void release()
Decrease reference count and delete this if reference count becomes zero.
Definition: selection.h:344
Iterator & operator=(const Iterator &other)
Assignment.
Definition: selection.cc:130
virtual bool empty() const
Returns true if selection is empty.
Definition: selection.h:445
virtual bool one() const =0
Override to return true if only one item is selected.
void add_ref()
Increase reference count.
Definition: selection.h:339
void first(unsigned int value)
Set first selected.
Definition: selection.h:77
virtual bool many() const
Always returns false.
Definition: selection.h:465
Class to implement multiple selections.
Definition: selection.h:522
void remove_listener(SelectionListener *listener)
Remove listener for selection changes.
Definition: selection.cc:80
virtual unsigned int first() const =0
Override to return first selected item.
virtual bool empty() const =0
Override to return true if selection is empty.
virtual void next()
Advance iterator.
Definition: selection.cc:1053
virtual IteratorImpl * get_iterator_impl() const =0
Override to return the iterator implementation for the selection iterator to used.
virtual void toggle(unsigned int index)
Toggle the selected index.
Definition: selection.cc:690
void fire_event(const SelectionChangedEvent &event)
Helper for subclasses to fire Selection Changed Events.
Definition: selection.cc:44
virtual void clear()=0
Override to clear the current selection.
bool shared() const
Check if the iterator implementation is being shared between two or more iterators.
Definition: selection.h:351
virtual IteratorImpl * get_iterator_impl() const
Override to return the iterator implementation for the selection iterator to used.
Definition: selection.h:515
virtual bool one() const
Returns true if only one item is selected.
Definition: selection.h:460
SelectionChangedEvent()
Default constructor creates a selection of item 0.
Definition: selection.h:60
Class with the details of a select, deselect or toggle operation.
Definition: selection.h:44
virtual unsigned int first() const
Returns first selected item.
Definition: selection.h:436
virtual void inserted(unsigned int index, unsigned int count)
Called by the object selection is on when new items have been inserted and selected item need to be m...
Definition: selection.cc:209
virtual IteratorImpl * get_iterator_impl() const
Get initial iterator implementation.
Definition: selection.cc:1071
virtual void deselect(unsigned int index)=0
Override to clear the selection for an item.
virtual void set(unsigned int index)
Select an item.
Definition: selection.cc:271
Iterator begin() const
Get iterator to first selected item.
Definition: selection.cc:95
virtual bool selected(unsigned int index) const
Returns true if an item is selected.
Definition: selection.h:429
virtual void set(unsigned int index)
Modifiy the selection so it only consist of the given index.
Definition: selection.cc:535
virtual void next()=0
Override this method to advance the iterator to the next item.
virtual bool any() const =0
Override to return true if one or more items are selected.
virtual unsigned int last() const =0
Override to return last selected item.
static const unsigned int NO_SELECTION
Constant for indices when there is no selection.
Definition: selection.h:177
bool operator!=(const Iterator &other) const
Compare two iterators.
Definition: selection.cc:154
virtual unsigned int index() const =0
Override this to get the current index.
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:422
virtual bool selected(unsigned int index) const
Returns true if an item is selected.
Definition: selection.cc:411
void selected(bool value)
Set selected flag.
Definition: selection.h:101
Type
Type of selection.
Definition: selection.h:172
virtual void next()
Advance iterator.
Definition: selection.h:513
Class to iterate through all the selected indices.
Definition: selection.h:384
bool selected() const
Returns the type of the event.
Definition: selection.h:96
virtual unsigned int count() const =0
Override to return the number of selected items.
virtual Type type() const =0
Override to return the type of this selection class.
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:455
virtual void toggle(unsigned int index)=0
Override to toggle the selection for an item.
virtual void set(unsigned int index)=0
Override to change selection to given item.
virtual unsigned int first() const
Returns first selected item.
Definition: selection.h:551
virtual void deselect(unsigned int index)
Clear the selection for an item.
Definition: selection.cc:293
MultiIteratorImpl(ConstRangeIterator start, ConstRangeIterator end)
Construct iterator implementation from iterators.
Definition: selection.cc:1032
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 ne...
Base class for all toolbox event listeners.
Definition: listener.h:33
Class to represent a single selection.
Definition: selection.h:411
Class derived to implement iterator.
Definition: selection.h:486
virtual unsigned int index() const
Override this to get the current index.
Definition: selection.h:612
virtual void inserted(unsigned int index, unsigned int count)
Data has been inserted so adjust selection.
Definition: selection.cc:443
Listener for selection changed events.
Definition: selection.h:129
virtual bool any() const
Returns true if one or more items are selected.
Definition: selection.h:570
virtual bool many() const
Returns true if there are more than one item selected.
Definition: selection.h:580
void last(unsigned int value)
Set last selected.
Definition: selection.h:87
virtual ~IteratorImpl()
Destructor does nothing.
Definition: selection.h:335
virtual void select(unsigned int index)
Add the index to the selection.
Definition: selection.cc:584
virtual void clear()
Clear the current selection.
Definition: selection.cc:241
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:440
virtual void toggle(unsigned int index)
Toggle the selection for an item.
Definition: selection.cc:307
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 d...
virtual bool many() const =0
Override to return true if more than one item is selected.
virtual void selection_changed(const SelectionChangedEvent &event)=0
Called whenever the selection has been changed.
virtual unsigned int index() const
Get the current index.
Definition: selection.h:507
virtual Type type() const
Returns the type of this selection class.
Definition: selection.h:537
virtual bool one() const
Returns true if only one item is selected.
Definition: selection.h:575
unsigned int last() const
Returns the last selected/deselected item in the range.
Definition: selection.h:82
Base class for selections of one or more indices from a zero based range.
Definition: selection.h:145
bool final() const
Returns true if this is the last event in a group of events triggered by a single action...
Definition: selection.h:117
virtual unsigned int last() const
Returns last selected item.
Definition: selection.h:555
virtual void select(unsigned int index)=0
Override to select an item.
virtual void removed(unsigned int index, unsigned int count)
Data has been removed so adjust selection.
Definition: selection.cc:471
Iterator end() const
Get iterator to end of selection.
Definition: selection.cc:105