Qt 4.8
Classes | Public Types | Public Functions | Private Types | Private Functions | Static Private Functions | Properties | Friends | Related Functions | List of all members
QMap< Key, T > Class Template Reference

The QMap class is a template class that provides a skip-list-based dictionary. More...

#include <qdatastream.h>

Inheritance diagram for QMap< Key, T >:
QMultiMap< Key, T > QMultiMap< QGraphicsItem *, QGraphicsItem *> QMultiMap< QString, Method > QMultiMap< QString, Signal > QMultiMap< Qt::GestureType, QGestureRecognizer *>

Classes

class  const_iterator
 The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap. More...
 
class  iterator
 The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap. More...
 

Public Types

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...
 

Public Functions

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...
 
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 Types

typedef QMapNode< Key, T > Node
 
typedef QMapPayloadNode< Key, T > PayloadNode
 

Private Functions

void detach_helper ()
 
QMapData::NodefindNode (const Key &key) const
 
void freeData (QMapData *d)
 
QMapData::NodemutableFindNode (QMapData::Node *update[], const Key &key) const
 
QMapData::Nodenode_create (QMapData *d, QMapData::Node *update[], const Key &key, const T &value)
 

Static Private Functions

static int alignment ()
 
static Nodeconcrete (QMapData::Node *node)
 
static int payload ()
 

Properties

union {
   QMapData *   d
 
   QMapData::Node *   e
 
}; 
 

Friends

class const_iterator
 
class iterator
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QMap< Key, T > &map)
 Writes the map map to stream out. More...
 
QDataStreamoperator>> (QDataStream &in, QMap< Key, T > &map)
 Reads a map from stream in into map. More...
 

Detailed Description

template<class Key, class T>
class QMap< Key, T >

The QMap class is a template class that provides a skip-list-based dictionary.

Note
This class or function is reentrant.

QMap<Key, T> is one of Qt's generic container classes. It stores (key, value) pairs and provides fast lookup of the value associated with a key.

QMap and QHash provide very similar functionality. The differences are:

Here's an example QMap with QString keys and int values:

To insert a (key, value) pair into the map, you can use operator[]():

map["one"] = 1;
map["three"] = 3;
map["seven"] = 7;

This inserts the following three (key, value) pairs into the QMap: ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the map is to use insert():

map.insert("twelve", 12);

To look up a value, use operator[]() or value():

int num1 = map["thirteen"];
int num2 = map.value("thirteen");

If there is no item with the specified key in the map, these functions return a default-constructed value.

If you want to check whether the map contains a certain key, use contains():

int timeout = 30;
if (map.contains("TIMEOUT"))
timeout = map.value("TIMEOUT");

There is also a value() overload that uses its second argument as a default value if there is no item with the specified key:

int timeout = map.value("TIMEOUT", 30);

In general, we recommend that you use contains() and value() rather than operator[]() for looking up a key in a map. The reason is that operator[]() silently inserts an item into the map if no item exists with the same key (unless the map is const). For example, the following code snippet will create 1000 items in memory:

// WRONG
...
for (int i = 0; i < 1000; ++i) {
if (map[i] == okButton)
cout << "Found button at index " << i << endl;
}

To avoid this problem, replace map[i] with map.value(i) in the code above.

If you want to navigate through all the (key, value) pairs stored in a QMap, you can use an iterator. QMap provides both Java-style iterators (QMapIterator and QMutableMapIterator) and STL-style iterators (QMap::const_iterator and QMap::iterator). Here's how to iterate over a QMap<QString, int> using a Java-style iterator:

QMapIterator<QString, int> i(map);
while (i.hasNext()) {
i.next();
cout << i.key() << ": " << i.value() << endl;
}

Here's the same code, but using an STL-style iterator this time:

while (i != map.constEnd()) {
cout << i.key() << ": " << i.value() << endl;
++i;
}

The items are traversed in ascending key order.

Normally, a QMap allows only one value per key. If you call insert() with a key that already exists in the QMap, the previous value will be erased. For example:

map.insert("plenty", 100);
map.insert("plenty", 2000);
// map.value("plenty") == 2000

However, you can store multiple values per key by using insertMulti() instead of insert() (or using the convenience subclass QMultiMap). If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>:

QList<int> values = map.values("plenty");
for (int i = 0; i < values.size(); ++i)
cout << values.at(i) << endl;

The items that share the same key are available from most recently to least recently inserted. Another approach is to call find() to get the STL-style iterator for the first item with a key and iterate from there:

while (i != map.end() && i.key() == "plenty") {
cout << i.value() << endl;
++i;
}

If you only need to extract the values from a map (not the keys), you can also use foreach:

...
foreach (int value, map)
cout << value << endl;

Items can be removed from the map in several ways. One way is to call remove(); this will remove any item with the given key. Another way is to use QMutableMapIterator::remove(). In addition, you can clear the entire map using clear().

QMap'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, QMap's key type must provide operator<(). QMap uses it to keep its items sorted, and assumes that two keys x and y are equal if neither x < y nor y < x is true.

Example:

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
public:
Employee() {}
Employee(const QString &name, const QDate &dateOfBirth);
...
private:
QString myName;
QDate myDateOfBirth;
};
inline bool operator<(const Employee &e1, const Employee &e2)
{
if (e1.name() != e2.name())
return e1.name() < e2.name();
return e1.dateOfBirth() < e2.dateOfBirth();
}
#endif // EMPLOYEE_H

In the example, we start by comparing the employees' names. If they're equal, we compare their dates of birth to break the tie.

See also
QMapIterator, QMutableMapIterator, QHash, QSet

Definition at line 67 of file qdatastream.h.

Typedefs

◆ ConstIterator

template<class Key, class T>
QMap< Key, T >::ConstIterator

Qt-style synonym for QMap::const_iterator.

Definition at line 389 of file qmap.h.

◆ difference_type

template<class Key, class T>
QMap< Key, T >::difference_type

Typedef for ptrdiff_t.

Provided for STL compatibility.

Definition at line 411 of file qmap.h.

◆ Iterator

template<class Key, class T>
QMap< Key, T >::Iterator

Qt-style synonym for QMap::iterator.

Definition at line 388 of file qmap.h.

◆ key_type

template<class Key, class T>
QMap< Key, T >::key_type

Typedef for Key.

Provided for STL compatibility.

Definition at line 409 of file qmap.h.

◆ mapped_type

template<class Key, class T>
QMap< Key, T >::mapped_type

Typedef for T.

Provided for STL compatibility.

Definition at line 410 of file qmap.h.

◆ Node

template<class Key, class T>
typedef QMapNode<Key, T> QMap< Key, T >::Node
private

Definition at line 161 of file qmap.h.

◆ PayloadNode

template<class Key, class T>
typedef QMapPayloadNode<Key, T> QMap< Key, T >::PayloadNode
private

Definition at line 162 of file qmap.h.

◆ size_type

template<class Key, class T>
QMap< Key, T >::size_type

Typedef for int.

Provided for STL compatibility.

Definition at line 412 of file qmap.h.

Constructors and Destructors

◆ QMap() [1/3]

template<class Key, class T>
QMap< Key, T >::QMap ( )
inline

Constructs an empty map.

See also
clear()

Definition at line 182 of file qmap.h.

Referenced by QMap< int, QFrameInfo >::operator==().

182 : d(&QMapData::shared_null) { d->ref.ref(); }
QBasicAtomicInt ref
Definition: qmap.h:71
QMapData * d
Definition: qmap.h:165
static QMapData shared_null
Definition: qmap.h:91

◆ QMap() [2/3]

template<class Key, class T>
QMap< Key, T >::QMap ( const QMap< Key, T > &  other)
inline

Constructs a copy of other.

This operation occurs in constant time, because QMap is implicitly shared. This makes returning a QMap from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes linear time.

See also
operator=()

Definition at line 183 of file qmap.h.

183  : d(other.d)
184  { d->ref.ref(); if (!d->sharable) detach(); }
QBasicAtomicInt ref
Definition: qmap.h:71
QMapData * d
Definition: qmap.h:165
uint sharable
Definition: qmap.h:76
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205

◆ ~QMap()

template<class Key, class T>
QMap< Key, T >::~QMap ( )
inline

Destroys the map.

References to the values in the map, and all iterators over this map, become invalid.

Definition at line 185 of file qmap.h.

185 { if (!d) return; if (!d->ref.deref()) freeData(d); }
QBasicAtomicInt ref
Definition: qmap.h:71
void freeData(QMapData *d)
Definition: qmap.h:642
QMapData * d
Definition: qmap.h:165

◆ QMap() [3/3]

template<class Key, class T>
QMap< Key, T >::QMap ( const typename std::map< Key, T > &  other)
explicit

Functions

◆ alignment()

template<class Key, class T>
static int QMap< Key, T >::alignment ( )
inlinestaticprivate

Definition at line 170 of file qmap.h.

170  {
171 #ifdef Q_ALIGNOF
172  return int(qMax(sizeof(void*), Q_ALIGNOF(Node)));
173 #else
174  return 0;
175 #endif
176  }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ begin() [1/2]

template<class Key, class T>
QMap::iterator QMap< Key, T >::begin ( )
inline

Returns an STL-style iterator pointing to the first item in the map.

See also
constBegin(), end()

Definition at line 372 of file qmap.h.

Referenced by QWizardPrivate::_q_handleFieldObjectDestroyed(), QSpanCollection::addSpan(), QSpanCollection::cleanSpanSubIndex(), QWindowsXPStylePrivate::cleanupHandleMap(), QFontCache::cleanupPrinterFonts(), QTextDocumentPrivate::clear(), QFontCache::clear(), QAbstractItemViewPrivate::clearOrRemove(), QAbstractItemViewPrivate::delegateRefCount(), QCopChannel::detach(), QConfFileSettingsPrivate::ensureSectionParsed(), formatDifference(), QConfFile::mergedKeyMap(), MetaObjectGenerator::metaObject(), QString::multiArg(), operator<<(), QMap< int, QFrameInfo >::operator==(), QRegExpEngine::parse(), QTessellatorPrivate::processIntersections(), qt_transparent_pixel(), qt_xclb_incr_timeout(), QGraphicsScenePrivate::removeItemHelper(), QCopChannel::reregisterAll(), QCompletionEngine::saveInCache(), QStandardItemPrivate::setItemData(), QAbstractItemModel::setItemData(), QSpanCollection::spansInRect(), QFontCache::timerEvent(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), QSpanCollection::updateSpan(), write_xpm_image(), and QAxServerBase::~QAxServerBase().

372 { detach(); return iterator(e->forward[0]); }
QMapData::Node * e
Definition: qmap.h:166
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
friend class iterator
Definition: qmap.h:299
Node * forward[1]
Definition: qmap.h:65

◆ begin() [2/2]

template<class Key, class T>
QMap::const_iterator QMap< Key, T >::begin ( ) const
inline

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 373 of file qmap.h.

373 { return const_iterator(e->forward[0]); }
QMapData::Node * e
Definition: qmap.h:166
Node * forward[1]
Definition: qmap.h:65
friend class const_iterator
Definition: qmap.h:369

◆ clear()

template<class Key , class T >
Q_INLINE_TEMPLATE void QMap< Key, T >::clear ( )

◆ concrete()

template<class Key, class T>
static Node* QMap< Key, T >::concrete ( QMapData::Node node)
inlinestaticprivate

Definition at line 177 of file qmap.h.

177  {
178  return reinterpret_cast<Node *>(reinterpret_cast<char *>(node) - payload());
179  }
static int payload()
Definition: qmap.h:169

◆ constBegin()

template<class Key, class T>
QMap::const_iterator QMap< Key, T >::constBegin ( ) const
inline

Returns a const STL-style iterator pointing to the first item in the map.

See also
begin(), constEnd()

Definition at line 374 of file qmap.h.

Referenced by QScriptDebuggerScriptsModel::addExtraScriptInfo(), QTessellatorPrivate::addIntersections(), QAxEventSink::addSignal(), breakpointMapToScriptValue(), QIBaseDriver::close(), compare(), consoleCommandGroupMapToScriptValue(), QDBusMetaObject::createMetaObject(), QConfFileSettingsPrivate::ensureAllSectionsParsed(), QNetworkDiskCache::expire(), QTextHtmlExporter::findUrlForImage(), QMdiSubWindowPrivate::getOperation(), QScriptCompleteScriptsJob::handleResponse(), QSortedModelEngine::indexHint(), QXmlSimpleReaderPrivate::isExpandedEntityValueTooLarge(), macValue(), mergeKeySets(), QWizardPage::nextId(), QScriptEnginePrivate::objectFromVariantMap(), operator+=(), operator<<(), operator>>(), QRegExpEngine::parse(), QDBusIntrospection::parseInterface(), QDBusMetaObjectGenerator::parseMethods(), QDBusMetaObjectGenerator::parseProperties(), QDBusMetaObjectGenerator::parseSignals(), QXmlSimpleReaderPrivate::processElementETagBegin2(), QIBaseDriver::qHandleEventNotification(), scriptMapToScriptValue(), set_text(), QTableModel::setItemData(), QCss::StyleSelector::styleRulesForNode(), QConfFileSettingsPrivate::syncConfFile(), QFontCache::timerEvent(), QApplicationPrivate::translateRawTouchEvent(), QMap< int, QFrameInfo >::unite(), QConfFileSettingsPrivate::writeIniFile(), QConfFileSettingsPrivate::writePlistFile(), and QFontCache::~QFontCache().

374 { return const_iterator(e->forward[0]); }
QMapData::Node * e
Definition: qmap.h:166
Node * forward[1]
Definition: qmap.h:65
friend class const_iterator
Definition: qmap.h:369

◆ constEnd()

template<class Key, class T>
QMap::const_iterator QMap< Key, T >::constEnd ( ) const
inline

Returns a const STL-style iterator pointing to the imaginary item after the last item in the map.

See also
constBegin(), end()

Definition at line 380 of file qmap.h.

Referenced by QScriptDebuggerScriptsModel::addExtraScriptInfo(), QAxEventSink::addSignal(), QWidgetAnimator::animate(), breakpointMapToScriptValue(), QIBaseDriver::close(), compare(), consoleCommandGroupMapToScriptValue(), QMultiMap< QString, Method >::contains(), QDBusMetaObject::createMetaObject(), QConfFileSettingsPrivate::ensureAllSectionsParsed(), QNetworkDiskCache::expire(), QTextHtmlExporter::findUrlForImage(), QMdiSubWindowPrivate::getOperation(), QScriptCompleteScriptsJob::handleResponse(), QSortedModelEngine::indexHint(), QWSServerPrivate::invokeScreenTransform(), QXmlSimpleReaderPrivate::isExpandedEntityValueTooLarge(), macValue(), mergeKeySets(), QWizardPage::nextId(), QScriptEnginePrivate::objectFromVariantMap(), operator+=(), operator<<(), operator>>(), QRegExpEngine::parse(), QDBusMetaObjectGenerator::parseMethods(), QDBusMetaObjectGenerator::parseProperties(), QDBusMetaObjectGenerator::parseSignals(), QXmlSimpleReaderPrivate::processElementETagBegin2(), QIBaseDriver::qHandleEventNotification(), QConfFileSettingsPrivate::remove(), scriptMapToScriptValue(), QWSServerPrivate::sendFontRemovedEvent(), QWSServerPrivate::sendMaxWindowRectEvents(), set_text(), QTableModel::setItemData(), QCss::StyleSelector::styleRulesForNode(), QConfFileSettingsPrivate::syncConfFile(), QFontCache::timerEvent(), QMap< int, QFrameInfo >::unite(), QConfFileSettingsPrivate::writeIniFile(), QConfFileSettingsPrivate::writePlistFile(), and QFontCache::~QFontCache().

380 { return const_iterator(e); }
QMapData::Node * e
Definition: qmap.h:166
friend class const_iterator
Definition: qmap.h:369

◆ constFind()

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::const_iterator QMap< Key, T >::constFind ( const Key &  key) const

Returns an const iterator pointing to the item with key key in the map.

Since
4.1

If the map contains no item with key key, the function returns constEnd().

See also
find(), QMultiMap::constFind()

Definition at line 612 of file qmap.h.

Referenced by QWidgetAnimator::animate(), QMultiMap< QString, Method >::operator+(), and QConfFileSettingsPrivate::writeIniFile().

613 {
614  return const_iterator(findNode(akey));
615 }
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481
friend class const_iterator
Definition: qmap.h:369

◆ contains()

template<class Key, class T >
Q_INLINE_TEMPLATE bool QMap< Key, T >::contains ( const Key &  key) const

Returns true if the map contains an item with key key; otherwise returns false.

See also
count(), QMultiMap::contains()

Definition at line 553 of file qmap.h.

Referenced by QRegExpEngine::addAnchors(), QRegExpEngine::addPlusTransitions(), QCopChannel::answer(), QGraphicsScenePrivate::cancelGesturesForChildren(), QBuiltInMimes::canConvertFromMime(), QXlibCursor::changeCursor(), QGraphicsItem::data(), QDragManager::dragCursor(), QGestureManager::filterEvent(), QCalendarModel::formatForCell(), QOfonoManagerInterface::getProperty(), QConnmanManagerInterface::getProperty(), QOfonoModemInterface::getProperty(), QConnmanProfileInterface::getProperty(), QOfonoNetworkRegistrationInterface::getProperty(), QOfonoNetworkOperatorInterface::getProperty(), QConnmanServiceInterface::getProperty(), QOfonoSimInterface::getProperty(), QConnmanTechnologyInterface::getProperty(), QOfonoDataConnectionManagerInterface::getProperty(), QOfonoPrimaryDataContextInterface::getProperty(), QOfonoSmsInterface::getProperty(), QScanThread::getUserConfigurations(), QGraphicsObject::grabGesture(), MetaObjectGenerator::hasClassInfo(), MetaObjectGenerator::hasEnum(), QGenericEngine::hasIdentifier(), QCoreWlanEngine::hasIdentifier(), QNlaEngine::hasIdentifier(), MetaObjectGenerator::hasProperty(), MetaObjectGenerator::hasSignal(), MetaObjectGenerator::hasSlot(), QCompletionEngine::lookupCache(), QCompletionEngine::matchHint(), QMultiMap< QString, Method >::operator+(), QTest::QTouchEventSequence::point(), QXmlSimpleReaderPrivate::processElementETagBegin2(), QConnmanEngine::propertyChangedContext(), QConfFileSettingsPrivate::remove(), renameOverloads(), QScanThread::run(), QIBaseDriver::subscribeToNotificationImplementation(), QApplicationPrivate::translateRawTouchEvent(), QIBaseDriver::unsubscribeFromNotificationImplementation(), and write_xpm_image().

554 {
555  return findNode(akey) != e;
556 }
QMapData::Node * e
Definition: qmap.h:166
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481

◆ count() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE int QMap< Key, T >::count ( const Key &  key) const

Returns the number of items associated with key key.

See also
contains(), insertMulti(), QMultiMap::count()

Definition at line 539 of file qmap.h.

Referenced by compare(), QXmlSimpleReaderPrivate::insertXmlRef(), MetaObjectGenerator::metaObject(), QCompletionEngine::saveInCache(), and QCss::StyleSelector::styleRulesForNode().

540 {
541  int cnt = 0;
542  QMapData::Node *node = findNode(akey);
543  if (node != e) {
544  do {
545  ++cnt;
546  node = node->forward[0];
547  } while (node != e && !qMapLessThanKey<Key>(akey, concrete(node)->key));
548  }
549  return cnt;
550 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * e
Definition: qmap.h:166
Node * forward[1]
Definition: qmap.h:65
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481

◆ count() [2/2]

template<class Key, class T>
int QMap< Key, T >::count ( ) const
inline

Same as size().

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 390 of file qmap.h.

Referenced by QMultiMap< QString, Method >::operator+().

390 { return d->size; }
int size
Definition: qmap.h:73
QMapData * d
Definition: qmap.h:165

◆ detach()

template<class Key, class T>
void QMap< Key, T >::detach ( )
inline

Detaches this map from any other maps with which it may share data.

Warning
This function is not part of the public interface.
See also
isDetached()

Definition at line 205 of file qmap.h.

Referenced by operator>>().

205 { if (d->ref != 1) detach_helper(); }
QBasicAtomicInt ref
Definition: qmap.h:71
QMapData * d
Definition: qmap.h:165
void detach_helper()
Definition: qmap.h:752

◆ detach_helper()

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE void QMap< Key, T >::detach_helper ( )
private

Definition at line 752 of file qmap.h.

753 {
754  union { QMapData *d; QMapData::Node *e; } x;
756  if (d->size) {
757  x.d->insertInOrder = true;
758  QMapData::Node *update[QMapData::LastLevel + 1];
759  QMapData::Node *cur = e->forward[0];
760  update[0] = x.e;
761  while (cur != e) {
762  QT_TRY {
763  Node *concreteNode = concrete(cur);
764  node_create(x.d, update, concreteNode->key, concreteNode->value);
765  } QT_CATCH(...) {
766  freeData(x.d);
767  QT_RETHROW;
768  }
769  cur = cur->forward[0];
770  }
771  x.d->insertInOrder = false;
772  }
773  if (!d->ref.deref())
774  freeData(d);
775  d = x.d;
776 }
QMapData::Node * node_create(QMapData *d, QMapData::Node *update[], const Key &key, const T &value)
Definition: qmap.h:451
int size
Definition: qmap.h:73
QMapData::Node * e
Definition: qmap.h:166
static int alignment()
Definition: qmap.h:170
QBasicAtomicInt ref
Definition: qmap.h:71
void freeData(QMapData *d)
Definition: qmap.h:642
QMapData * d
Definition: qmap.h:165
#define QT_RETHROW
Definition: qglobal.h:1539
static QMapData * createData()
Definition: qmap.cpp:59
#define QT_CATCH(A)
Definition: qglobal.h:1537
Node * forward[1]
Definition: qmap.h:65
Definition: qmap.h:61
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
#define QT_TRY
Definition: qglobal.h:1536

◆ empty()

template<class Key, class T>
bool QMap< Key, T >::empty ( ) const
inline

This function is provided for STL compatibility.

It is equivalent to isEmpty(), returning true if the map is empty; otherwise returning false.

Definition at line 413 of file qmap.h.

413 { return isEmpty(); }
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203

◆ end() [1/2]

template<class Key, class T>
QMap::iterator QMap< Key, T >::end ( )
inline

Returns an STL-style iterator pointing to the imaginary item after the last item in the map.

See also
begin(), constEnd()

Definition at line 375 of file qmap.h.

Referenced by QWizardPrivate::_q_handleFieldObjectDestroyed(), QWidgetAnimator::abort(), QSpanCollection::addSpan(), QCopChannel::answer(), QSpanCollection::cleanSpanSubIndex(), QWSServerPrivate::cleanupFonts(), QWindowsXPStylePrivate::cleanupHandleMap(), QFontCache::cleanupPrinterFonts(), QTextDocumentPrivate::clear(), QFontCache::clear(), QAbstractItemViewPrivate::clearOrRemove(), QAbstractItemViewPrivate::delegateForIndex(), QAbstractItemViewPrivate::delegateRefCount(), QCopChannel::detach(), QConfFileSettingsPrivate::ensureSectionParsed(), QXmlSimpleReaderPrivate::entityExist(), QFontCache::findEngine(), QFontCache::findEngineData(), formatDifference(), QCopChannel::init(), QWSServerPrivate::invokeSelectCursor(), QConfFile::mergedKeyMap(), MetaObjectGenerator::metaObject(), QString::multiArg(), QApplication::notify(), operator<<(), QRegExpEngine::parse(), QXmlSimpleReaderPrivate::parsePEReference(), QTessellatorPrivate::processIntersections(), QXmlSimpleReaderPrivate::processReference(), qt_transparent_pixel(), qt_x11_incr_event_filter(), QCopChannel::registerChannel(), QConfFileSettingsPrivate::remove(), QGraphicsScenePrivate::removeItemHelper(), QCopChannel::reregisterAll(), QSqlTableModelPrivate::revertCachedRow(), QCompletionEngine::saveInCache(), QStandardItemPrivate::setItemData(), QAbstractItemModel::setItemData(), QSpanCollection::spanAt(), QSpanCollection::spansInRect(), QFontCache::timerEvent(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), QSpanCollection::updateSpan(), write_xpm_image(), QAxServerBase::~QAxServerBase(), and QCopChannel::~QCopChannel().

375  {
376  detach();
377  return iterator(e);
378  }
QMapData::Node * e
Definition: qmap.h:166
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
friend class iterator
Definition: qmap.h:299

◆ end() [2/2]

template<class Key, class T>
QMap::const_iterator QMap< Key, T >::end ( ) const
inline

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 379 of file qmap.h.

379 { return const_iterator(e); }
QMapData::Node * e
Definition: qmap.h:166
friend class const_iterator
Definition: qmap.h:369

◆ erase()

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::erase ( iterator  pos)

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.

Use remove(key) instead.

See also
remove()

Definition at line 717 of file qmap.h.

Referenced by QWidgetAnimator::abort(), QCopChannel::answer(), QSpanCollection::cleanSpanSubIndex(), QWSServerPrivate::cleanupFonts(), QFontCache::cleanupPrinterFonts(), QTextDocumentPrivate::clear(), QConfFileSettingsPrivate::ensureSectionParsed(), QRegExpEngine::parse(), QConfFileSettingsPrivate::remove(), QGraphicsScenePrivate::removeItemHelper(), QGraphicsScenePrivate::removeSceneEventFilter(), QSqlTableModelPrivate::revertCachedRow(), QCompletionEngine::saveInCache(), QFontCache::timerEvent(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), and QSpanCollection::updateSpan().

718 {
719  QMapData::Node *update[QMapData::LastLevel + 1];
720  QMapData::Node *cur = e;
721  QMapData::Node *next = e;
722 
723  if (it == iterator(e))
724  return it;
725 
726  for (int i = d->topLevel; i >= 0; i--) {
727  while ((next = cur->forward[i]) != e && qMapLessThanKey<Key>(concrete(next)->key, it.key()))
728  cur = next;
729  update[i] = cur;
730  }
731 
732  while (next != e) {
733  cur = next;
734  next = cur->forward[0];
735  if (cur == it) {
736  concrete(cur)->key.~Key();
737  concrete(cur)->value.~T();
738  d->node_delete(update, payload(), cur);
739  return iterator(next);
740  }
741 
742  for (int i = 0; i <= d->topLevel; ++i) {
743  if (update[i]->forward[i] != cur)
744  break;
745  update[i] = cur;
746  }
747  }
748  return end();
749 }
void node_delete(Node *update[], int offset, Node *node)
Definition: qmap.cpp:157
Key key
Definition: qmap.h:124
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
#define it(className, varName)
QMapData::Node * e
Definition: qmap.h:166
int topLevel
Definition: qmap.h:72
QMapData * d
Definition: qmap.h:165
friend class iterator
Definition: qmap.h:299
Node * forward[1]
Definition: qmap.h:65
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
static int payload()
Definition: qmap.h:169
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
T value
Definition: qmap.h:125

◆ find() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::find ( const Key &  key)

Returns an iterator pointing to the item with key key in the map.

If the map contains no item with key key, 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. The other values are accessible by incrementing the iterator. For example, here's some code that iterates over all the items with the same key:

...
QMap<QString, int>::const_iterator i = map.find("HDR");
while (i != map.end() && i.key() == "HDR") {
cout << i.value() << endl;
++i;
}
See also
constFind(), value(), values(), lowerBound(), upperBound(), QMultiMap::find()

Definition at line 618 of file qmap.h.

Referenced by QWidgetAnimator::abort(), QCopChannel::answer(), QAbstractItemViewPrivate::delegateForIndex(), QXmlSimpleReaderPrivate::entityExist(), QFontCache::findEngine(), QFontCache::findEngineData(), QCopChannel::init(), QWSServerPrivate::invokeSelectCursor(), QApplication::notify(), QMultiMap< QString, Method >::operator+(), QXmlSimpleReaderPrivate::parsePEReference(), QTessellatorPrivate::processIntersections(), QXmlSimpleReaderPrivate::processReference(), qt_x11_incr_event_filter(), QCopChannel::registerChannel(), QSqlTableModelPrivate::revertCachedRow(), QMdiSubWindowPrivate::setNewGeometry(), QMdiSubWindowPrivate::updateCursor(), QMdiSubWindowPrivate::updateDirtyRegions(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), and QCopChannel::~QCopChannel().

619 {
620  detach();
621  return iterator(findNode(akey));
622 }
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
friend class iterator
Definition: qmap.h:299
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481

◆ find() [2/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::const_iterator QMap< Key, T >::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.

Definition at line 606 of file qmap.h.

607 {
608  return const_iterator(findNode(akey));
609 }
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481
friend class const_iterator
Definition: qmap.h:369

◆ findNode()

template<class Key, class T >
Q_INLINE_TEMPLATE QMapData::Node * QMap< Key, T >::findNode ( const Key &  key) const
private

Definition at line 481 of file qmap.h.

482 {
483  QMapData::Node *cur = e;
484  QMapData::Node *next = e;
485 
486  for (int i = d->topLevel; i >= 0; i--) {
487  while ((next = cur->forward[i]) != e && qMapLessThanKey<Key>(concrete(next)->key, akey))
488  cur = next;
489  }
490 
491  if (next != e && !qMapLessThanKey<Key>(akey, concrete(next)->key)) {
492  return next;
493  } else {
494  return e;
495  }
496 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * e
Definition: qmap.h:166
int topLevel
Definition: qmap.h:72
QMapData * d
Definition: qmap.h:165
Node * forward[1]
Definition: qmap.h:65
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177

◆ freeData()

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE void QMap< Key, T >::freeData ( QMapData d)
private

Definition at line 642 of file qmap.h.

643 {
645  QMapData *cur = x;
646  QMapData *next = cur->forward[0];
647  while (next != x) {
648  cur = next;
649  next = cur->forward[0];
650  Node *concreteNode = concrete(reinterpret_cast<QMapData::Node *>(cur));
651  concreteNode->key.~Key();
652  concreteNode->value.~T();
653  }
654  }
655  x->continueFreeData(payload());
656 }
QMapData * forward[QMapData::LastLevel+1]
Definition: qmap.h:70
Definition: qmap.h:61
static int payload()
Definition: qmap.h:169
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177

◆ insert()

template<class Key, class T>
Q_INLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::insert ( const Key &  key,
const T &  value 
)

Inserts a new item with the key key and a value of value.

Use the two-argument insert() overload instead.

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.

See also
insertMulti()

If you don't want to overwrite, call contains() beforehand.

QMap<QString, int> map; ... map.insert("delay", 30000, false); QMap<QString, int> map; ... if (!map.contains("delay")) map.insert("delay", 30000);

Definition at line 559 of file qmap.h.

Referenced by QRegExpEngine::addAnchors(), QTessellatorPrivate::addIntersection(), QRegExpEngine::addPlusTransitions(), QAxEventSink::addProperty(), QDir::addResourceSearchPath(), QAxEventSink::addSignal(), QSpanCollection::addSpan(), allKeys(), QScriptObjectSnapshot::capture(), QRegExpEngine::Box::cat(), QRegExpEngine::Box::catAnchor(), QXlibCursor::changeCursor(), QSpanCollection::cleanSpanSubIndex(), ControlList::ControlList(), QTextCopyHelper::convertFormatIndex(), QMacPasteboardMimeVCard::convertFromMime(), QAxServerBase::createMenu(), QAxServerBase::createPopup(), QGenericEngine::doRequestUpdate(), QGraphicsScenePrivate::drawSubtreeRecursive(), QtopiaPrintEngine::end(), QGestureManager::filterEvent(), QLastResortMimes::formatsForMime(), QScanThread::foundNetwork(), QImageReaderPrivate::getText(), QScanThread::getUserConfigurations(), QGraphicsObject::grabGesture(), QCopChannel::init(), QMdiSubWindowPrivate::initOperationMap(), QMap< int, QFrameInfo >::insert(), QFontCache::insertEngine(), QFontCache::insertEngineData(), QComboBox::insertItem(), QDBusXmlParser::interfaces(), QWSServerPrivate::invokeDefineCursor(), QListModel::itemData(), QTreeModel::itemData(), QStandardItemPrivate::itemData(), QTableModel::itemData(), QAbstractItemModel::itemData(), mdiAreaNavigate(), QConfFile::mergedKeyMap(), mergeKeySets(), MetaObjectGenerator::metaObject(), QString::multiArg(), QAudioDeviceInfo::nearestFormat(), QDBusXmlParser::objectTree(), operator+=(), QGraphicsView::paintEvent(), QScriptXmlParser::parse(), parseAnnotations(), QXmlSimpleReaderPrivate::parseEntityDecl(), QSettingsPrivate::processChild(), QTextFormat::properties(), QAxBase::propertyBag(), QConnmanEngine::propertyChangedContext(), QBuiltInMimes::QBuiltInMimes(), QClipboardINCRTransaction::QClipboardINCRTransaction(), QDirectPainter::QDirectPainter(), QLibraryPrivate::QLibraryPrivate(), qt_transparent_pixel(), read_xpm_body(), readAllProperties(), QConfFileSettingsPrivate::readIniSection(), QConfFileSettingsPrivate::readPlistFile(), QCopChannel::registerChannel(), QConfFileSettingsPrivate::remove(), renameOverloads(), QMultiMap< QString, Method >::replace(), QSqlTableModelPrivate::revertCachedRow(), QScriptDebuggerScriptsModel::scripts(), QConfFileSettingsPrivate::set(), set_text(), QGtkStylePrivate::setupGtkFileChooser(), QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber(), QIBaseDriver::subscribeToNotificationImplementation(), QConfFileSettingsPrivate::syncConfFile(), QApplicationPrivate::translateRawTouchEvent(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateInsertedRows(), QSpanCollection::updateRemovedRows(), QDeclarativeEngineDebugService::valueContents(), QScriptEnginePrivate::variantMapFromObject(), and write_xpm_image().

561 {
562  detach();
563 
564  QMapData::Node *update[QMapData::LastLevel + 1];
565  QMapData::Node *node = mutableFindNode(update, akey);
566  if (node == e) {
567  node = node_create(d, update, akey, avalue);
568  } else {
569  concrete(node)->value = avalue;
570  }
571  return iterator(node);
572 }
QMapData::Node * mutableFindNode(QMapData::Node *update[], const Key &key) const
Definition: qmap.h:779
QMapData::Node * node_create(QMapData *d, QMapData::Node *update[], const Key &key, const T &value)
Definition: qmap.h:451
QMapData::Node * e
Definition: qmap.h:166
QMapData * d
Definition: qmap.h:165
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
friend class iterator
Definition: qmap.h:299
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
T value
Definition: qmap.h:125

◆ insertMulti()

template<class Key, class T>
Q_INLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::insertMulti ( const Key &  key,
const T &  value 
)

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 insert(), which overwrites the value of an existing item.)

See also
insert(), values()

Definition at line 595 of file qmap.h.

Referenced by QGestureManager::filterEvent(), QMultiMap< QString, Method >::insert(), QCss::StyleSelector::matchRule(), operator>>(), and QGestureManager::registerGestureRecognizer().

597 {
598  detach();
599 
600  QMapData::Node *update[QMapData::LastLevel + 1];
601  mutableFindNode(update, akey);
602  return iterator(node_create(d, update, akey, avalue));
603 }
QMapData::Node * mutableFindNode(QMapData::Node *update[], const Key &key) const
Definition: qmap.h:779
QMapData::Node * node_create(QMapData *d, QMapData::Node *update[], const Key &key, const T &value)
Definition: qmap.h:451
QMapData * d
Definition: qmap.h:165
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
friend class iterator
Definition: qmap.h:299

◆ isDetached()

template<class Key, class T>
bool QMap< Key, T >::isDetached ( ) const
inline

Returns true if the map's internal data isn't shared with any other map object; otherwise returns false.

Warning
This function is not part of the public interface.
See also
detach()

Definition at line 206 of file qmap.h.

206 { return d->ref == 1; }
QBasicAtomicInt ref
Definition: qmap.h:71
QMapData * d
Definition: qmap.h:165

◆ isEmpty()

template<class Key, class T>
bool QMap< Key, T >::isEmpty ( ) const
inline

◆ isSharedWith()

template<class Key, class T>
bool QMap< Key, T >::isSharedWith ( const QMap< Key, T > &  other) const
inline
Warning
This function is not part of the public interface.

Definition at line 208 of file qmap.h.

208 { return d == other.d; }
QMapData * d
Definition: qmap.h:165

◆ key() [1/2]

template<class Key , class T>
Q_OUTOFLINE_TEMPLATE const Key QMap< Key, T >::key ( const T &  value) const

Returns the first key with value value.

If the map contains no item with value value, the function returns a default-constructed key.

This function can be slow (linear time), because QMap's internal data structure is optimized for fast lookup by key, not by value.

See also
value(), keys()

Definition at line 844 of file qmap.h.

Referenced by QWizardPrivate::_q_handleFieldObjectDestroyed(), QScriptDebuggerScriptsModel::addExtraScriptInfo(), QAxEventSink::addSignal(), QBuiltInMimes::canConvertToMime(), QGestureManager::cleanupCachedGestures(), QWSServerPrivate::cleanupFonts(), QBuiltInMimes::convertToMime(), QTextHtmlExporter::findUrlForImage(), QBuiltInMimes::formatsForMime(), macValue(), QString::multiArg(), set_text(), and QGestureManager::unregisterGestureRecognizer().

845 {
846  return key(avalue, Key());
847 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844

◆ key() [2/2]

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE const Key QMap< Key, T >::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.

Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function can be slow (linear time), because QMap's internal data structure is optimized for fast lookup by key, not by value.

Definition at line 850 of file qmap.h.

851 {
852  const_iterator i = begin();
853  while (i != end()) {
854  if (i.value() == avalue)
855  return i.key();
856  ++i;
857  }
858 
859  return defaultKey;
860 }
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
friend class const_iterator
Definition: qmap.h:369

◆ keys() [1/2]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QList< Key > QMap< Key, T >::keys ( ) const

Returns a list containing all the keys in the map in ascending order.

Keys that occur multiple times in the map (because items were inserted with insertMulti(), or unite() was used) also occur multiple times in the list.

To obtain a list of unique keys, where each key from the map only occurs once, use uniqueKeys().

The order is guaranteed to be the same as that used by values().

See also
uniqueKeys(), values(), key()

Definition at line 818 of file qmap.h.

Referenced by QGraphicsScene::addItem(), QAccessibleTextWidget::attributes(), QBuiltInMimes::canConvertToMime(), QScriptObjectSnapshot::capture(), QConfFileSettingsPrivate::children(), QMacSettingsPrivate::children(), QWinSettingsPrivate::children(), QBuiltInMimes::formatsForMime(), QScanThread::isKnownSsid(), QDBusXmlParser::objectTree(), QGraphicsScenePrivate::removeItemHelper(), QIBaseDriver::subscribedToNotificationsImplementation(), QImageReader::textKeys(), QMdiSubWindowPrivate::updateDirtyRegions(), and QGraphicsItem::~QGraphicsItem().

819 {
820  QList<Key> res;
821  res.reserve(size());
822  const_iterator i = begin();
823  while (i != end()) {
824  res.append(i.key());
825  ++i;
826  }
827  return res;
828 }
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
friend class const_iterator
Definition: qmap.h:369

◆ keys() [2/2]

template<class Key , class T>
Q_OUTOFLINE_TEMPLATE QList< Key > QMap< Key, T >::keys ( const T &  value) const

Returns a list containing all the keys associated with value value in ascending order.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function can be slow (linear time), because QMap's internal data structure is optimized for fast lookup by key, not by value.

Definition at line 831 of file qmap.h.

832 {
833  QList<Key> res;
834  const_iterator i = begin();
835  while (i != end()) {
836  if (i.value() == avalue)
837  res.append(i.key());
838  ++i;
839  }
840  return res;
841 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
friend class const_iterator
Definition: qmap.h:369

◆ lowerBound() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::lowerBound ( const Key &  key)

Returns an iterator pointing to the first item with key key in the map.

If the map contains no item with key key, the function returns an iterator to the nearest item with a greater key.

Example:

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.lowerBound(0); // returns iterator to (1, "one")
map.lowerBound(1); // returns iterator to (1, "one")
map.lowerBound(2); // returns iterator to (5, "five")
map.lowerBound(10); // returns iterator to (10, "ten")
map.lowerBound(999); // returns end()

If the map contains multiple items with key key, this function returns an iterator that points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, here's some code that iterates over all the items with the same key:

...
QMap<QString, int>::const_iterator i = map.lowerBound("HDR");
while (i != upperBound) {
cout << i.value() << endl;
++i;
}
See also
qLowerBound(), upperBound(), find()

Definition at line 899 of file qmap.h.

Referenced by QSpanCollection::addSpan(), QGraphicsScenePrivate::filterEvent(), QGestureManager::filterEventThroughContexts(), QSortedModelEngine::indexHint(), QConfFileSettingsPrivate::remove(), QGraphicsScenePrivate::removeSceneEventFilter(), QSpanCollection::spanAt(), QSpanCollection::spansInRect(), and QSpanCollection::updateSpan().

900 {
901  detach();
902  return static_cast<QMapData::Node *>(const_cast<const QMap *>(this)->lowerBound(akey));
903 }
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
Definition: qmap.h:899
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ lowerBound() [2/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::const_iterator QMap< Key, T >::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.

Definition at line 891 of file qmap.h.

892 {
893  QMapData::Node *update[QMapData::LastLevel + 1];
894  mutableFindNode(update, akey);
895  return const_iterator(update[0]->forward[0]);
896 }
QMapData::Node * mutableFindNode(QMapData::Node *update[], const Key &key) const
Definition: qmap.h:779
friend class const_iterator
Definition: qmap.h:369

◆ mutableFindNode()

template<class Key, class T >
Q_OUTOFLINE_TEMPLATE QMapData::Node * QMap< Key, T >::mutableFindNode ( QMapData::Node update[],
const Key &  key 
) const
private

Definition at line 779 of file qmap.h.

781 {
782  QMapData::Node *cur = e;
783  QMapData::Node *next = e;
784 
785  for (int i = d->topLevel; i >= 0; i--) {
786  while ((next = cur->forward[i]) != e && qMapLessThanKey<Key>(concrete(next)->key, akey))
787  cur = next;
788  aupdate[i] = cur;
789  }
790  if (next != e && !qMapLessThanKey<Key>(akey, concrete(next)->key)) {
791  return next;
792  } else {
793  return e;
794  }
795 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * e
Definition: qmap.h:166
int topLevel
Definition: qmap.h:72
QMapData * d
Definition: qmap.h:165
Node * forward[1]
Definition: qmap.h:65
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177

◆ node_create()

template<class Key, class T>
Q_INLINE_TEMPLATE QMapData::Node * QMap< Key, T >::node_create ( QMapData d,
QMapData::Node update[],
const Key &  key,
const T &  value 
)
private

Definition at line 451 of file qmap.h.

452 {
453  QMapData::Node *abstractNode = adt->node_create(aupdate, payload(), alignment());
454  QT_TRY {
455  Node *concreteNode = concrete(abstractNode);
456  new (&concreteNode->key) Key(akey);
457  QT_TRY {
458  new (&concreteNode->value) T(avalue);
459  } QT_CATCH(...) {
460  concreteNode->key.~Key();
461  QT_RETHROW;
462  }
463  } QT_CATCH(...) {
464  adt->node_delete(aupdate, payload(), abstractNode);
465  QT_RETHROW;
466  }
467 
468  // clean up the update array for further insertions
469  /*
470  for (int i = 0; i <= d->topLevel; ++i) {
471  if ( aupdate[i]==reinterpret_cast<QMapData::Node *>(adt) || aupdate[i]->forward[i] != abstractNode)
472  break;
473  aupdate[i] = abstractNode;
474  }
475 */
476 
477  return abstractNode;
478 }
static int alignment()
Definition: qmap.h:170
#define QT_RETHROW
Definition: qglobal.h:1539
#define QT_CATCH(A)
Definition: qglobal.h:1537
static int payload()
Definition: qmap.h:169
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
#define QT_TRY
Definition: qglobal.h:1536

◆ operator!=()

template<class Key, class T>
bool QMap< Key, T >::operator!= ( const QMap< Key, T > &  other) const
inline

Returns true if other is not equal to this map; otherwise returns false.

Two maps are considered equal if they contain the same (key, value) pairs.

This function requires the value type to implement operator==().

See also
operator==()

Definition at line 199 of file qmap.h.

199 { return !(*this == other); }

◆ operator=()

template<class Key, class T>
Q_INLINE_TEMPLATE QMap< Key, T > & QMap< Key, T >::operator= ( const QMap< Key, T > &  other)

Assigns other to this map and returns a reference to this map.

Definition at line 429 of file qmap.h.

430 {
431  if (d != other.d) {
432  QMapData* o = other.d;
433  o->ref.ref();
434  if (!d->ref.deref())
435  freeData(d);
436  d = o;
437  if (!d->sharable)
438  detach_helper();
439  }
440  return *this;
441 }
QBasicAtomicInt ref
Definition: qmap.h:71
void freeData(QMapData *d)
Definition: qmap.h:642
QMapData * d
Definition: qmap.h:165
uint sharable
Definition: qmap.h:76
Definition: qmap.h:61
void detach_helper()
Definition: qmap.h:752

◆ operator==()

template<class Key, class T>
Q_OUTOFLINE_TEMPLATE bool QMap< Key, T >::operator== ( const QMap< Key, T > &  other) const

Returns true if other is equal to this map; otherwise returns false.

Two maps are considered equal if they contain the same (key, value) pairs.

This function requires the value type to implement operator==().

See also
operator!=()

Definition at line 925 of file qmap.h.

926 {
927  if (size() != other.size())
928  return false;
929  if (d == other.d)
930  return true;
931 
932  const_iterator it1 = begin();
933  const_iterator it2 = other.begin();
934 
935  while (it1 != end()) {
936  if (!(it1.value() == it2.value()) || qMapLessThanKey(it1.key(), it2.key()) || qMapLessThanKey(it2.key(), it1.key()))
937  return false;
938  ++it2;
939  ++it1;
940  }
941  return true;
942 }
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
QMapData * d
Definition: qmap.h:165
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
bool qMapLessThanKey(const Key &key1, const Key &key2)
Definition: qmap.h:105
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
friend class const_iterator
Definition: qmap.h:369

◆ operator[]() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE T & QMap< Key, T >::operator[] ( const Key &  key)

Returns the value associated with the key key as a modifiable reference.

If the map contains no item with key key, the function inserts a default-constructed value into the map with key key, and returns a reference to it. If the map contains multiple items with key key, this function returns a reference to the most recently inserted value.

See also
insert(), value()

Definition at line 527 of file qmap.h.

528 {
529  detach();
530 
531  QMapData::Node *update[QMapData::LastLevel + 1];
532  QMapData::Node *node = mutableFindNode(update, akey);
533  if (node == e)
534  node = node_create(d, update, akey, T());
535  return concrete(node)->value;
536 }
QMapData::Node * mutableFindNode(QMapData::Node *update[], const Key &key) const
Definition: qmap.h:779
QMapData::Node * node_create(QMapData *d, QMapData::Node *update[], const Key &key, const T &value)
Definition: qmap.h:451
QMapData::Node * e
Definition: qmap.h:166
QMapData * d
Definition: qmap.h:165
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
T value
Definition: qmap.h:125

◆ operator[]() [2/2]

template<class Key, class T >
Q_INLINE_TEMPLATE const T QMap< Key, T >::operator[] ( const Key &  key) const

Same as 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 521 of file qmap.h.

522 {
523  return value(akey);
524 }
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499

◆ payload()

template<class Key, class T>
static int QMap< Key, T >::payload ( )
inlinestaticprivate

Definition at line 169 of file qmap.h.

169 { return sizeof(PayloadNode) - sizeof(QMapData::Node *); }
QMapPayloadNode< Key, T > PayloadNode
Definition: qmap.h:162

◆ remove()

template<class Key, class T >
Q_OUTOFLINE_TEMPLATE int QMap< Key, T >::remove ( const Key &  key)

Removes all the items that have the key key from the map.

Use erase(it) instead.

Returns the number of items removed which is usually 1 but will be 0 if the key isn't in the map, or > 1 if insertMulti() has been used with the key.

See also
clear(), take(), QMultiMap::remove()

Definition at line 662 of file qmap.h.

Referenced by QDir::addResourceSearchPath(), QAxEventSink::addSignal(), QAxServerBase::createPopup(), QTextDocumentPrivate::deleteObject(), QGenericEngine::doRequestUpdate(), QConfFile::mergedKeyMap(), QMultiMap< QString, Method >::operator+(), QTessellatorPrivate::processIntersections(), QConfFileSettingsPrivate::remove(), QGraphicsScenePrivate::removeItemHelper(), QSqlTableModelPrivate::revertCachedRow(), QConfFileSettingsPrivate::set(), QIBaseDriver::subscribeToNotificationImplementation(), QConnmanEngine::technologyPropertyChangedContext(), QIBaseDriver::unsubscribeFromNotificationImplementation(), QClipboardINCRTransaction::~QClipboardINCRTransaction(), and QCopChannel::~QCopChannel().

663 {
664  detach();
665 
666  QMapData::Node *update[QMapData::LastLevel + 1];
667  QMapData::Node *cur = e;
668  QMapData::Node *next = e;
669  int oldSize = d->size;
670 
671  for (int i = d->topLevel; i >= 0; i--) {
672  while ((next = cur->forward[i]) != e && qMapLessThanKey<Key>(concrete(next)->key, akey))
673  cur = next;
674  update[i] = cur;
675  }
676 
677  if (next != e && !qMapLessThanKey<Key>(akey, concrete(next)->key)) {
678  bool deleteNext = true;
679  do {
680  cur = next;
681  next = cur->forward[0];
682  deleteNext = (next != e && !qMapLessThanKey<Key>(concrete(cur)->key, concrete(next)->key));
683  concrete(cur)->key.~Key();
684  concrete(cur)->value.~T();
685  d->node_delete(update, payload(), cur);
686  } while (deleteNext);
687  }
688  return oldSize - d->size;
689 }
void node_delete(Node *update[], int offset, Node *node)
Definition: qmap.cpp:157
Key key
Definition: qmap.h:124
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
int size
Definition: qmap.h:73
QMapData::Node * e
Definition: qmap.h:166
int topLevel
Definition: qmap.h:72
QMapData * d
Definition: qmap.h:165
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
Node * forward[1]
Definition: qmap.h:65
static int payload()
Definition: qmap.h:169
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
T value
Definition: qmap.h:125

◆ setInsertInOrder()

template<class Key, class T>
void QMap< Key, T >::setInsertInOrder ( bool  sharable)
inline
Warning
This function is not part of the public interface.

Definition at line 209 of file qmap.h.

Referenced by operator>>().

209 { d->insertInOrder = ordered; }
QMapData * d
Definition: qmap.h:165
uint insertInOrder
Definition: qmap.h:75

◆ setSharable()

template<class Key, class T>
void QMap< Key, T >::setSharable ( bool  sharable)
inline
Warning
This function is not part of the public interface.

Definition at line 207 of file qmap.h.

207 { if (!sharable) detach(); d->sharable = sharable; }
QMapData * d
Definition: qmap.h:165
uint sharable
Definition: qmap.h:76
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205

◆ size()

template<class Key, class T>
int QMap< Key, T >::size ( ) const
inline

◆ swap()

template<class Key, class T>
void QMap< Key, T >::swap ( QMap< Key, T > &  other)
inline

Swaps map other with this map.

Since
4.8

This operation is very fast and never fails.

Definition at line 192 of file qmap.h.

Referenced by QMultiMap< QString, Method >::swap().

192 { qSwap(d, other.d); }
QMapData * d
Definition: qmap.h:165
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ take()

template<class Key, class T >
Q_OUTOFLINE_TEMPLATE T QMap< Key, T >::take ( const Key &  key)

Removes the item with the key key from the map and returns the value associated with it.

If the item does not exist in the map, the function simply returns a default-constructed value. If there are multiple items for key in the map, only the most recently inserted one is removed and returned.

If you don't use the return value, remove() is more efficient.

See also
remove()

Definition at line 692 of file qmap.h.

Referenced by QWSServerPrivate::invokeDefineCursor(), QFSFileEnginePrivate::map(), QApplicationPrivate::translateRawTouchEvent(), QGestureManager::unregisterGestureRecognizer(), and QLibraryPrivate::~QLibraryPrivate().

693 {
694  detach();
695 
696  QMapData::Node *update[QMapData::LastLevel + 1];
697  QMapData::Node *cur = e;
698  QMapData::Node *next = e;
699 
700  for (int i = d->topLevel; i >= 0; i--) {
701  while ((next = cur->forward[i]) != e && qMapLessThanKey<Key>(concrete(next)->key, akey))
702  cur = next;
703  update[i] = cur;
704  }
705 
706  if (next != e && !qMapLessThanKey<Key>(akey, concrete(next)->key)) {
707  T t = concrete(next)->value;
708  concrete(next)->key.~Key();
709  concrete(next)->value.~T();
710  d->node_delete(update, payload(), next);
711  return t;
712  }
713  return T();
714 }
void node_delete(Node *update[], int offset, Node *node)
Definition: qmap.cpp:157
Key key
Definition: qmap.h:124
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * e
Definition: qmap.h:166
int topLevel
Definition: qmap.h:72
QMapData * d
Definition: qmap.h:165
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
Node * forward[1]
Definition: qmap.h:65
static int payload()
Definition: qmap.h:169
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
T value
Definition: qmap.h:125

◆ toStdMap()

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE std::map< Key, T > QMap< Key, T >::toStdMap ( ) const

Returns an STL map equivalent to this QMap.

This function is only available if Qt is configured with STL compatibility enabled.

Definition at line 959 of file qmap.h.

960 {
961  std::map<Key, T> map;
962  const_iterator it = end();
963  while (it != begin()) {
964  --it;
965  map.insert(std::pair<Key, T>(it.key(), it.value()));
966  }
967  return map;
968 }
#define it(className, varName)
QFuture< void > map(Sequence &sequence, MapFunction function)
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
friend class const_iterator
Definition: qmap.h:369

◆ uniqueKeys()

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QList< Key > QMap< Key, T >::uniqueKeys ( ) const

Returns a list containing all the keys in the map in ascending order.

Since
4.2

Keys that occur multiple times in the map (because items were inserted with insertMulti(), or unite() was used) occur only once in the returned list.

See also
keys(), values()

Definition at line 798 of file qmap.h.

799 {
800  QList<Key> res;
801  res.reserve(size()); // May be too much, but assume short lifetime
802  const_iterator i = begin();
803  if (i != end()) {
804  for (;;) {
805  const Key &aKey = i.key();
806  res.append(aKey);
807  do {
808  if (++i == end())
809  goto break_out_of_outer_loop;
810  } while (!(aKey < i.key())); // loop while (key == i.key())
811  }
812  }
813 break_out_of_outer_loop:
814  return res;
815 }
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
friend class const_iterator
Definition: qmap.h:369

◆ unite()

template<class Key, class T>
Q_INLINE_TEMPLATE QMap< Key, T > & QMap< Key, T >::unite ( const QMap< Key, T > &  other)

Inserts all the items in the other map into this map.

If a key is common to both maps, the resulting map will contain the key multiple times.

See also
insertMulti()

Definition at line 625 of file qmap.h.

Referenced by QRegExpEngine::Box::cat(), QDBusMetaObject::createMetaObject(), and QRegExpEngine::Box::orx().

626 {
627  QMap<Key, T> copy(other);
628  const_iterator it = copy.constEnd();
629  const const_iterator b = copy.constBegin();
630  while (it != b) {
631  --it;
632  insertMulti(it.key(), it.value());
633  }
634  return *this;
635 }
#define it(className, varName)
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:595
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
friend class const_iterator
Definition: qmap.h:369

◆ upperBound() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::iterator QMap< Key, T >::upperBound ( const Key &  key)

Returns an iterator pointing to the item that immediately follows the last item with key key in the map.

If the map contains no item with key key, the function returns an iterator to the nearest item with a greater key.

Example:

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.upperBound(0); // returns iterator to (1, "one")
map.upperBound(1); // returns iterator to (5, "five")
map.upperBound(2); // returns iterator to (5, "five")
map.upperBound(10); // returns end()
map.upperBound(999); // returns end()
See also
qUpperBound(), lowerBound(), find()

Definition at line 918 of file qmap.h.

Referenced by QConfFileSettingsPrivate::ensureSectionParsed(), QGraphicsScenePrivate::filterEvent(), QGestureManager::filterEventThroughContexts(), and QGraphicsScenePrivate::removeSceneEventFilter().

919 {
920  detach();
921  return static_cast<QMapData::Node *>(const_cast<const QMap *>(this)->upperBound(akey));
922 }
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
iterator upperBound(const Key &key)
Returns an iterator pointing to the item that immediately follows the last item with key key in the m...
Definition: qmap.h:918
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ upperBound() [2/2]

template<class Key, class T >
Q_INLINE_TEMPLATE QMap< Key, T >::const_iterator QMap< Key, T >::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.

Definition at line 907 of file qmap.h.

908 {
909  QMapData::Node *update[QMapData::LastLevel + 1];
910  mutableFindNode(update, akey);
911  QMapData::Node *node = update[0]->forward[0];
912  while (node != e && !qMapLessThanKey<Key>(akey, concrete(node)->key))
913  node = node->forward[0];
914  return const_iterator(node);
915 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * mutableFindNode(QMapData::Node *update[], const Key &key) const
Definition: qmap.h:779
QMapData::Node * e
Definition: qmap.h:166
Node * forward[1]
Definition: qmap.h:65
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
friend class const_iterator
Definition: qmap.h:369

◆ value() [1/2]

template<class Key, class T >
Q_INLINE_TEMPLATE const T QMap< Key, T >::value ( const Key &  key) const

Returns the value associated with the key key.

If the map contains no item with key key, the function returns a default-constructed value. If there are multiple items for key in the map, the value of the most recently inserted one is returned.

See also
key(), values(), contains(), operator[]()

Definition at line 499 of file qmap.h.

Referenced by QWizardPrivate::_q_handleFieldObjectDestroyed(), QAxServerBase::ActiveXProc(), QRegExpEngine::addAnchors(), QRegExpEngine::Box::addAnchorsToEngine(), QTessellatorPrivate::addEdges(), QScriptDebuggerScriptsModel::addExtraScriptInfo(), QTessellatorPrivate::addIntersection(), QDir::addResourceSearchPath(), QAxEventSink::addSignal(), QSpanCollection::addSpan(), QCopChannel::answer(), QBuiltInMimes::canConvertFromMime(), QRegExpEngine::Box::cat(), QRegExpEngine::Box::catAnchor(), QXlibCursor::changeCursor(), QGestureManager::cleanupCachedGestures(), QWSServerPrivate::cleanupFonts(), QWindowsXPStylePrivate::cleanupHandleMap(), QNetworkManagerEngine::connectToId(), QTextCopyHelper::convertFormatIndex(), QBuiltInMimes::convertFromMime(), ControlList::data(), QGraphicsItem::data(), QAbstractItemViewPrivate::delegateForIndex(), QRegExpEngine::Box::dump(), QTessellatorPrivate::edgeInChain(), QAxEventSink::findProperty(), QDBusMetaObjectGenerator::findType(), QTextHtmlExporter::findUrlForImage(), QCalendarModel::formatForCell(), QGraphicsScenePrivate::gestureEventHandler(), QGestureManager::getGestureTargets(), QNetworkManagerSettingsConnection::getId(), QGenericEngine::getInterfaceFromId(), QCoreWlanEngine::getInterfaceFromId(), QConnmanEngine::getInterfaceFromId(), QNlaEngine::getInterfaceFromId(), QNetworkManagerSettingsConnection::getMacAddress(), QOfonoManagerInterface::getProperty(), QConnmanManagerInterface::getProperty(), QOfonoModemInterface::getProperty(), QConnmanProfileInterface::getProperty(), QOfonoNetworkRegistrationInterface::getProperty(), QOfonoNetworkOperatorInterface::getProperty(), QConnmanServiceInterface::getProperty(), QOfonoSimInterface::getProperty(), QConnmanTechnologyInterface::getProperty(), QOfonoDataConnectionManagerInterface::getProperty(), QOfonoPrimaryDataContextInterface::getProperty(), QOfonoSmsInterface::getProperty(), QNetworkManagerSettingsConnection::getSeenBssids(), QNetworkManagerSettingsConnection::getSsid(), QNetworkManagerSettingsConnection::getTimestamp(), QNetworkManagerSettingsConnection::getType(), QNetworkManagerSettingsConnection::getUuid(), QAxEventSink::Invoke(), QGestureEvent::isAccepted(), QNetworkManagerSettingsConnection::isAutoConnect(), QXmlSimpleReaderPrivate::isExpandedEntityValueTooLarge(), QSslCertificate::issuerInfo(), macValue(), QGraphicsScenePrivate::markDirty(), QRegExpMatchState::matchHere(), QBuiltInMimes::mimeForFormat(), QGraphicsItem::mouseMoveEvent(), QApplication::notify(), QTextDocumentPrivate::objectForIndex(), QAxEventSink::OnChanged(), QGtkStylePrivate::openFilename(), QGtkStylePrivate::openFilenames(), QRegExpEngine::parse(), QNetworkManagerEngine::parseConnection(), QDBusMetaObjectGenerator::parseMethods(), QAxMetaObject::parsePrototype(), QWSServer::processEventQueue(), QAxMetaObject::propertyType(), MetaObjectGenerator::propertyType(), QAxBase::propertyWritable(), QGraphicsItemCache::purge(), renameOverloads(), resolveClassName(), QSqlTableModelPrivate::revertCachedRow(), QGtkStylePrivate::saveFilename(), QCompletionEngine::saveInCache(), QWSServer::sendIMEvent(), QWSServerPrivate::sendKeyEventUnfiltered(), QGraphicsScenePrivate::sendMouseEvent(), QWSServerPrivate::sendMouseEventUnfiltered(), set_text(), QApplicationPrivate::setMaxWindowRect(), QAxBase::setPropertyBag(), QSslCertificate::subjectInfo(), QImageReader::text(), QApplicationPrivate::translateRawTouchEvent(), MetaObjectGenerator::tryCache(), QGestureManager::unregisterGestureRecognizer(), QIBaseDriver::unsubscribeFromNotificationImplementation(), QSpanCollection::updateInsertedColumns(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), and QConfFileSettingsPrivate::writeIniFile().

500 {
501  QMapData::Node *node;
502  if (d->size == 0 || (node = findNode(akey)) == e) {
503  return T();
504  } else {
505  return concrete(node)->value;
506  }
507 }
int size
Definition: qmap.h:73
QMapData::Node * e
Definition: qmap.h:166
QMapData * d
Definition: qmap.h:165
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481
T value
Definition: qmap.h:125

◆ value() [2/2]

template<class Key, class T>
Q_INLINE_TEMPLATE const T QMap< Key, T >::value ( const Key &  key,
const T &  defaultValue 
) const

If the map contains no item with key key, the function returns defaultValue.

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 510 of file qmap.h.

511 {
512  QMapData::Node *node;
513  if (d->size == 0 || (node = findNode(akey)) == e) {
514  return adefaultValue;
515  } else {
516  return concrete(node)->value;
517  }
518 }
int size
Definition: qmap.h:73
QMapData::Node * e
Definition: qmap.h:166
QMapData * d
Definition: qmap.h:165
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481
T value
Definition: qmap.h:125

◆ values() [1/2]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QList< T > QMap< Key, T >::values ( ) const

Returns a list containing all the values in the map, in ascending order of their keys.

If a key is associated with multiple values, all of its values will be in the list, and not just the most recently inserted one.

See also
keys(), value()

Definition at line 863 of file qmap.h.

Referenced by QScriptObjectSnapshot::capture(), QTest::QTouchEventSequence::commit(), QGestureManager::unregisterGestureRecognizer(), and QGestureManager::~QGestureManager().

864 {
865  QList<T> res;
866  res.reserve(size());
867  const_iterator i = begin();
868  while (i != end()) {
869  res.append(i.value());
870  ++i;
871  }
872  return res;
873 }
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
friend class const_iterator
Definition: qmap.h:369

◆ values() [2/2]

template<class Key, class T >
Q_OUTOFLINE_TEMPLATE QList< T > QMap< Key, 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.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
count(), insertMulti()

Definition at line 876 of file qmap.h.

877 {
878  QList<T> res;
879  QMapData::Node *node = findNode(akey);
880  if (node != e) {
881  do {
882  res.append(concrete(node)->value);
883  node = node->forward[0];
884  } while (node != e && !qMapLessThanKey<Key>(akey, concrete(node)->key));
885  }
886  return res;
887 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMapData::Node * e
Definition: qmap.h:166
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
Node * forward[1]
Definition: qmap.h:65
static Node * concrete(QMapData::Node *node)
Definition: qmap.h:177
QMapData::Node * findNode(const Key &key) const
Definition: qmap.h:481
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

Friends and Related Functions

◆ const_iterator

template<class Key, class T>
friend class const_iterator
friend

Definition at line 369 of file qmap.h.

◆ iterator

template<class Key, class T>
friend class iterator
friend

Definition at line 299 of file qmap.h.

◆ operator<<()

template<class Key, class T>
QDataStream & operator<< ( QDataStream out,
const QMap< Key, T > &  map 
)
related

Writes the map map to stream out.

This function requires the key and value types to implement operator<<().

See also
Format of the QDataStream operators

Definition at line 422 of file qdatastream.h.

423 {
424  out << quint32(map.size());
425  typename QMap<Key, T>::ConstIterator it = map.end();
426  typename QMap<Key, T>::ConstIterator begin = map.begin();
427  while (it != begin) {
428  --it;
429  out << it.key() << it.value();
430  }
431  return out;
432 }
#define it(className, varName)
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
unsigned int quint32
Definition: qglobal.h:938

◆ operator>>()

template<class Key, class T>
QDataStream & operator>> ( QDataStream in,
QMap< Key, T > &  map 
)
related

Reads a map from stream in into map.

This function requires the key and value types to implement operator>>().

See also
Format of the QDataStream operators

Definition at line 389 of file qdatastream.h.

394 {
395  QDataStream::Status oldStatus = in.status();
396  in.resetStatus();
397  map.clear();
398 
399  quint32 n;
400  in >> n;
401 
402  map.detach();
403  map.setInsertInOrder(true);
404  for (quint32 i = 0; i < n; ++i) {
405  if (in.status() != QDataStream::Ok)
406  break;
407 
408  aKey key;
409  aT value;
410  in >> key >> value;
411  map.insertMulti(key, value);
412  }
413  map.setInsertInOrder(false);
414  if (in.status() != QDataStream::Ok)
415  map.clear();
416  if (oldStatus != QDataStream::Ok)
417  in.setStatus(oldStatus);
418  return in;
419 }
Status status() const
Returns the status of the data stream.
void setInsertInOrder(bool ordered)
Definition: qmap.h:209
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
Status
This enum describes the current status of the data stream.
Definition: qdatastream.h:101
void setStatus(Status status)
Sets the status of the data stream to the status given.
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:595
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
void resetStatus()
Resets the status of the data stream.
unsigned int quint32
Definition: qglobal.h:938
void clear()
Removes all items from the map.
Definition: qmap.h:444

Properties

◆ @65

union { ... }

◆ d

template<class Key, class T>
QMapData* QMap< Key, T >::d

◆ e

template<class Key, class T>
QMapData::Node* QMap< Key, T >::e

Definition at line 166 of file qmap.h.


The documentation for this class was generated from the following files: