📄 qmap.cpp
字号:
\sa value()*//*! \fn bool QMap::iterator::operator==(const iterator &other) const \fn bool QMap::iterator::operator==(const const_iterator &other) const Returns true if \a other points to the same item as this iterator; otherwise returns false. \sa operator!=()*//*! \fn bool QMap::iterator::operator!=(const iterator &other) const \fn bool QMap::iterator::operator!=(const const_iterator &other) const Returns true if \a other points to a different item than this iterator; otherwise returns false. \sa operator==()*//*! \fn QMap::iterator QMap::iterator::operator++() The prefix ++ operator (\c{++i}) advances the iterator to the next item in the map and returns an iterator to the new current item. Calling this function on QMap::end() leads to undefined results. \sa operator--()*//*! \fn QMap::iterator QMap::iterator::operator++(int) \overload The postfix ++ operator (\c{i++}) advances the iterator to the next item in the map and returns an iterator to the previously current item.*//*! \fn QMap::iterator QMap::iterator::operator--() The prefix -- operator (\c{--i}) makes the preceding item current and returns an iterator pointing to the new current item. Calling this function on QMap::begin() leads to undefined results. \sa operator++()*//*! \fn QMap::iterator QMap::iterator::operator--(int) \overload The prefix -- operator (\c{--i}) makes the preceding item current and returns an iterator pointing to the previously current item.*//*! \fn QMap::iterator QMap::iterator::operator+(int j) const Returns an iterator to the item at \a j positions forward from this iterator. (If \a j is negative, the iterator goes backward.) This operation can be slow for large \a j values. \sa operator-()*//*! \fn QMap::iterator QMap::iterator::operator-(int j) const Returns an iterator to the item at \a j positions backward from this iterator. (If \a j is negative, the iterator goes forward.) This operation can be slow for large \a j values. \sa operator+()*//*! \fn QMap::iterator &QMap::iterator::operator+=(int j) Advances the iterator by \a j items. (If \a j is negative, the iterator goes backward.) \sa operator-=(), operator+()*//*! \fn QMap::iterator &QMap::iterator::operator-=(int j) Makes the iterator go back by \a j items. (If \a j is negative, the iterator goes forward.) \sa operator+=(), operator-()*//*! \class QMap::const_iterator \brief The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap. QMap features both \l{STL-style iterators} and \l{Java-style iterators}. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity. QMap\<Key, T\>::const_iterator allows you to iterate over a QMap (or a QMultiMap). If you want to modify the QMap as you iterate over it, you must use QMap::iterator instead. It is generally good practice to use QMap::const_iterator on a non-const QMap as well, unless you need to change the QMap through the iterator. Const iterators are slightly faster, and can improve code readability. The default QMap::const_iterator constructor creates an uninitialized iterator. You must initialize it using a QMap function like QMap::constBegin(), QMap::constEnd(), or QMap::find() before you can start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a map: \code QMap<QString, int> map; map.insert("January", 1); map.insert("February", 2); ... map.insert("December", 12); QMap<QString, int>::const_iterator i; for (i = map.constBegin(); i != map.constEnd(); ++i) cout << i.key() << ": " << i.value() << endl; \endcode Unlike QHash, which stores its items in an arbitrary order, QMap stores its items ordered by key. Items that share the same key (because they were inserted using QMap::insertMulti()) will appear consecutively, from the most recently to the least recently inserted value. Multiple iterators can be used on the same map. If you add items to the map, existing iterators will remain valid. If you remove items from the map, iterators that point to the removed items will become dangling iterators. \sa QMap::iterator, QMapIterator*//*! \fn QMap::const_iterator::operator QMapData::Node *() const \internal*//*! \typedef QMap::const_iterator::difference_type \internal*//*! \typedef QMap::const_iterator::iterator_category \internal*//*! \typedef QMap::const_iterator::pointer \internal*//*! \typedef QMap::const_iterator::reference \internal*//*! \typedef QMap::const_iterator::value_type \internal*//*! \fn QMap::const_iterator::const_iterator() Constructs an uninitialized iterator. Functions like key(), value(), and operator++() must not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it. \sa QMap::constBegin() QMap::constEnd()*//*! \fn QMap::const_iterator::const_iterator(QMapData::Node *node) \internal*//*! \fn QMap::const_iterator::const_iterator(const iterator &other) Constructs a copy of \a other.*//*! \fn const Key &QMap::const_iterator::key() const Returns the current item's key. \sa value()*//*! \fn const T &QMap::const_iterator::value() const Returns the current item's value. \sa key(), operator*()*//*! \fn const T &QMap::const_iterator::operator*() const Returns the current item's value. Same as value(). \sa key()*//*! \fn const T *QMap::const_iterator::operator->() const Returns a pointer to the current item's value. \sa value()*//*! \fn bool QMap::const_iterator::operator==(const const_iterator &other) const Returns true if \a other points to the same item as this iterator; otherwise returns false. \sa operator!=()*//*! \fn bool QMap::const_iterator::operator!=(const const_iterator &other) const Returns true if \a other points to a different item than this iterator; otherwise returns false. \sa operator==()*//*! \fn QMap::const_iterator QMap::const_iterator::operator++() The prefix ++ operator (\c{++i}) advances the iterator to the next item in the map and returns an iterator to the new current item. Calling this function on QMap::end() leads to undefined results. \sa operator--()*//*! \fn QMap::const_iterator QMap::const_iterator::operator++(int) \overload The postfix ++ operator (\c{i++}) advances the iterator to the next item in the map and returns an iterator to the previously current item.*//*! \fn QMap::const_iterator &QMap::const_iterator::operator--() The prefix -- operator (\c{--i}) makes the preceding item current and returns an iterator pointing to the new current item. Calling this function on QMap::begin() leads to undefined results. \sa operator++()*//*! \fn QMap::const_iterator QMap::const_iterator::operator--(int) \overload The postfix -- operator (\c{i--}) makes the preceding item current and returns an iterator pointing to the previously current item.*//*! \fn QMap::const_iterator QMap::const_iterator::operator+(int j) const Returns an iterator to the item at \a j positions forward from this iterator. (If \a j is negative, the iterator goes backward.) This operation can be slow for large \a j values. \sa operator-()*//*! \fn QMap::const_iterator QMap::const_iterator::operator-(int j) const Returns an iterator to the item at \a j positions backward from this iterator. (If \a j is negative, the iterator goes forward.) This operation can be slow for large \a j values. \sa operator+()*//*! \fn QMap::const_iterator &QMap::const_iterator::operator+=(int j) Advances the iterator by \a j items. (If \a j is negative, the iterator goes backward.) This operation can be slow for large \a j values. \sa operator-=(), operator+()*//*! \fn QMap::const_iterator &QMap::const_iterator::operator-=(int j) Makes the iterator go back by \a j items. (If \a j is negative, the iterator goes forward.) This operation can be slow for large \a j values. \sa operator+=(), operator-()*//*! \fn QDataStream &operator<<(QDataStream &out, const QMap<Key, T> &map) \relates QMap Writes the map \a map to stream \a out. This function requires the key and value types to implement \c operator<<(). \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//*! \fn QDataStream &operator>>(QDataStream &in, QMap<Key, T> &map) \relates QMap Reads a map from stream \a in into \a map. This function requires the key and value types to implement \c operator>>(). \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//*! \class QMultiMap \brief The QMultiMap class is a convenience QMap subclass that provides multi-valued maps. \ingroup tools \ingroup shared \mainclass \reentrant QMultiMap\<Key, T\> is one of Qt's generic \l{container classes}. It inherits QMap and extends it with a few convenience functions that make it more suitable than QMap for storing multi-valued maps. A multi-valued map is a map that allows multiple values with the same key; QMap normally doesn't allow that, unless you call QMap::insertMulti(). Because QMultiMap inherits QMap, all of QMap's functionality also applies to QMultiMap. For example, you can use isEmpty() to test whether the map is empty, and you can traverse a QMultiMap using QMap's iterator classes (for example, QMapIterator). But in addition, it provides an insert() function that corresponds to QMap::insertMulti(), and a replace() function that corresponds to QMap::insert(). It also provides convenient operator+() and operator+=(). Example: \code QMultiMap<QString, int> map1, map2, map3; map1.insert("plenty", 100); map1.insert("plenty", 2000); // map1.size() == 2 map2.insert("plenty", 5000); // map2.size() == 1 map3 = map1 + map2; // map3.size() == 3 \endcode Unlike QMap, QMultiMap provides no operator[]. Use value() or replace() if you want to access the most recently inserted item with a certain key. If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>: \code QList<int> values = map.values("plenty"); for (int i = 0; i < values.size(); ++i) cout << values.at(i) << endl; \endcode The items that share the same key are available from most recently to least recently inserted. If you prefer the STL-style iterators, you can call find() to get the iterator for the first item with a key and iterate from there: \code QMultiMap<QString, int>::iterator i = map.find("plenty"); while (i != map.end() && i.key() == "plenty") { cout << i.value() << endl; ++i; } \endcode QMultiMap's key and value data types must be \l{assignable data types}. This covers most data types you are likely to encounter, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QMultiMap's key type must provide operator<(). See the QMap documentation for details. \sa QMap, QMapIterator, QMutableMapIterator, QMultiHash*//*! \fn QMultiMap::QMultiMap() Constructs an empty map.*//*! \fn QMultiMap::QMultiMap(const QMap<Key, T> &other) Constructs a copy of \a other (which can be a QMap or a QMultiMap). \sa operator=()*//*! \fn QMultiMap::iterator QMultiMap::replace(const Key &key, const T &value) Inserts a new item with the key \a key and a value of \a value. If there is already an item with the key \a key, that item's value is replaced with \a value. If there are multiple items with the key \a key, the most recently inserted item's value is replaced with \a value. \sa insert()*//*! \fn QMultiMap::iterator QMultiMap::insert(const Key &key, const T &value) Inserts a new item with the key \a key and a value of \a value. If there is already an item with the same key in the map, this function will simply create a new one. (This behavior is different from replace(), which overwrites the value of an existing item.) \sa replace()*//*! \fn QMultiMap &QMultiMap::operator+=(const QMultiMap &other) Inserts all the items in the \a other map into this map and returns a reference to this map. \sa insert(), operator+()*//*! \fn QMultiMap QMultiMap::operator+(const QMultiMap &other) const Returns a map that contains all the items in this map in addition to all the items in \a other. If a key is common to both maps, the resulting map will contain the key multiple times. \sa operator+=()*//*! \fn T &QMap::iterator::data() const Use value() instead.*//*! \fn const T &QMap::const_iterator::data() const Use value() instead.*//*! \fn iterator QMap::remove(iterator it) Use erase(\a it) instead.*//*! \fn void QMap::erase(const Key &key) Use remove(\a key) instead.*//*! \fn iterator QMap::insert(const Key &key, const T &value, bool overwrite); Use the two-argument insert() overload instead. If you don't want to overwrite, call contains() beforehand. \oldcode QMap<QString, int> map; ... map.insert("delay", 30000, false); \newcode QMap<QString, int> map; ... if (!map.contains("delay")) map.insert("delay", 30000); \endcode*//*! \fn iterator QMap::replace(const Key &key, const T &value) Use remove() then insert().*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -