diff options
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 49ccbc9c9f..fe8a1407e2 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -45,6 +45,7 @@ #include <QtCore/qrefcount.h> #include <QtCore/qarraydata.h> #include <QtCore/qhashfunctions.h> +#include <QtCore/qvector.h> #include <iterator> #include <list> @@ -213,7 +214,11 @@ public: T takeFirst(); T takeLast(); void move(int from, int to); - void swap(int i, int j); + void swapItemsAt(int i, int j); +#if QT_DEPRECATED_SINCE(5, 13) && QT_VERSION < QT_VERSION_CHECK(6,0,0) + QT_DEPRECATED_X("Use QList<T>::swapItemsAt()") + void swap(int i, int j) { swapItemsAt(i, j); } +#endif int indexOf(const T &t, int from = 0) const; int lastIndexOf(const T &t, int from = -1) const; bool contains(const T &t) const; @@ -689,7 +694,7 @@ inline void QList<T>::replace(int i, const T &t) } template <typename T> -inline void QList<T>::swap(int i, int j) +inline void QList<T>::swapItemsAt(int i, int j) { Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(), "QList<T>::swap", "index out of range"); @@ -1051,6 +1056,37 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co t)); } +template <typename T> +Q_OUTOFLINE_TEMPLATE QVector<T> QList<T>::toVector() const +{ + QVector<T> result(size()); + for (int i = 0; i < size(); ++i) + result[i] = at(i); + return result; +} + +template <typename T> +QList<T> QList<T>::fromVector(const QVector<T> &vector) +{ + return vector.toList(); +} + +template <typename T> +Q_OUTOFLINE_TEMPLATE QList<T> QVector<T>::toList() const +{ + QList<T> result; + result.reserve(size()); + for (int i = 0; i < size(); ++i) + result.append(at(i)); + return result; +} + +template <typename T> +QVector<T> QVector<T>::fromList(const QList<T> &list) +{ + return list.toVector(); +} + Q_DECLARE_SEQUENTIAL_ITERATOR(List) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) |