Qt 4.8
|
The QMultiMap class is a convenience QMap subclass that provides multi-valued maps. More...
#include <qcontainerfwd.h>
Public Functions | |
QMap< Key, T >::const_iterator | constFind (const Key &key, const T &value) const |
Returns an iterator pointing to the item with key key and the value value in the map. More... | |
bool | contains (const Key &key, const T &value) const |
Returns true if the map contains an item with key key and value value; otherwise returns false. More... | |
int | count (const Key &key, const T &value) const |
Returns the number of items with key key and value value. More... | |
QMap< Key, T >::iterator | find (const Key &key, const T &value) |
Returns an iterator pointing to the item with key key and value value in the map. More... | |
QMap< Key, T >::const_iterator | find (const Key &key, const T &value) const |
Returns a const iterator pointing to the item with the given key and value in the map. More... | |
QMap< Key, T >::iterator | insert (const Key &key, const T &value) |
Inserts a new item with the key key and a value of value. More... | |
QMultiMap | operator+ (const QMultiMap &other) const |
Returns a map that contains all the items in this map in addition to all the items in other. More... | |
QMultiMap & | operator+= (const QMultiMap &other) |
Inserts all the items in the other map into this map and returns a reference to this map. More... | |
QMultiMap () | |
Constructs an empty map. More... | |
QMultiMap (const QMap< Key, T > &other) | |
Constructs a copy of other (which can be a QMap or a QMultiMap). More... | |
int | remove (const Key &key, const T &value) |
Removes all the items that have the key key and the value value from the map. More... | |
QMap< Key, T >::iterator | replace (const Key &key, const T &value) |
Inserts a new item with the key key and a value of value. More... | |
void | swap (QMultiMap< Key, T > &other) |
Swaps map other with this map. More... | |
Public Functions inherited from QMap< Key, T > | |
iterator | begin () |
Returns an STL-style iterator pointing to the first item in the map. More... | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | clear () |
Removes all items from the map. More... | |
const_iterator | constBegin () const |
Returns a const STL-style iterator pointing to the first item in the map. More... | |
const_iterator | constEnd () const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map. More... | |
const_iterator | constFind (const Key &key) const |
Returns an const iterator pointing to the item with key key in the map. More... | |
bool | contains (const Key &key) const |
Returns true if the map contains an item with key key; otherwise returns false. More... | |
int | count (const Key &key) const |
Returns the number of items associated with key key. More... | |
int | count () const |
Same as size(). More... | |
void | detach () |
Detaches this map from any other maps with which it may share data. More... | |
bool | empty () const |
This function is provided for STL compatibility. More... | |
iterator | end () |
Returns an STL-style iterator pointing to the imaginary item after the last item in the map. More... | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | erase (iterator it) |
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to the next item in the map. More... | |
iterator | find (const Key &key) |
Returns an iterator pointing to the item with key key in the map. More... | |
const_iterator | find (const Key &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | insert (const Key &key, const T &value) |
Inserts a new item with the key key and a value of value. More... | |
iterator | insertMulti (const Key &key, const T &value) |
Inserts a new item with the key key and a value of value. More... | |
bool | isDetached () const |
Returns true if the map's internal data isn't shared with any other map object; otherwise returns false. More... | |
bool | isEmpty () const |
Returns true if the map contains no items; otherwise returns false. More... | |
bool | isSharedWith (const QMap< Key, T > &other) const |
const Key | key (const T &value) const |
Returns the first key with value value. More... | |
const Key | key (const T &value, const Key &defaultKey) const |
Returns the first key with value value, or defaultKey if the map contains no item with value value. More... | |
QList< Key > | keys () const |
Returns a list containing all the keys in the map in ascending order. More... | |
QList< Key > | keys (const T &value) const |
Returns a list containing all the keys associated with value value in ascending order. More... | |
iterator | lowerBound (const Key &key) |
Returns an iterator pointing to the first item with key key in the map. More... | |
const_iterator | lowerBound (const Key &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | operator!= (const QMap< Key, T > &other) const |
Returns true if other is not equal to this map; otherwise returns false. More... | |
QMap< Key, T > & | operator= (const QMap< Key, T > &other) |
Assigns other to this map and returns a reference to this map. More... | |
bool | operator== (const QMap< Key, T > &other) const |
Returns true if other is equal to this map; otherwise returns false. More... | |
T & | operator[] (const Key &key) |
Returns the value associated with the key key as a modifiable reference. More... | |
const T | operator[] (const Key &key) const |
Same as value(). More... | |
QMap () | |
Constructs an empty map. More... | |
QMap (const QMap< Key, T > &other) | |
Constructs a copy of other. More... | |
QMap (const typename std::map< Key, T > &other) | |
int | remove (const Key &key) |
Removes all the items that have the key key from the map. More... | |
void | setInsertInOrder (bool ordered) |
void | setSharable (bool sharable) |
int | size () const |
Returns the number of (key, value) pairs in the map. More... | |
void | swap (QMap< Key, T > &other) |
Swaps map other with this map. More... | |
T | take (const Key &key) |
Removes the item with the key key from the map and returns the value associated with it. More... | |
std::map< Key, T > | toStdMap () const |
Returns an STL map equivalent to this QMap. More... | |
QList< Key > | uniqueKeys () const |
Returns a list containing all the keys in the map in ascending order. More... | |
QMap< Key, T > & | unite (const QMap< Key, T > &other) |
Inserts all the items in the other map into this map. More... | |
iterator | upperBound (const Key &key) |
Returns an iterator pointing to the item that immediately follows the last item with key key in the map. More... | |
const_iterator | upperBound (const Key &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
const T | value (const Key &key) const |
Returns the value associated with the key key. More... | |
const T | value (const Key &key, const T &defaultValue) const |
If the map contains no item with key key, the function returns defaultValue. More... | |
QList< T > | values () const |
Returns a list containing all the values in the map, in ascending order of their keys. More... | |
QList< T > | values (const Key &key) const |
Returns a list containing all the values associated with key key, from the most recently inserted to the least recently inserted one. More... | |
~QMap () | |
Destroys the map. More... | |
Private Functions | |
T & | operator[] (const Key &key) |
const T | operator[] (const Key &key) const |
Additional Inherited Members | |
Public Types inherited from QMap< Key, T > | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QMap::const_iterator. More... | |
typedef qptrdiff | difference_type |
Typedef for ptrdiff_t. More... | |
typedef iterator | Iterator |
Qt-style synonym for QMap::iterator. More... | |
typedef Key | key_type |
Typedef for Key. More... | |
typedef T | mapped_type |
Typedef for T. More... | |
typedef int | size_type |
Typedef for int. More... | |
Related Functions inherited from QMap< Key, T > | |
QDataStream & | operator<< (QDataStream &out, const QMap< Key, T > &map) |
Writes the map map to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QMap< Key, T > &map) |
Reads a map from stream in into map. More... | |
The QMultiMap class is a convenience QMap subclass that provides multi-valued maps.
QMultiMap<Key, T> is one of Qt's generic container classes. It inherits QMap and extends it with a few convenience functions that make it more suitable than QMap for storing multi-valued maps. A multi-valued map is a map that allows multiple values with the same key; QMap normally doesn't allow that, unless you call QMap::insertMulti().
Because QMultiMap inherits QMap, all of QMap's functionality also applies to QMultiMap. For example, you can use isEmpty() to test whether the map is empty, and you can traverse a QMultiMap using QMap's iterator classes (for example, QMapIterator). But in addition, it provides an insert() function that corresponds to QMap::insertMulti(), and a replace() function that corresponds to QMap::insert(). It also provides convenient operator+() and operator+=().
Example:
Unlike QMap, QMultiMap provides no operator[]. Use value() or replace() if you want to access the most recently inserted item with a certain key.
If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>:
The items that share the same key are available from most recently to least recently inserted.
If you prefer the STL-style iterators, you can call find() to get the iterator for the first item with a key and iterate from there:
QMultiMap's key and value data types must be assignable data types. This covers most data types you are likely to encounter, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QMultiMap's key type must provide operator<(). See the QMap documentation for details.
Definition at line 59 of file qcontainerfwd.h.
Constructs a copy of other (which can be a QMap or a QMultiMap).
Definition at line 977 of file qmap.h.
|
inline |
Returns an iterator pointing to the item with key key and the value value in the map.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the map contains no such item, the function returns constEnd().
Definition at line 1040 of file qmap.h.
Q_INLINE_TEMPLATE bool QMultiMap< Key, T >::contains | ( | const Key & | key, |
const T & | value | ||
) | const |
Returns true if the map contains an item with key key and value value; otherwise returns false.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1048 of file qmap.h.
Referenced by QGraphicsScenePrivate::filterEvent(), and QGraphicsScenePrivate::removeSceneEventFilter().
Q_INLINE_TEMPLATE int QMultiMap< Key, T >::count | ( | const Key & | key, |
const T & | value | ||
) | const |
Returns the number of items with key key and value value.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1071 of file qmap.h.
Referenced by QNetworkDiskCache::expire().
|
inline |
Returns an iterator pointing to the item with key key and value value in the map.
If the map contains no such item, the function returns end().
If the map contains multiple items with key key, this function returns an iterator that points to the most recently inserted value.
Definition at line 1020 of file qmap.h.
|
inline |
Returns a const iterator pointing to the item with the given key and value in the map.
If the map contains no such item, the function returns end().
If the map contains multiple items with the specified key, this function returns a const iterator that points to the most recently inserted value.
Definition at line 1030 of file qmap.h.
|
inline |
Inserts a new item with the key key and a value of value.
If there is already an item with the same key in the map, this function will simply create a new one. (This behavior is different from replace(), which overwrites the value of an existing item.)
Definition at line 982 of file qmap.h.
Referenced by QSslCertificate::alternateSubjectNames(), QNetworkDiskCache::expire(), QGestureManager::filterEvent(), QGraphicsScenePrivate::installSceneEventFilter(), and QDBusXmlParser::interfaces().
|
inline |
Returns a map that contains all the items in this map in addition to all the items in other.
If a key is common to both maps, the resulting map will contain the key multiple times.
Definition at line 987 of file qmap.h.
|
inline |
Inserts all the items in the other map into this map and returns a reference to this map.
Definition at line 985 of file qmap.h.
|
private |
|
private |
Q_INLINE_TEMPLATE int QMultiMap< Key, T >::remove | ( | const Key & | key, |
const T & | value | ||
) |
Removes all the items that have the key key and the value value from the map.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the number of items removed.
Definition at line 1054 of file qmap.h.
|
inline |
Inserts a new item with the key key and a value of value.
If there is already an item with the key key, that item's value is replaced with value.
If there are multiple items with the key key, the most recently inserted item's value is replaced with value.
Definition at line 980 of file qmap.h.