summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-18 11:26:52 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-18 12:43:27 +0200
commit8fec622c186d254bc9750606d54c32670a9046a5 (patch)
tree69d50f4da0ede588dda33bcda82a7f6af8155cb6
parent0b4522ae19d560881fdf85e8762c0d7f28310d50 (diff)
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 <chris.adams@jollamobile.com>
-rw-r--r--.qmake.conf2
-rw-r--r--src/contacts/qcontactdetail.cpp5
-rw-r--r--src/imports/contacts/qdeclarativecontactmodel.cpp18
-rw-r--r--src/imports/organizer/qdeclarativeorganizermodel.cpp18
-rw-r--r--src/organizer/qorganizeritemdetail.cpp5
-rw-r--r--src/versit/qvcardrestorehandler_p.cpp7
-rw-r--r--tests/auto/versit/qversit/tst_qversit.cpp8
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<int, QVariant> 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<QString, const QContactCollection*> 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<QString, QDeclarativeContactCollection*> 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<QString, const QOrganizerCollection*> 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<QString, QDeclarativeOrganizerCollection*> 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<QOrganizerItemDetail::DetailType>(detailType));
- QMapIterator<int, QVariant> 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<QContactDetail> 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<QContact> i(expectedContacts);
+ auto i = expectedContacts.cbegin();
foreach (QContact parsed, contacts) {
- QContact expected = i.next();
+ QContact expected = *i++;
QList<QContactDetail> 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<QOrganizerItem> i(expectedItems);
+ auto i = expectedItems.cbegin();
foreach (QOrganizerItem parsed, items) {
- QOrganizerItem expected = i.next();
+ QOrganizerItem expected = *i++;
QList<QOrganizerItemDetail> expectedDetails = expected.details();
foreach(QOrganizerItemDetail expectedDetail, expectedDetails) {
QOrganizerItemDetail::DetailType name = expectedDetail.type();