Qt 4.8
|
The QMap class is a template class that provides a skip-list-based dictionary. More...
#include <qdatastream.h>
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... | |
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 Types | |
typedef QMapNode< Key, T > | Node |
typedef QMapPayloadNode< Key, T > | PayloadNode |
Private Functions | |
void | detach_helper () |
QMapData::Node * | findNode (const Key &key) const |
void | freeData (QMapData *d) |
QMapData::Node * | mutableFindNode (QMapData::Node *update[], const Key &key) const |
QMapData::Node * | node_create (QMapData *d, QMapData::Node *update[], const Key &key, const T &value) |
Static Private Functions | |
static int | alignment () |
static Node * | concrete (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.) | |
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 QMap class is a template class that provides a skip-list-based dictionary.
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[]():
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():
To look up a value, use operator[]() or value():
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():
There is also a value() overload that uses its second argument as a default value if there is no item with the specified key:
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:
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:
Here's the same code, but using an STL-style iterator this time:
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:
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>:
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:
If you only need to extract the values from a map (not the keys), you can also use foreach:
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:
In the example, we start by comparing the employees' names. If they're equal, we compare their dates of birth to break the tie.
Definition at line 67 of file qdatastream.h.
QMap< Key, T >::ConstIterator |
Qt-style synonym for QMap::const_iterator.
QMap< Key, T >::difference_type |
Qt-style synonym for QMap::iterator.
QMap< Key, T >::mapped_type |
|
private |
Constructs an empty map.
Definition at line 182 of file qmap.h.
Referenced by QMap< int, QFrameInfo >::operator==().
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.
Definition at line 183 of file qmap.h.
|
explicit |
|
inlinestaticprivate |
Definition at line 170 of file qmap.h.
|
inline |
Returns an STL-style iterator pointing to the first item in the map.
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().
|
inline |
Q_INLINE_TEMPLATE void QMap< Key, T >::clear | ( | ) |
Removes all items from the map.
Definition at line 444 of file qmap.h.
Referenced by classIDL(), QSqlTableModelPrivate::clear(), QSpanCollection::clear(), QTextDocumentPrivate::clear(), QFontCache::clear(), QConfFileSettingsPrivate::clear(), QSqlTableModelPrivate::clearCache(), QTextDocument::clone(), QIBaseDriver::close(), QConfFileSettingsPrivate::ensureAllSectionsParsed(), QScanThread::getUserConfigurations(), QXmlSimpleReaderPrivate::init(), QCompletionModel::invalidate(), operator>>(), QAxServerBase::removeMenu(), QMoviePrivate::reset(), QImageReader::setDevice(), QConfFileSettingsPrivate::syncConfFile(), QSpanCollection::updateRemovedColumns(), QSpanCollection::updateRemovedRows(), and QTest::QTouchEventSequence::~QTouchEventSequence().
|
inlinestaticprivate |
Definition at line 177 of file qmap.h.
|
inline |
Returns a const STL-style iterator pointing to the first item in the map.
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().
|
inline |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map.
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().
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.
If the map contains no item with key key, the function returns constEnd().
Definition at line 612 of file qmap.h.
Referenced by QWidgetAnimator::animate(), QMultiMap< QString, Method >::operator+(), and QConfFileSettingsPrivate::writeIniFile().
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.
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().
Q_INLINE_TEMPLATE int QMap< Key, T >::count | ( | const Key & | key | ) | const |
Returns the number of items associated with key key.
Definition at line 539 of file qmap.h.
Referenced by compare(), QXmlSimpleReaderPrivate::insertXmlRef(), MetaObjectGenerator::metaObject(), QCompletionEngine::saveInCache(), and QCss::StyleSelector::styleRulesForNode().
|
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+().
|
inline |
Detaches this map from any other maps with which it may share data.
Definition at line 205 of file qmap.h.
Referenced by operator>>().
|
private |
Definition at line 752 of file qmap.h.
|
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.
|
inline |
Returns an STL-style iterator pointing to the imaginary item after the last item in the map.
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().
|
inline |
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.
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().
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:
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().
Q_INLINE_TEMPLATE QMap< Key, T >::const_iterator QMap< Key, T >::find | ( | const Key & | key | ) | const |
|
private |
Definition at line 481 of file qmap.h.
|
private |
Definition at line 642 of file qmap.h.
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.
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().
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.)
Definition at line 595 of file qmap.h.
Referenced by QGestureManager::filterEvent(), QMultiMap< QString, Method >::insert(), QCss::StyleSelector::matchRule(), operator>>(), and QGestureManager::registerGestureRecognizer().
|
inline |
|
inline |
Returns true if the map contains no items; otherwise returns false.
Definition at line 203 of file qmap.h.
Referenced by QWidgetAnimator::animating(), QSpanCollection::cleanSpanSubIndex(), QDBusMetaObject::createMetaObject(), QConfFileSettingsPrivate::ensureSectionParsed(), QScriptDebuggerCommandExecutor::execute(), QGestureManager::filterEvent(), QImageReaderPrivate::getText(), QDragManager::hasCustomDragCursors(), QComboBox::insertItem(), QSslCertificate::issuerInfo(), QGraphicsItem::mouseMoveEvent(), QRegExpEngine::parse(), QDBusIntrospection::parseInterface(), QTessellatorPrivate::processIntersections(), MetaObjectGenerator::readEnumInfo(), set_text(), QSslCertificate::subjectInfo(), QConfFileSettingsPrivate::syncConfFile(), QApplicationPrivate::translateRawTouchEvent(), QClipboardINCRTransaction::~QClipboardINCRTransaction(), and QGraphicsItem::~QGraphicsItem().
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.
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().
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.
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.
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().
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().
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.
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:
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:
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().
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.
|
private |
Definition at line 779 of file qmap.h.
|
private |
Definition at line 451 of file qmap.h.
|
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==()
.
Q_INLINE_TEMPLATE QMap< Key, T > & QMap< Key, T >::operator= | ( | const QMap< Key, T > & | other | ) |
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==()
.
Definition at line 925 of file qmap.h.
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.
Definition at line 527 of file qmap.h.
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.
|
inlinestaticprivate |
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.
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().
|
inline |
Definition at line 209 of file qmap.h.
Referenced by operator>>().
|
inline |
Definition at line 207 of file qmap.h.
|
inline |
Returns the number of (key, value) pairs in the map.
Definition at line 201 of file qmap.h.
Referenced by QIBaseDriver::close(), macValue(), operator<<(), QMap< int, QFrameInfo >::operator==(), QXmlSimpleReaderPrivate::parseDoctype(), QXmlSimpleReaderPrivate::processElementETagBegin2(), set_text(), QFontCache::timerEvent(), QConfFileSettingsPrivate::writeIniFile(), and QConfFileSettingsPrivate::writePlistFile().
Swaps map other with this map.
This operation is very fast and never fails.
Definition at line 192 of file qmap.h.
Referenced by QMultiMap< QString, Method >::swap().
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.
Definition at line 692 of file qmap.h.
Referenced by QWSServerPrivate::invokeDefineCursor(), QFSFileEnginePrivate::map(), QApplicationPrivate::translateRawTouchEvent(), QGestureManager::unregisterGestureRecognizer(), and QLibraryPrivate::~QLibraryPrivate().
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.
Q_OUTOFLINE_TEMPLATE QList< Key > QMap< Key, T >::uniqueKeys | ( | ) | 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) occur only once in the returned list.
Definition at line 798 of file qmap.h.
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.
Definition at line 625 of file qmap.h.
Referenced by QRegExpEngine::Box::cat(), QDBusMetaObject::createMetaObject(), and QRegExpEngine::Box::orx().
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:
Definition at line 918 of file qmap.h.
Referenced by QConfFileSettingsPrivate::ensureSectionParsed(), QGraphicsScenePrivate::filterEvent(), QGestureManager::filterEventThroughContexts(), and QGraphicsScenePrivate::removeSceneEventFilter().
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.
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.
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().
Q_INLINE_TEMPLATE const T QMap< Key, T >::value | ( | const Key & | key, |
const T & | defaultValue | ||
) | const |
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.
Definition at line 863 of file qmap.h.
Referenced by QScriptObjectSnapshot::capture(), QTest::QTouchEventSequence::commit(), QGestureManager::unregisterGestureRecognizer(), and QGestureManager::~QGestureManager().
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.
Definition at line 876 of file qmap.h.
|
friend |
|
related |
Writes the map map to stream out.
This function requires the key and value types to implement operator<<()
.
Definition at line 422 of file qdatastream.h.
|
related |
Reads a map from stream in into map.
This function requires the key and value types to implement operator>>()
.
Definition at line 389 of file qdatastream.h.
union { ... } |
Definition at line 165 of file qmap.h.
Referenced by QMap< int, QFrameInfo >::isSharedWith(), QMap< int, QFrameInfo >::operator=(), QMap< int, QFrameInfo >::operator==(), QMap< int, QFrameInfo >::swap(), and QMap< int, QFrameInfo >::~QMap().
QMapData::Node* QMap< Key, T >::e |