From 7f4d0405b409b1d3aa9d91e31972669576ec698c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 10 Oct 2018 18:58:22 +0200 Subject: Rename QList::swap(int, int) to swapItemsAt() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old name was confusing as it conflicted with QList::swap(QList &other), that was doing something completely different. Rename the method to swapItemsAt() which is a lot clearer. Change-Id: Iac77a1e790a7256766f83a24d2a243c880d875f4 Reviewed-by: Jędrzej Nowacki --- src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp | 2 +- src/corelib/tools/qlist.cpp | 7 +++++++ src/corelib/tools/qlist.h | 8 ++++++-- src/corelib/tools/qstringlist.cpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp index cc3f689710..0e746cd6e6 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlistdata.cpp @@ -146,7 +146,7 @@ list.move(1, 4); //! [12] QList list; list << "A" << "B" << "C" << "D" << "E" << "F"; -list.swap(1, 4); +list.swapItemsAt(1, 4); // list: ["A", "E", "C", "D", "B", "F"] //! [12] diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 0eed4a619e..1de93ff9e1 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -965,6 +965,13 @@ void **QListData::erase(void **xi) /*! \fn template void QList::swap(int i, int j) + \obsolete Use swapItemsAt() + + \sa move(), swapItemsAt() +*/ + +/*! \fn template void QList::swapItemsAt(int i, int j) + Exchange the item at index position \a i with the item at index position \a j. This function assumes that both \a i and \a j are at least 0 but less than size(). To avoid failure, test that both diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 073993ee56..fe8a1407e2 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -214,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::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; @@ -690,7 +694,7 @@ inline void QList::replace(int i, const T &t) } template -inline void QList::swap(int i, int j) +inline void QList::swapItemsAt(int i, int j) { Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(), "QList::swap", "index out of range"); diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index cf150c2a1b..ec6de08805 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -780,7 +780,7 @@ int QtPrivate::QStringList_removeDuplicates(QStringList *that) continue; ++setSize; if (j != i) - that->swap(i, j); + that->swapItemsAt(i, j); ++j; } if (n != j) -- cgit v1.2.3