From 44757c534b950e2fca2d56d0ab4228b4123cf080 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 10 Jul 2019 15:45:10 +0200 Subject: Eradicate Java-style iterators and mark the module free of them ... and of QLinkedList Java-style iterators are going to be deprecated, or at the very least banned from use in Qt code. Ditto QLinkedList. Unfortunately, the module contains more than 120 uses of Q_FOREACH, even though, according to my sources, its use was banned in Qt implementation from the get-go. So QT_NO_FOREACH is currently not an option. Change-Id: I0f05e9c78dda259b0eac1bcdfc7dddfcddc4b908 Reviewed-by: Allan Sandfeld Jensen --- .../qdeclarativeplacecontentmodel.cpp | 25 +++++++++------------- .../qdeclarativesearchresultmodel.cpp | 11 +++------- src/location/doc/snippets/places/requesthandler.h | 4 ++-- src/location/places/qplace.cpp | 5 +---- 4 files changed, 16 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp b/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp index 1920583b..3d64d299 100644 --- a/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp @@ -149,10 +149,7 @@ void QDeclarativePlaceContentModel::initializeCollection(int totalCount, const Q int initialCount = m_contentCount; clearData(); - QMapIterator i(collection); - while (i.hasNext()) { - i.next(); - + for (auto i = collection.cbegin(), end = collection.cend(); i != end; ++i) { const QPlaceContent &content = i.value(); if (content.type() != m_type) continue; @@ -317,11 +314,9 @@ void QDeclarativePlaceContentModel::fetchFinished() QPlaceContent::Collection contents = reply->content(); //find out which indexes are new and which ones have changed. - QMapIterator it(contents); QList changedIndexes; QList newIndexes; - while (it.hasNext()) { - it.next(); + for (auto it = contents.cbegin(), end = contents.cend(); it != end; ++it) { if (!m_content.contains(it.key())) newIndexes.append(it.key()); else if (it.value() != m_content.value(it.key())) @@ -330,14 +325,14 @@ void QDeclarativePlaceContentModel::fetchFinished() //insert new indexes in blocks where within each //block, the indexes are consecutive. - QListIterator newIndexesIter(newIndexes); int startIndex = -1; - while (newIndexesIter.hasNext()) { - int currentIndex = newIndexesIter.next(); + for (auto it = newIndexes.cbegin(), end = newIndexes.cend(); it != end; ++it) { + int currentIndex = *it; if (startIndex == -1) startIndex = currentIndex; - if (!newIndexesIter.hasNext() || (newIndexesIter.hasNext() && (newIndexesIter.peekNext() > (currentIndex + 1)))) { + auto next = std::next(it); + if (next == end || *next > (currentIndex + 1)) { beginInsertRows(QModelIndex(),startIndex,currentIndex); for (int i = startIndex; i <= currentIndex; ++i) { const QPlaceContent &content = contents.value(i); @@ -360,13 +355,13 @@ void QDeclarativePlaceContentModel::fetchFinished() //modify changed indexes in blocks where within each //block, the indexes are consecutive. startIndex = -1; - QListIterator changedIndexesIter(changedIndexes); - while (changedIndexesIter.hasNext()) { - int currentIndex = changedIndexesIter.next(); + for (auto it = changedIndexes.cbegin(), end = changedIndexes.cend(); it != end; ++it) { + int currentIndex = *it; if (startIndex == -1) startIndex = currentIndex; - if (!changedIndexesIter.hasNext() || (changedIndexesIter.hasNext() && changedIndexesIter.peekNext() > (currentIndex + 1))) { + auto next = std::next(it); + if (next == end || *next > (currentIndex + 1)) { for (int i = startIndex; i <= currentIndex; ++i) { const QPlaceContent &content = contents.value(i); m_content.insert(i, content); diff --git a/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index c620b9f7..9129731b 100644 --- a/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -963,20 +963,15 @@ void QDeclarativeSearchResultModel::placeRemoved(const QString &placeId) QList QDeclarativeSearchResultModel::resultsFromPages() const { QList res; - QMapIterator> i(m_pages); - while (i.hasNext()) { - i.next(); - res.append(i.value()); - } + for (const auto &e : m_pages) + res.append(e); return res; } void QDeclarativeSearchResultModel::removePageRow(int row) { - QMutableMapIterator> i(m_pages); int scanned = 0; - while (i.hasNext()) { - i.next(); + for (auto i = m_pages.begin(), end = m_pages.end(); i != end; ++i) { QList &page = i.value(); scanned += page.size(); if (row >= scanned) diff --git a/src/location/doc/snippets/places/requesthandler.h b/src/location/doc/snippets/places/requesthandler.h index e5ee0d00..9aa5fe76 100644 --- a/src/location/doc/snippets/places/requesthandler.h +++ b/src/location/doc/snippets/places/requesthandler.h @@ -358,8 +358,8 @@ public slots: //! [Image handler] void handleImagesReply() { if (contentReply->error() == QPlaceReply::NoError) { - QMapIterator iter(contentReply->content()); - while (iter.hasNext()) { + const auto content = contentReply->content(); + for (auto iter = content.cbegin(), end = content.cend(); iter != end; ++iter) { qDebug() << "Index: " << iter.key(); QPlaceImage image = iter.value(); qDebug() << image.url(); diff --git a/src/location/places/qplace.cpp b/src/location/places/qplace.cpp index ab115b5b..4e3e36d3 100644 --- a/src/location/places/qplace.cpp +++ b/src/location/places/qplace.cpp @@ -297,11 +297,8 @@ void QPlace::setContent(QPlaceContent::Type type, const QPlaceContent::Collectio */ void QPlace::insertContent(QPlaceContent::Type type, const QPlaceContent::Collection &content) { - QMapIterator iter(content); - while (iter.hasNext()) { - iter.next(); + for (auto iter = content.cbegin(), end = content.cend(); iter != end; ++iter) d_ptr->m_contentCollections[type].insert(iter.key(), iter.value()); - } } /*! -- cgit v1.2.1