Rename QList<T>::swap(int, int) to swapItemsAt()

The old name was confusing as it conflicted with
QList<T>::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 <jedrzej.nowacki@qt.io>
This commit is contained in:
Lars Knoll 2018-10-10 18:58:22 +02:00
parent 972f8845a8
commit 7f4d0405b4
8 changed files with 20 additions and 9 deletions

View File

@ -146,7 +146,7 @@ list.move(1, 4);
//! [12]
QList<QString> list;
list << "A" << "B" << "C" << "D" << "E" << "F";
list.swap(1, 4);
list.swapItemsAt(1, 4);
// list: ["A", "E", "C", "D", "B", "F"]
//! [12]

View File

@ -965,6 +965,13 @@ void **QListData::erase(void **xi)
/*! \fn template <class T> void QList<T>::swap(int i, int j)
\obsolete Use swapItemsAt()
\sa move(), swapItemsAt()
*/
/*! \fn template <class T> void QList<T>::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

View File

@ -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<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;
@ -690,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");

View File

@ -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)

View File

@ -526,7 +526,7 @@ bool QImageReaderPrivate::initHandler()
// Try the most probable extension first
int currentFormatIndex = extensions.indexOf(format.toLower());
if (currentFormatIndex > 0)
extensions.swap(0, currentFormatIndex);
extensions.swapItemsAt(0, currentFormatIndex);
}
int currentExtension = 0;

View File

@ -534,7 +534,7 @@ void QPlatformIntegration::setPrimaryScreen(QPlatformScreen *newPrimary)
if (idx == 0)
return;
QGuiApplicationPrivate::screen_list.swap(0, idx);
QGuiApplicationPrivate::screen_list.swapItemsAt(0, idx);
emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
}

View File

@ -208,7 +208,7 @@ void QXcbConnection::updateScreen(QXcbScreen *screen, const xcb_randr_output_cha
const int idx = m_screens.indexOf(screen);
if (idx > 0) {
qAsConst(m_screens).first()->setPrimary(false);
m_screens.swap(0, idx);
m_screens.swapItemsAt(0, idx);
}
screen->virtualDesktop()->setPrimaryScreen(screen);
QXcbIntegration::instance()->setPrimaryScreen(screen);
@ -260,7 +260,7 @@ void QXcbConnection::destroyScreen(QXcbScreen *screen)
newPrimary->setPrimary(true);
const int idx = m_screens.indexOf(newPrimary);
if (idx > 0)
m_screens.swap(0, idx);
m_screens.swapItemsAt(0, idx);
QXcbIntegration::instance()->setPrimaryScreen(newPrimary);
}

View File

@ -151,7 +151,7 @@ inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphi
if (order == Qt::DescendingOrder) {
const int n = items->size();
for (int i = 0; i < n / 2; ++i)
items->swap(i, n - i - 1);
items->swapItemsAt(i, n - i - 1);
}
}