This class manages a list of live QObject
pointers.
More...
#include <GCF3/ObjectList>
Public Member Functions | |
ObjectList () | |
ObjectList (QObject *obj) | |
ObjectList (const QObjectList &objects) | |
ObjectList (const ObjectList &other) | |
~ObjectList () | |
void | add (QObject *obj) |
void | insert (int index, QObject *obj) |
void | remove (QObject *obj) |
void | removeAt (int index) |
void | add (const ObjectList &list) |
void | insert (int index, const QObjectList &list) |
void | remove (const ObjectList &list) |
int | count () const |
QObject * | at (int index) const |
QObject * | first () const |
QObject * | last () const |
int | indexOf (QObject *obj) const |
const QObjectList & | toList () const |
void | removeAll () |
void | deleteAll () |
void | setEventListener (GCF::ObjectListEventListener *listener) |
GCF::ObjectListEventListener * | eventListener () const |
ObjectList & | operator= (const ObjectList &other) |
QObject * | operator[] (int index) const |
ObjectList & | operator+= (QObject *obj) |
ObjectList & | operator-= (QObject *obj) |
ObjectList | operator+ (QObject *obj) |
ObjectList | operator- (QObject *obj) |
ObjectList & | operator+= (const ObjectList &list) |
ObjectList & | operator-= (const ObjectList &list) |
ObjectList | operator+ (const ObjectList &list) |
ObjectList | operator- (const ObjectList &list) |
Detailed Description
This class can be used as a replacement for QList<QObject*>
, when you want only valid pointers to QObject
to be stored in the list. This class automatically notifies and removes invalid QObject
pointers, as and when the objects that the pointers point to are deleted elsewhere in the application.
Three types of events can happen on GCF::ObjectList
- A
QObject
pointer got added to the list - A
QObject
pointer got removed from the list - A
QObject
, whose pointer is in the list, got deleted
You can listen to these events by implementing GCF::ObjectListEventListener and setting pointer to an instance of that using the setEventListener() function.
If you want to have several listeners receive event notifications on an object list, then you can install a GCF::ObjectListEventBroadcaster on the object list and register all event listeners with the broadcaster.
Alternatively, you can install a GCF::ObjectListWatcher as event listener on the object list and connect to event-signals in the watcher.
Instances of this class are shallow-copyable. This means a reference counter is used to manage copies of this class. While modifications trigger a deep-copy+modify, access functions work on a shared data.
Constructor & Destructor Documentation
GCF::ObjectList::ObjectList | ( | ) |
Default constructor.
|
explicit |
Constructs an object list with obj
and adds the obj
to list.
- Parameters
-
obj QObject
pointer that needs to be added to this list
|
explicit |
Constructs an object list and adds QObject
pointers in objects
to it.
- Parameters
-
objects QObjectList
that will be added to this list
GCF::ObjectList::ObjectList | ( | const ObjectList & | other | ) |
Copy constructor.
- Parameters
-
other the other GCF::ObjectList object from which information is copied.
GCF::ObjectList::~ObjectList | ( | ) |
Destructor.
- Note
- Does not delete objects stored inside the list.
Member Function Documentation
void GCF::ObjectList::add | ( | QObject * | obj | ) |
Adds QObject
pointer to this list.
- Parameters
-
obj QObject
pointer that needs to be added to this list
- Note
- the GCF::ObjectListEventListener::objectAdded() method will be called to notify the addition.
void GCF::ObjectList::insert | ( | int | index, |
QObject * | obj | ||
) |
Inserts a pointer to QObject
at a specific index.
- Parameters
-
obj pointer to QObject
that will be inserted into the listindex index at which the pointer will be inserted.
void GCF::ObjectList::remove | ( | QObject * | obj | ) |
Removes the QObject
pointer obj from the list.
- Parameters
-
obj pointer to QObject
that will be removed from the list.
void GCF::ObjectList::removeAt | ( | int | index | ) |
Removes the QObject
pointer at the specified index from the list.
- Parameters
-
index index from which the QObject
pointer will be removed.
void GCF::ObjectList::add | ( | const ObjectList & | list | ) |
Appends QObject
pointers inside GCF::ObjectList list
to the current list.
- Parameters
-
list GCF::ObjectList from which the objects will be added to this.
void GCF::ObjectList::insert | ( | int | index, |
const QObjectList & | list | ||
) |
Inserts QObject
pointers from other GCF::ObjectList 'list' to current list, starting from the specified index.
- Parameters
-
list ObjectList from which the objects will be inserted.
void GCF::ObjectList::remove | ( | const ObjectList & | list | ) |
Removes the QObject
pointers from the current list which are present in other ObjectList
list
.
- Parameters
-
list list of QObject
pointers that needs to be removed.
int GCF::ObjectList::count | ( | ) | const |
Returns the object count of this.
- Returns
- object count of this.
QObject * GCF::ObjectList::at | ( | int | index | ) | const |
Returns the QObject
pointer at the index.
- Parameters
-
index index of QObject
pointer which needs to be returned.
- Returns
- the
QObject
pointer at index.
QObject * GCF::ObjectList::first | ( | ) | const |
Returns the QObject
pointer at the first index of the list.
- Returns
- the QObject pointer at first index.
QObject * GCF::ObjectList::last | ( | ) | const |
Returns the last QObject
pointer in this list.
- Returns
- the
QObject
pointer which exists at last index.
int GCF::ObjectList::indexOf | ( | QObject * | obj | ) | const |
Returns the index of QObject
pointer in the list if it exists, otherwise returns -1.
- Parameters
-
obj QObject
pointer of which index needs to be returned.
- Returns
- index of the
QObject
in the list.
const QObjectList & GCF::ObjectList::toList | ( | ) | const |
Returns the existing QObject
pointers as a QObjectList
.
- Returns
- list of QObjects.
void GCF::ObjectList::removeAll | ( | ) |
Removes all the QObject
pointers from the current list.
- Note
- Does not delete the
QObject
pointers while removing.
void GCF::ObjectList::deleteAll | ( | ) |
Deletes all the QObject
in the current list.
void GCF::ObjectList::setEventListener | ( | GCF::ObjectListEventListener * | listener | ) |
Sets an event listener on this. If there was already an event listener set, it will be replaced.
- Parameters
-
listener event listener that needs to be set on this.
GCF::ObjectListEventListener * GCF::ObjectList::eventListener | ( | ) | const |
Returns the event listener which is currently set.
- Returns
- event listener which is currently set.
GCF::ObjectList & GCF::ObjectList::operator= | ( | const ObjectList & | other | ) |
Overloaded equal to operator. Shallow copies data from other ObjectList to this.
- Returns
- the reference to the this.
GCF::ObjectList::operator[] | ( | int | index | ) | const |
Returns the object pointer at the specified index.
- Parameters
-
index index of QObject
pointer that needs to be returned.
- Returns
QObject
pointer at specified index.
GCF::ObjectList::operator+= | ( | QObject * | obj | ) |
Adds the QObject
pointer obj to this and returns the reference of this list.
- Parameters
-
obj QObject
pointer which needs to be added.
- Returns
- reference to this.
GCF::ObjectList::operator-= | ( | QObject * | obj | ) |
Removes the QObject
pointer obj from this and returns the reference of this list.
- Parameters
-
obj QObject
pointer which needs be removed.
- Returns
- reference to this.
GCF::ObjectList::operator+ | ( | QObject * | obj | ) |
Adds the QObject
pointer and QObject
pointers in current list to a new ObjectList
and returns the new list.
- Parameters
-
obj QObject
pointer which will be added.
- Returns
- new ObjectList which contains
QObject
pointer obj and existing objects in this.
GCF::ObjectList::operator- | ( | QObject * | obj | ) |
Creates and returns a new ObjectList which contains subtracted list of QObject
pointers of current list from obj
.
- Parameters
-
obj QObject
pointer that will be subtracted from this.
- Returns
- new ObjectList which does not contain
QObject
pointer obj and contains the QObjects of this.
GCF::ObjectList::operator+= | ( | const ObjectList & | list | ) |
Adds the QObject
pointers in the other ObjectList 'list' to this and returns reference to this list.
- Parameters
-
list ObjectList containing QObject
pointers which needs be added.
- Returns
- reference to current list.
GCF::ObjectList::operator-= | ( | const ObjectList & | list | ) |
Removes the QObject
pointers from current list which are present in ObjectList list
and returns reference to this.
- Parameters
-
list ObjectList containing QObject
pointers which needs be removed.
- Returns
- reference to this.
GCF::ObjectList::operator+ | ( | const ObjectList & | list | ) |
Creates and returns a new ObjectList which will be sum of QObject
pointers in ObjectList 'list' and this.
- Parameters
-
list ObjectList containing QObject
pointers which needs be added.
- Returns
- new ObjectList which contains QObjects of both this and ObjectList 'list'.
GCF::ObjectList::operator- | ( | const ObjectList & | list | ) |
Creates and returns a new ObjectList which contains subtracted list of QObjects of current list from list
.
- Parameters
-
list ObjectList containing QObject
pointers which needs to be subtracted.
- Returns
- new ObjectList which contains subtracted list of
QObject
pointers of current list fromlist
.