This class manages a map of QObject-value pairs.
#include <GCF3/ObjectMap>. More...
Public Member Functions | |
| ObjectMap () | |
| ObjectMap (const ObjectMap &other) | |
| ObjectMap (const QMap< QObject *, T > &map) | |
| ~ObjectMap () | |
| void | setEventListener (ObjectMapEventListener *listener) |
| ObjectMapEventListener * | eventListener () const |
| ObjectMap & | operator= (const ObjectMap &other) |
| void | insert (QObject *object, const T &value) |
| void | remove (QObject *object) |
| T & | operator[] (QObject *object) |
| const T & | operator[] (QObject *object) const |
| int | count () const |
| bool | isEmpty () const |
| bool | contains (QObject *object) const |
| T | value (QObject *object, const T &defVal=T()) const |
| QObjectList | keys () const |
| QList< T > | values () const |
| QMap< QObject *, T > | toMap () const |
| const QMap< QObject *, T > & | map () const |
| void | removeAll () |
| void | deleteAll () |
Public Member Functions inherited from GCF::ObjectListEventListener | |
| ObjectListEventListener () | |
| virtual | ~ObjectListEventListener () |
Detailed Description
template<class T>
class GCF::ObjectMap< T >
This class can be used as a replacement for QMap<QObject*, T>, when you want only valid pointers to QObject to be stored in the map. This class automatically notifies and removes invalid QObject - Value pairs, as and when the objects are deleted inside the application.
Three types of events can happen on GCF::ObjectMap
- A
QObjectpointer - Value pair got added to the map. - A
QObjectpointer - Value got removed from the map. - A
QObjectpointer in the map, got deleted
You can listen to this by setting an GCF::ObjectMapEventListener using setEventListener(ObjectMapEventListener *listener) method. When a new QObject pointer - Value pair is inserted to/removed from the ObjectMap, ObjectMapEventListener will notify it.
If you want to have several listeners receive event notifications on an object map, then you can install a GCF::ObjectMapEventBroadcaster on the object map and register all event listeners with the broadcaster.
Constructor & Destructor Documentation
| GCF::ObjectMap< T >::ObjectMap | ( | ) |
Default constructor.
| GCF::ObjectMap< T >::ObjectMap | ( | const ObjectMap< T > & | other | ) |
Copy constructor. ObjectMap does not copy the GCF::ObjectMapEventListener that is currently set on the other GCF::ObjectMap.
- Parameters
-
other ObjectMap from which objects-value pairs will be copied.
| GCF::ObjectMap< T >::ObjectMap | ( | const QMap< QObject *, T > & | map | ) |
Copies the QObject-value pairs from QMap<QObject*,T> map to this.
| GCF::ObjectMap< T >::~ObjectMap | ( | ) |
Destructor.
Member Function Documentation
| GCF::ObjectMap< T >::setEventListener | ( | ObjectMapEventListener * | listener | ) |
Sets event listener on this. If there was a already an event listener set then it will be replaced with the new one.
- Parameters
-
listener the GCF::ObjectMapEventListener which needs to be set as event listener.
| GCF::ObjectMap< T >::eventListener | ( | ) | const |
- Returns
- currently set event listener on this.
| GCF::ObjectMap< T >::operator= | ( | const ObjectMap< T > & | other | ) |
Overloaded equal to operator. It copies everything from GCF::ObjectMap except the GCF::ObjectMapEventListener that is currently set on other GCF::ObjectMap.
- Parameters
-
other ObjectMap from which objects-value pairs will be copied.
| GCF::ObjectMap< T >::insert | ( | QObject * | object, |
| const T & | value | ||
| ) |
Inserts the QObject pointer - Value pair into the map.
- Parameters
-
object QObjectpointer which needs to be inserted into the map.value template class value which needs to be inserted into the map against object pointer 'object'.
| GCF::ObjectMap< T >::remove | ( | QObject * | object | ) |
Removes the QObject pointer - Value pair from the map.
- Parameters
-
object QObjectpointer which needs to be removed from the map.
| GCF::ObjectMap< T >::operator[] | ( | QObject * | object | ) |
Returns reference to the value for QObject pointer existing in the map. You have to make sure that the object exists in the map before calling this function.
- Parameters
-
object QObjectpointer for which reference to value needs to be returned from the map.
- Returns
- reference to the value.
| GCF::ObjectMap< T >::operator[] | ( | QObject * | object | ) | const |
Returns a constant reference to the value for QObject pointer existing in the map. You have to make sure that the object exists in the map before calling this function.
- Parameters
-
object QObjectpointer for which const reference value needs to be returned from the map.
- Returns
- const reference to the value.
| GCF::ObjectMap< T >::count | ( | ) | const |
- Returns
- the map object count.
| GCF::ObjectMap< T >::isEmpty | ( | ) | const |
- Returns
- true whether the map is empty otherwise false.
| GCF::ObjectMap< T >::contains | ( | QObject * | object | ) | const |
- Returns
- true if the map contains the object otherwise false.
| GCF::ObjectMap< T >::value | ( | QObject * | object, |
| const T & | defVal = T() |
||
| ) | const |
Returns a copy of the value stored against the QObject pointer object in the map otherwise returns the default value defVal.
- Returns
- value corresponding to
objectin map if it exists otherwise returns default value.
| GCF::ObjectMap< T >::keys | ( | ) | const |
Returns keys of map. Since GCF::ObjectMap stores QObject pointer versus value, keys() will return QObjectList.
- Returns
QObjectListof all the object pointers stored as keys.
| GCF::ObjectMap< T >::values | ( | ) | const |
Returns values of map. Since GCF::ObjectMap stores QObject pointer versus Template class value, value() will return QList<T>.
- Returns
QList<T>of values stored as key-value pair.
| GCF::ObjectMap< T >::toMap | ( | ) | const |
- Returns
- stored
QObjectpointer - Value pairs as QMap<QObject*,T>.
| GCF::ObjectMap< T >::map | ( | ) | const |
- Returns
- constant reference to
QObjectpointer - Value map.
| GCF::ObjectMap< T >::removeAll | ( | ) |
Removes all QObject pointer - Value stored in this map.
| GCF::ObjectMap< T >::deleteAll | ( | ) |
Deletes all QObject pointer stored in this map and removes the value stored in this map.


Public Member Functions inherited from