GCF LOGO VCL LOGO
GCF::ObjectMap< T > Class Template Reference

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)
 
ObjectMapEventListenereventListener () const
 
ObjectMapoperator= (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
 
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 QObject pointer - Value pair got added to the map.
  • A QObject pointer - Value got removed from the map.
  • A QObject pointer 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

template<class T>
GCF::ObjectMap< T >::ObjectMap ( )

Default constructor.

template<class T>
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
otherObjectMap from which objects-value pairs will be copied.
template<class T>
GCF::ObjectMap< T >::ObjectMap ( const QMap< QObject *, T > &  map)

Copies the QObject-value pairs from QMap<QObject*,T> map to this.

template<class T>
GCF::ObjectMap< T >::~ObjectMap ( )

Destructor.

Member Function Documentation

template<class T>
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
listenerthe GCF::ObjectMapEventListener which needs to be set as event listener.
template<class T>
GCF::ObjectMap< T >::eventListener ( ) const
Returns
currently set event listener on this.
template<class T>
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
otherObjectMap from which objects-value pairs will be copied.
template<class T>
GCF::ObjectMap< T >::insert ( QObject *  object,
const T &  value 
)

Inserts the QObject pointer - Value pair into the map.

Parameters
objectQObject pointer which needs to be inserted into the map.
valuetemplate class value which needs to be inserted into the map against object pointer 'object'.
template<class T>
GCF::ObjectMap< T >::remove ( QObject *  object)

Removes the QObject pointer - Value pair from the map.

Parameters
objectQObject pointer which needs to be removed from the map.
template<class T>
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
objectQObject pointer for which reference to value needs to be returned from the map.
Returns
reference to the value.
template<class T>
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
objectQObject pointer for which const reference value needs to be returned from the map.
Returns
const reference to the value.
template<class T>
GCF::ObjectMap< T >::count ( ) const
Returns
the map object count.
template<class T>
GCF::ObjectMap< T >::isEmpty ( ) const
Returns
true whether the map is empty otherwise false.
template<class T>
GCF::ObjectMap< T >::contains ( QObject *  object) const
Returns
true if the map contains the object otherwise false.
template<class T>
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 object in map if it exists otherwise returns default value.
template<class T>
GCF::ObjectMap< T >::keys ( ) const

Returns keys of map. Since GCF::ObjectMap stores QObject pointer versus value, keys() will return QObjectList.

Returns
QObjectList of all the object pointers stored as keys.
template<class T>
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.
template<class T>
GCF::ObjectMap< T >::toMap ( ) const
Returns
stored QObject pointer - Value pairs as QMap<QObject*,T>.
template<class T>
GCF::ObjectMap< T >::map ( ) const
Returns
constant reference to QObject pointer - Value map.
template<class T>
GCF::ObjectMap< T >::removeAll ( )

Removes all QObject pointer - Value stored in this map.

template<class T>
GCF::ObjectMap< T >::deleteAll ( )

Deletes all QObject pointer stored in this map and removes the value stored in this map.