![]() |
Carousel
|
The ObservableList class is a template class that provides observable lists. More...
#include <ObservableList.h>
Classes | |
class | const_iterator |
Public Member Functions | |
void | append (const TItem &item) |
void | append (const QList< TItem > &items) |
const TItem & | at (int index) const |
const TItem & | back () const |
QList< TItem >::const_iterator | begin () const |
void | clear () |
QList< TItem >::const_iterator | constBegin () const |
QList< TItem >::const_iterator | constEnd () const |
bool | contains (const TItem &item) const |
int | count () const |
int | count (const TItem &item) const |
bool | empty () const |
QList< TItem >::const_iterator | end () const |
TItem | first () |
const TItem & | first () const |
const TItem & | front () const |
int | indexOf (const TItem &item, int from=0) const |
void | installObserver (IListObserver< TItem > *observer) const |
bool | isEmpty () const |
TItem | last () |
const TItem & | last () const |
int | lastIndexOf (const TItem &item, int from=-1) const |
const TItem & | operator[] (int index) const |
TItem | operator[] (int index) |
void | prepend (const TItem &item) |
void | push_back (const TItem &item) |
void | push_front (const TItem &item) |
int | removeAll (const TItem &item) |
void | removeAt (int index) |
bool | removeObserver (IListObserver< TItem > *observer) const |
bool | removeOne (const TItem &item) |
void | reserve (int size) |
int | size () const |
void | sort () |
template<template< typename > class LessThan> | |
void | sort (LessThan< TItem > &lessThan) |
QList< TItem > | toList () const |
The ObservableList class is a template class that provides observable lists.
ObservableList<TItem> extends Qt's generic container classes by adding observable availability. It stores a list of values and provides almost all functionality as well as QList<TItem> does.
Also it provides two methods for inistalling (installObserver()) and removing (removeObserver()) observers, which want to know about this list changed (items were added, removed, sorted, etc).
void ObservableList< TItem >::append | ( | const TItem & | item | ) |
Inserts item at the end of the list.
This is the same as list.insert(0, item). This operation is usually very fast (constant time), because list preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.
Notify observers with ChangedAction::Add action and added item.
void ObservableList< TItem >::append | ( | const QList< TItem > & | items | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Appends the items of the value list to this list.
void ObservableList< TItem >::prepend | ( | const TItem & | item | ) |
Inserts item at the beginning of the list.
This is the same as list.insert(0, item). This operation is usually very fast (constant time), because list preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.
Notify observers with ChangedAction::Add action and added item.
int ObservableList< TItem >::size | ( | ) | const |
Returns the number of items in the list.
bool ObservableList< TItem >::isEmpty | ( | ) | const |
Returns true if the list contains no items; otherwise returns false.
void ObservableList< TItem >::clear | ( | ) |
Removes all items from the list.
Notify observers with ChangedAction::Reset action and purged items.
const TItem & ObservableList< TItem >::at | ( | int | index | ) | const |
Returns the item at index position index as a modifiable reference. index must be a valid index position in the list (i.e., 0 <= index < size()).
This function is very fast (constant time).
const TItem & ObservableList< TItem >::operator[] | ( | int | index | ) | const |
Returns the item at index position index as a modifiable reference. index must be a valid index position in the list (i.e., 0 <= index < size()).
This function is very fast (constant time).
TItem ObservableList< TItem >::operator[] | ( | int | index | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Same as at().
void ObservableList< TItem >::reserve | ( | int | size | ) |
Reserve space for size elements.
If size is smaller than the current size of the list, nothing will happen.
Use this function to avoid repetetive reallocation of list's internal data if you can predict how many elements will be appended. Note that the reservation applies only to the internal pointer array.
void ObservableList< TItem >::removeAt | ( | int | index | ) |
Removes the item at index position index. index must be a valid index position in the list (i.e., 0 <= index < size()).
Notify observers with ChangedAction::Remove action and removed by specified index item.
int ObservableList< TItem >::removeAll | ( | const TItem & | item | ) |
Removes all occurrences of value in the list and returns the number of entries removed.
Notify observers with ChangedAction::Remove action and removed items.
bool ObservableList< TItem >::removeOne | ( | const TItem & | item | ) |
Removes the first occurrence of item in the list and returns true on success; otherwise returns false.
Notify observers with ChangedAction::Remove action and removed item.
int ObservableList< TItem >::indexOf | ( | const TItem & | item, |
int | from = 0 |
||
) | const |
Returns the index position of the first occurrence of item in the list, searching forward from index position from. Returns -1 if no item matched.
int ObservableList< TItem >::lastIndexOf | ( | const TItem & | item, |
int | from = -1 |
||
) | const |
Returns the index position of the last occurrence of item in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.
bool ObservableList< TItem >::contains | ( | const TItem & | item | ) | const |
Returns true if the list contains an occurrence of item; otherwise returns false.
This function requires the item type to have an implementation of operator==().
int ObservableList< TItem >::count | ( | ) | const |
Returns the number of items in the list. This is effectively the same as size().
int ObservableList< TItem >::count | ( | const TItem & | item | ) | const |
Returns the number of occurrences of item in the list.
This function requires the item type to have an implementation of operator==().
TItem ObservableList< TItem >::first | ( | ) |
Returns a reference to the first item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this function.
const TItem & ObservableList< TItem >::first | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
TItem ObservableList< TItem >::last | ( | ) |
Returns a reference to the last item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this function.
const TItem & ObservableList< TItem >::last | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
QList< TItem >::const_iterator ObservableList< TItem >::begin | ( | ) | const |
Returns a const STL-style iterator pointing to the first item in the list.
QList< TItem >::const_iterator ObservableList< TItem >::constBegin | ( | ) | const |
Returns a const STL-style iterator pointing to the first item in the list.
QList< TItem >::const_iterator ObservableList< TItem >::end | ( | ) | const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
QList< TItem >::const_iterator ObservableList< TItem >::constEnd | ( | ) | const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.
void ObservableList< TItem >::push_back | ( | const TItem & | item | ) |
This function is provided for STL compatibility. It is equivalent to append(item).
Notify observers with ChangedAction::Add action and added item.
void ObservableList< TItem >::push_front | ( | const TItem & | item | ) |
This function is provided for STL compatibility. It is equivalent to prepend(item).
Notify observers with ChangedAction::Add action and added item.
const TItem & ObservableList< TItem >::front | ( | ) | const |
const TItem & ObservableList< TItem >::back | ( | ) | const |
bool ObservableList< TItem >::empty | ( | ) | const |
This function is provided for STL compatibility. It is equivalent to isEmpty() and returns true if the list is empty.
QList< TItem > ObservableList< TItem >::toList | ( | ) | const |
Returns list representation.
void ObservableList< TItem >::sort | ( | ) |
Sorts the items in ascending order using the the QtAlgorithms' qSort() method.
Notify observers with ChangedAction::Reset action and all items.
void ObservableList< TItem >::sort | ( | LessThan< TItem > & | lessThan | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Uses the lessThan function instead of operator<() to compare the items.