diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2013-10-05 03:48:45 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-11 18:47:27 +0200 |
commit | 059857d4d5dc5862d0135c839e7dabaa7331e4b5 (patch) | |
tree | f7452bccc8493d88927ed5cc56d49ce7138436b7 | |
parent | 0e96e47debd1d8c48d1d23fd51c9ee05f61c80e0 (diff) |
QVector: add some functions missing for QList compat
Eases migration from QList to QVector.
Had to rename the 'length' parameter to mid() to suppress
-Wshadow warnings.
Task-number: QTBUG-3781
Change-Id: I755c6caefe4de81ea42a81b1c76aab728e639613
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | src/corelib/tools/qvector.cpp | 38 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 23 |
2 files changed, 52 insertions, 9 deletions
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 69b656c191..11990d30b2 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -562,6 +562,44 @@ \sa insert(), replace(), fill() */ +/*! \fn void QVector::removeAt(int i) + \since 5.2 + + Equivalent to + \code + remove(i); + \endcode + + Provided for compatibility with QList. + + \sa remove(int), QList::removeAt(int) +*/ + +/*! \fn int QVector::length() const + \since 5.2 + + Same as size() and count(). + + Provided for compatibility with QList. + + \sa size(), count(), QList::length() +*/ + +/*! \fn T QVector::takeAt(int i) + \since 5.2 + + Equivalent to + \code + T t = at(i); + remove(i); + return t; + \endcode + + Provided for compatibility with QList. + + \sa takeFirst(), takeLast(), QList::takeAt(int) +*/ + /*! \fn void QVector::removeFirst() \since 5.1 Removes the first item in the vector. Calling this function is diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 3d86440fcd..f56511edbf 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -152,6 +152,11 @@ public: bool contains(const T &t) const; int count(const T &t) const; + // QList compatibility + void removeAt(int i) { remove(i); } + int length() const { return size(); } + T takeAt(int i) { T t = at(i); remove(i); return t; } + // STL-style typedef typename Data::iterator iterator; typedef typename Data::const_iterator const_iterator; @@ -187,7 +192,7 @@ public: inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } - QVector<T> mid(int pos, int length = -1) const; + QVector<T> mid(int pos, int len = -1) const; T value(int i) const; T value(int i, const T &defaultValue) const; @@ -772,17 +777,17 @@ int QVector<T>::count(const T &t) const } template <typename T> -Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int length) const +Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int len) const { - if (length < 0) - length = size() - pos; - if (pos == 0 && length == size()) + if (len < 0) + len = size() - pos; + if (pos == 0 && len == size()) return *this; - if (pos + length > size()) - length = size() - pos; + if (pos + len > size()) + len = size() - pos; QVector<T> copy; - copy.reserve(length); - for (int i = pos; i < pos + length; ++i) + copy.reserve(len); + for (int i = pos; i < pos + len; ++i) copy += at(i); return copy; } |