From 8fec622c186d254bc9750606d54c32670a9046a5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 18 Jun 2019 11:26:52 +0200 Subject: Eradicate Java-style iterators and mark the module free of them Java-style iterators are scheduled for deprecation, or at the very least banned from use in Qt code. Change-Id: I58491db446ecaba2007f7e3fb45a9784635391db Reviewed-by: Christopher Adams --- .qmake.conf | 2 ++ src/contacts/qcontactdetail.cpp | 5 +---- src/imports/contacts/qdeclarativecontactmodel.cpp | 18 +++++++----------- src/imports/organizer/qdeclarativeorganizermodel.cpp | 18 +++++++----------- src/organizer/qorganizeritemdetail.cpp | 5 +---- src/versit/qvcardrestorehandler_p.cpp | 7 +++---- tests/auto/versit/qversit/tst_qversit.cpp | 8 ++++---- 7 files changed, 25 insertions(+), 38 deletions(-) diff --git a/.qmake.conf b/.qmake.conf index 8840bd92d..effd89836 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,5 @@ load(qt_build_config) +DEFINES += QT_NO_JAVA_STYLE_ITERATORS + MODULE_VERSION = 0.0.0 diff --git a/src/contacts/qcontactdetail.cpp b/src/contacts/qcontactdetail.cpp index df6ef769f..8671484a1 100644 --- a/src/contacts/qcontactdetail.cpp +++ b/src/contacts/qcontactdetail.cpp @@ -344,11 +344,8 @@ QDataStream& operator>>(QDataStream& in, QContactDetail& detail) QContactDetail::AccessConstraints accessConstraints(accessConstraintsInt); detail.d->m_access = accessConstraints; - QMapIterator it(values); - while (it.hasNext()) { - it.next(); + for (auto it = values.cbegin(), end = values.cend(); it != end; ++it) detail.setValue(it.key(), it.value()); - } } else { in.setStatus(QDataStream::ReadCorruptData); } diff --git a/src/imports/contacts/qdeclarativecontactmodel.cpp b/src/imports/contacts/qdeclarativecontactmodel.cpp index 00d16e78a..27e331dce 100644 --- a/src/imports/contacts/qdeclarativecontactmodel.cpp +++ b/src/imports/contacts/qdeclarativecontactmodel.cpp @@ -913,25 +913,21 @@ void QDeclarativeContactModel::collectionsFetched() declCollections.insert(declCollection->collection().id().toString(), declCollection); } // go tables through - QHashIterator collIterator(collections); - while (collIterator.hasNext()) { - collIterator.next(); - if (declCollections.contains(collIterator.key())) { + for (auto it = collections.cbegin(), end = collections.cend(); it != end; ++it) { + if (declCollections.contains(it.key())) { // collection on both sides, update the declarative collection - declCollections.value(collIterator.key())->setCollection(*collections.value(collIterator.key())); + declCollections.value(it.key())->setCollection(*it.value()); } else { // new collection, add it to declarative collection list QDeclarativeContactCollection* declCollection = new QDeclarativeContactCollection(this); - declCollection->setCollection(*collections.value(collIterator.key())); + declCollection->setCollection(*it.value()); d->m_collections.append(declCollection); } } - QHashIterator declCollIterator(declCollections); - while (declCollIterator.hasNext()) { - declCollIterator.next(); - if (!collections.contains(declCollIterator.key())) { + for (auto it = declCollections.cbegin(), end = declCollections.cend(); it != end; ++it) { + if (!collections.contains(it.key())) { // collection deleted on the backend side, delete from declarative collection list - QDeclarativeContactCollection* toBeDeletedColl = declCollections.value(declCollIterator.key()); + QDeclarativeContactCollection* toBeDeletedColl = it.value(); d->m_collections.removeOne(toBeDeletedColl); toBeDeletedColl->deleteLater(); } diff --git a/src/imports/organizer/qdeclarativeorganizermodel.cpp b/src/imports/organizer/qdeclarativeorganizermodel.cpp index 98889f568..c191f37aa 100644 --- a/src/imports/organizer/qdeclarativeorganizermodel.cpp +++ b/src/imports/organizer/qdeclarativeorganizermodel.cpp @@ -1674,25 +1674,21 @@ void QDeclarativeOrganizerModel::collectionsFetched() declCollections.insert(declCollection->collection().id().toString(), declCollection); } // go tables through - QHashIterator collIterator(collections); - while (collIterator.hasNext()) { - collIterator.next(); - if (declCollections.contains(collIterator.key())) { + for (auto it = collections.cbegin(), end = collections.cend(); it != end; ++it) { + if (declCollections.contains(it.key())) { // collection on both sides, update the declarative collection - declCollections.value(collIterator.key())->setCollection(*collections.value(collIterator.key())); + declCollections.value(it.key())->setCollection(*it.value()); } else { // new collection, add it to declarative collection list QDeclarativeOrganizerCollection* declCollection = new QDeclarativeOrganizerCollection(this); - declCollection->setCollection(*collections.value(collIterator.key())); + declCollection->setCollection(*it.value()); d->m_collections.append(declCollection); } } - QHashIterator declCollIterator(declCollections); - while (declCollIterator.hasNext()) { - declCollIterator.next(); - if (!collections.contains(declCollIterator.key())) { + for (auto it = declCollections.cbegin(), end = declCollections.cend(); it != end; ++it) { + if (!collections.contains(it.key())) { // collection deleted on the backend side, delete from declarative collection list - QDeclarativeOrganizerCollection* toBeDeletedColl = declCollections.value(declCollIterator.key()); + QDeclarativeOrganizerCollection* toBeDeletedColl = it.value(); d->m_collections.removeOne(toBeDeletedColl); toBeDeletedColl->deleteLater(); } diff --git a/src/organizer/qorganizeritemdetail.cpp b/src/organizer/qorganizeritemdetail.cpp index 277f0bc39..431a59b0a 100644 --- a/src/organizer/qorganizeritemdetail.cpp +++ b/src/organizer/qorganizeritemdetail.cpp @@ -311,11 +311,8 @@ Q_ORGANIZER_EXPORT QDataStream &operator>>(QDataStream &in, QOrganizerItemDetail detail = QOrganizerItemDetail(static_cast(detailType)); - QMapIterator it(values); - while (it.hasNext()) { - it.next(); + for (auto it = values.cbegin(), end = values.cend(); it != end; ++it) detail.setValue(it.key(), it.value()); - } } else { in.setStatus(QDataStream::ReadCorruptData); } diff --git a/src/versit/qvcardrestorehandler_p.cpp b/src/versit/qvcardrestorehandler_p.cpp index 0e9f33ae1..b05ab5e93 100644 --- a/src/versit/qvcardrestorehandler_p.cpp +++ b/src/versit/qvcardrestorehandler_p.cpp @@ -149,10 +149,9 @@ bool QVCardRestoreHandler::propertyProcessed( detail.setValue(fieldName.toInt(), deserializeValue(property)); // Replace the equivalent detail in updatedDetails with the new one - QMutableListIterator it(*updatedDetails); - while (it.hasNext()) { - if (it.next().key() == detail.key()) { - it.remove(); + for (auto it = updatedDetails->begin(), end = updatedDetails->end(); it != end; ++it) { + if (it->key() == detail.key()) { + updatedDetails->erase(it); break; } } diff --git a/tests/auto/versit/qversit/tst_qversit.cpp b/tests/auto/versit/qversit/tst_qversit.cpp index 2b8ed0c8a..642816436 100644 --- a/tests/auto/versit/qversit/tst_qversit.cpp +++ b/tests/auto/versit/qversit/tst_qversit.cpp @@ -136,9 +136,9 @@ void tst_QVersit::testImportVCardFiles() if (expectedContacts.size() > 0) { QCOMPARE(contacts.size(), expectedContacts.size()); - QListIterator i(expectedContacts); + auto i = expectedContacts.cbegin(); foreach (QContact parsed, contacts) { - QContact expected = i.next(); + QContact expected = *i++; QList expectedDetails = expected.details(); foreach(QContactDetail expectedDetail, expectedDetails) { QContactDetail::DetailType type = expectedDetail.type(); @@ -588,9 +588,9 @@ void tst_QVersit::testImportICalFiles() if (expectedItems.size() > 0) { QCOMPARE(items.size(), expectedItems.size()); - QListIterator i(expectedItems); + auto i = expectedItems.cbegin(); foreach (QOrganizerItem parsed, items) { - QOrganizerItem expected = i.next(); + QOrganizerItem expected = *i++; QList expectedDetails = expected.details(); foreach(QOrganizerItemDetail expectedDetail, expectedDetails) { QOrganizerItemDetail::DetailType name = expectedDetail.type(); -- cgit v1.2.3