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

This class manages a map of <T>-QObject pairs. <T> is a template class. More...

#include <GCF3/MapToObject>

Public Member Functions

 MapToObject ()
 
 MapToObject (const MapToObject &other)
 
 MapToObject (const QMap< T, QObject * > &map)
 
 ~MapToObject ()
 
void setEventListener (MapToObjectEventListener *listener)
 
MapToObjectEventListenereventListener () const
 
MapToObjectoperator= (const MapToObject &other)
 
void insert (const T &value, QObject *object)
 
void remove (const T &value)
 
QObject * operator[] (const T &value) const
 
int count () const
 
bool isEmpty () const
 
bool contains (const T &value) const
 
QObject * value (const T &key) const
 
QList< T > keys () const
 
QObjectList values () const
 
QMap< T, QObject * > toMap () const
 
const QMap< T, QObject * > & map () const
 
void removeAll ()
 
void deleteAll ()
 
- Public Member Functions inherited from GCF::ObjectListEventListener
 ObjectListEventListener ()
 
virtual ~ObjectListEventListener ()
 

Detailed Description

template<class T>
class GCF::MapToObject< T >

This class can be used as a replacement for QMap<T, QObject*>, when you want Value versus valid pointers to QObject to be stored in the map. This class automatically notifies and removes Value - invalid QObject pairs, as and when the object pointers inside MapToObject are deleted elsewhere in the application.

Three types of events can happen on GCF::MapToObject

  • A Value - QObject pointer pair got added to the map.
  • A Value - QObject pointer - got removed from the map.
  • A QObject pointer in Value - QObject pair's ,got deleted.

You can listen to this class by setting GCF::MapToObjectEventListener using setEventListener(MapToObjectEventListener *listener) method. When a new Value - QObject pointer pair is inserted or removed from the MapToObject, MapToObjectEventListener will notify it.

If you want to have several listeners receive event notifications on an object map, then you can install a GCF::MapToObjectEventBroadcaster on the object map and register all event listeners with the broadcaster.

Constructor & Destructor Documentation

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

Default constructor.

template<class T>
GCF::MapToObject< T >::MapToObject ( const MapToObject< T > &  other)

Copy constructor. MapToObject does not copy the GCF::MapToObjectEventListener that is currently set on the other GCF::MapToObject.

Parameters
otherMapToObject from which value-objects pairs will be copied.
template<class T>
GCF::MapToObject< T >::MapToObject ( const QMap< T, QObject * > &  map)

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

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

Destructor.

Member Function Documentation

template<class T>
GCF::MapToObject< T >::setEventListener ( MapToObjectEventListener listener)

Sets an event listener on the this. If there was a already an event listener set then it will be replaced with the new one.

Parameters
listenerthe GCF::MapToObjectEventListener which needs to be set as event listener.
template<class T>
GCF::MapToObject< T >::eventListener ( ) const
Returns
currently set event listener on this.
template<class T>
GCF::MapToObject< T >::operator= ( const MapToObject< T > &  other)

Overloaded equal to operator. It copies everything from GCF::MapToObject except the GCF::MapToObjectEventListener that is currently set on 'other' GCF::MapToObject.

Parameters
otherMapToObject from which value-objects pairs will be copied.
template<class T>
GCF::MapToObject< T >::insert ( const T &  value,
QObject *  object 
)

Inserts the Value - QObject pointer pair into the map.

Parameters
valuetemplate class value which needs to be inserted into the map
objectQObject pointer which needs to be inserted into the map against value.
template<class T>
GCF::MapToObject< T >::remove ( const T &  value)

Removes the Value - QObject pointer pair from the map.

Parameters
valuetemplate class value which needs to be removed from the map.
template<class T>
GCF::MapToObject< T >::operator[] ( const T &  value) const

Returns QObject pointer for value existing in the map. You have to make sure that the value exists in the map before calling this function.

Parameters
valuetemplate class value for which QObject pointer needs to be returned from the map.
Returns
QObject pointer stored against value.
template<class T>
GCF::MapToObject< T >::count ( ) const
Returns
the map object count.
template<class T>
GCF::MapToObject< T >::isEmpty ( ) const
Returns
true if the map is empty otherwise false.
template<class T>
GCF::MapToObject< T >::contains ( const T &  value) const
Returns
true if the map contains the value otherwise false.
template<class T>
GCF::MapToObject< T >::value ( const T &  key) const
Returns
QObject pointer stored against template class value 'key' in the map.
template<class T>
GCF::MapToObject< T >::keys ( ) const

Returns keys of map. Since GCF::MapToObject stores Template class value versus QObject pointer, keys() will return QList<T>.

Returns
QList<T> of all template class values stored as keys.
template<class T>
GCF::MapToObject< T >::values ( ) const

Returns list of QObject pointers stored in the map. Since GCF::MapToObject stores QObject pointer versus Template class value, value() will return QList<T>.

Returns
QObjectList of QObject pointers stored as values of map.
template<class T>
GCF::MapToObject< T >::toMap ( ) const
Returns
stored template class value - QObject pointer pairs as QMap<T,QObject*>.
template<class T>
GCF::MapToObject< T >::map ( ) const
Returns
constant reference to template class value - QObject pointer map.
template<class T>
GCF::MapToObject< T >::removeAll ( )

Removes all template class value - QObject pointer stored in this map.

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

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