diff options
author | Chris Adams <chris.adams@qinetic.com.au> | 2020-10-01 16:16:22 +1000 |
---|---|---|
committer | Chris Adams <chris.adams@qinetic.com.au> | 2020-11-02 13:18:27 +1000 |
commit | f337e281e28904741a3b1ac23d15c3a83ef2bbc9 (patch) | |
tree | a207d3fa8e0760bdfc7b18d63b03e8fce16cfb8b | |
parent | cc293592e4a430e42d6086ca5971ab4ac0222b81 (diff) |
Fix QList-from-QSet conversions
Change-Id: I93a8500e4555bb33760f4bd73be8d0af0f1422f4
Reviewed-by: Pekka Vuorela <pvuorela@iki.fi>
11 files changed, 37 insertions, 33 deletions
diff --git a/src/contacts/qcontactmanagerenginev2wrapper_p.cpp b/src/contacts/qcontactmanagerenginev2wrapper_p.cpp index e3b8c0255..974167407 100644 --- a/src/contacts/qcontactmanagerenginev2wrapper_p.cpp +++ b/src/contacts/qcontactmanagerenginev2wrapper_p.cpp @@ -313,7 +313,7 @@ bool PartialSaveRequestController::start() // Special case for the case where every contact is new - we don't need to bother fetching // any existing contacts - just prune them down to the mask and do the save request. QList<QContact> contactsToSave; - QSet<QContactDetail::DetailType> mask(request()->typeMask().toSet()); + QSet<QContactDetail::DetailType> mask(request()->typeMask().constBegin(), request()->typeMask().constEnd()); for (int i = 0; i < newContactIndices.count(); i++) { QContact contactToSave; partiallyCopyDetails(&contactToSave, contacts[newContactIndices[i]], mask); @@ -341,7 +341,7 @@ void PartialSaveRequestController::handleFinishedSubRequest(QContactAbstractRequ QMap<int, QContactManager::Error> fetchErrors(cfbir->errorMap()); QList<QContact> existingContacts(cfbir->contacts()); QList<QContact> contacts(request()->contacts()); - QSet<QContactDetail::DetailType> mask(request()->typeMask().toSet()); + QSet<QContactDetail::DetailType> mask(request()->typeMask().constBegin(), request()->typeMask().constEnd()); for (int i = 0; i < contacts.count(); i++) { // See if this is an existing contact or a new one const int fetchedIdx = m_existingIdMap.value(i, -1); diff --git a/src/imports/contacts/details/qdeclarativecontactaddress_p.h b/src/imports/contacts/details/qdeclarativecontactaddress_p.h index c0151a5af..178c19486 100644 --- a/src/imports/contacts/details/qdeclarativecontactaddress_p.h +++ b/src/imports/contacts/details/qdeclarativecontactaddress_p.h @@ -144,7 +144,7 @@ public: { QList<int> oldList = detail().value< QList<int> >(QContactAddress::FieldSubTypes); - if (!readOnly() && subTypes.toSet() != oldList.toSet()) { + if (!readOnly() && QSet<int>(subTypes.constBegin(), subTypes.constEnd()) != QSet<int>(oldList.constBegin(), oldList.constEnd())) { detail().setValue(QContactAddress::FieldSubTypes, QVariant::fromValue(subTypes)); emit valueChanged(); } diff --git a/src/imports/contacts/details/qdeclarativecontactfamily_p.h b/src/imports/contacts/details/qdeclarativecontactfamily_p.h index d7df2f44f..0ac797107 100644 --- a/src/imports/contacts/details/qdeclarativecontactfamily_p.h +++ b/src/imports/contacts/details/qdeclarativecontactfamily_p.h @@ -80,7 +80,7 @@ public: QString spouse() const {return detail().value(QContactFamily::FieldSpouse).toString();} void setChildren(const QStringList& v) { - if (!readOnly() && v.toSet() != children().toSet()) { + if (!readOnly() && QSet<QString>(v.constBegin(), v.constEnd()) != QSet<QString>(children().constBegin(), children().constEnd())) { detail().setValue(QContactFamily::FieldChildren, v); emit valueChanged(); } diff --git a/src/imports/contacts/details/qdeclarativecontactonlineaccount_p.h b/src/imports/contacts/details/qdeclarativecontactonlineaccount_p.h index c5e4bb456..01b9a6d54 100644 --- a/src/imports/contacts/details/qdeclarativecontactonlineaccount_p.h +++ b/src/imports/contacts/details/qdeclarativecontactonlineaccount_p.h @@ -121,7 +121,7 @@ public: void setCapabilities(const QStringList& v) { - if (!readOnly() && v.toSet() != capabilities().toSet()) { + if (!readOnly() && QSet<QString>(v.constBegin(), v.constEnd()) != QSet<QString>(capabilities().constBegin(), capabilities().constEnd())) { detail().setValue(QContactOnlineAccount::FieldCapabilities, v); emit valueChanged(); } @@ -132,7 +132,7 @@ public: { QList<int> oldList = detail().value< QList<int> >(QContactOnlineAccount::FieldSubTypes); - if (!readOnly() && subTypes.toSet() != oldList.toSet()) { + if (!readOnly() && QSet<int>(subTypes.constBegin(), subTypes.constEnd()) != QSet<int>(oldList.constBegin(), oldList.constEnd())) { detail().setValue(QContactOnlineAccount::FieldSubTypes, QVariant::fromValue(subTypes)); emit valueChanged(); } diff --git a/src/imports/contacts/details/qdeclarativecontactorganization_p.h b/src/imports/contacts/details/qdeclarativecontactorganization_p.h index 4f550510b..7eb67436a 100644 --- a/src/imports/contacts/details/qdeclarativecontactorganization_p.h +++ b/src/imports/contacts/details/qdeclarativecontactorganization_p.h @@ -101,7 +101,7 @@ public: QUrl logoUrl() const {return detail().value(QContactOrganization::FieldLogoUrl).toString();} void setDepartment(const QStringList& v) { - if (!readOnly() && v.toSet() != department().toSet()) { + if (!readOnly() && QSet<QString>(v.constBegin(), v.constEnd()) != QSet<QString>(department().constBegin(), department().constEnd())) { detail().setValue(QContactOrganization::FieldDepartment, v); emit valueChanged(); } diff --git a/src/imports/contacts/details/qdeclarativecontactphonenumber_p.h b/src/imports/contacts/details/qdeclarativecontactphonenumber_p.h index cec557bd0..476f18b5d 100644 --- a/src/imports/contacts/details/qdeclarativecontactphonenumber_p.h +++ b/src/imports/contacts/details/qdeclarativecontactphonenumber_p.h @@ -104,7 +104,7 @@ public: { QList<int> oldList = detail().value< QList<int> >(QContactPhoneNumber::FieldSubTypes); - if (!readOnly() && subTypes.toSet() != oldList.toSet()) { + if (!readOnly() && QSet<int>(subTypes.constBegin(), subTypes.constEnd()) != QSet<int>(oldList.constBegin(), oldList.constEnd())) { detail().setValue(QContactPhoneNumber::FieldSubTypes, QVariant::fromValue(subTypes)); emit valueChanged(); } diff --git a/src/imports/contacts/qdeclarativecontactfetchhint.cpp b/src/imports/contacts/qdeclarativecontactfetchhint.cpp index 6da4ee967..e80e65aee 100644 --- a/src/imports/contacts/qdeclarativecontactfetchhint.cpp +++ b/src/imports/contacts/qdeclarativecontactfetchhint.cpp @@ -82,7 +82,7 @@ QList<int> QDeclarativeContactFetchHint::detailTypesHint() const } void QDeclarativeContactFetchHint::setDetailTypesHint(const QList<int> &detailTypes) { - if (detailTypes.toSet() != detailTypesHint().toSet()) { + if (QSet<int>(detailTypes.constBegin(), detailTypes.constEnd()) != QSet<int>(detailTypesHint().constBegin(), detailTypesHint().constEnd())) { QList<QContactDetail::DetailType> convertedDetailTypes; foreach (const int detailType, detailTypes) { convertedDetailTypes << static_cast<QContactDetail::DetailType>(detailType); @@ -104,7 +104,8 @@ QStringList QDeclarativeContactFetchHint::relationshipTypesHint() const } void QDeclarativeContactFetchHint::setRelationshipTypesHint(const QStringList& relationshipTypes) { - if (relationshipTypes.toSet() != m_fetchHint.relationshipTypesHint().toSet()) { + if (QSet<QString>(relationshipTypes.constBegin(), relationshipTypes.constEnd()) + != QSet<QString>(m_fetchHint.relationshipTypesHint().constBegin(), m_fetchHint.relationshipTypesHint().constEnd())) { m_fetchHint.setRelationshipTypesHint(relationshipTypes); emit fetchHintChanged(); } diff --git a/src/imports/organizer/qdeclarativeorganizeritemfetchhint.cpp b/src/imports/organizer/qdeclarativeorganizeritemfetchhint.cpp index 0824a1b6e..081c5131f 100644 --- a/src/imports/organizer/qdeclarativeorganizeritemfetchhint.cpp +++ b/src/imports/organizer/qdeclarativeorganizeritemfetchhint.cpp @@ -116,7 +116,7 @@ QList<int> QDeclarativeOrganizerItemFetchHint::detailTypesHint() const void QDeclarativeOrganizerItemFetchHint::setDetailTypesHint(const QList<int> &detailTypes) { - if (detailTypes.toSet() != detailTypesHint().toSet()) { + if (QSet<int>(detailTypes.constBegin(), detailTypes.constEnd()) != QSet<int>(detailTypesHint().constBegin(), detailTypesHint().constEnd())) { QList<QOrganizerItemDetail::DetailType> convertedDetailTypes; foreach (const int detailType, detailTypes) convertedDetailTypes << static_cast<QOrganizerItemDetail::DetailType>(detailType); diff --git a/src/versitorganizer/qversitorganizerexporter_p.cpp b/src/versitorganizer/qversitorganizerexporter_p.cpp index 2c6aa8a59..58ba684cf 100644 --- a/src/versitorganizer/qversitorganizerexporter_p.cpp +++ b/src/versitorganizer/qversitorganizerexporter_p.cpp @@ -389,7 +389,7 @@ void QVersitOrganizerExporterPrivate::encodeRecurRule( if (!rule.daysOfWeek().isEmpty()) { value.append(QStringLiteral(";BYDAY=")); bool first = true; - QList<Qt::DayOfWeek> daysOfWeek(QList<Qt::DayOfWeek>::fromSet(rule.daysOfWeek())); + QList<Qt::DayOfWeek> daysOfWeek(rule.daysOfWeek().values()); std::sort(daysOfWeek.begin(), daysOfWeek.end()); foreach (Qt::DayOfWeek day, daysOfWeek) { if (!first) @@ -413,8 +413,7 @@ void QVersitOrganizerExporterPrivate::encodeRecurRule( if (!rule.monthsOfYear().isEmpty()) { value.append(QStringLiteral(";BYMONTH=")); bool first = true; - QList<QOrganizerRecurrenceRule::Month> months( - QList<QOrganizerRecurrenceRule::Month>::fromSet(rule.monthsOfYear())); + QList<QOrganizerRecurrenceRule::Month> months(rule.monthsOfYear().values()); std::sort(months.begin(), months.end()); foreach (QOrganizerRecurrenceRule::Month month, months) { if (!first) @@ -440,7 +439,7 @@ void QVersitOrganizerExporterPrivate::encodeRecurRule( */ void QVersitOrganizerExporterPrivate::appendInts(QString* str, const QSet<int>& ints) { bool first = true; - QList<int> intList(QList<int>::fromSet(ints)); + QList<int> intList(ints.values()); std::sort(intList.begin(), intList.end()); foreach (int n, intList) { if (!first) @@ -489,7 +488,7 @@ void QVersitOrganizerExporterPrivate::encodeRecurDates( QString value = property.value(); bool valueIsEmpty = value.isEmpty(); - QList<QDate> dateList(QList<QDate>::fromSet(dates)); + QList<QDate> dateList(dates.values()); std::sort(dateList.begin(), dateList.end()); foreach (const QDate& dt, dateList) { QString str; diff --git a/tests/auto/contacts/qcontactmanager/tst_qcontactmanager.cpp b/tests/auto/contacts/qcontactmanager/tst_qcontactmanager.cpp index d0fb0f44d..e2d5548fa 100644 --- a/tests/auto/contacts/qcontactmanager/tst_qcontactmanager.cpp +++ b/tests/auto/contacts/qcontactmanager/tst_qcontactmanager.cpp @@ -2129,15 +2129,18 @@ void tst_QContactManager::changeSet() QVERIFY(!changeSet.addedContacts().isEmpty()); QVERIFY(!changeSet.changedContacts().isEmpty()); QVERIFY(changeSet.removedContacts().isEmpty()); - QSet<QContactId> changedIds; - QSet<QContactDetail::DetailType> changedTypes; + QSet<QContactId> changedIds, expectedIds; + QSet<QContactDetail::DetailType> changedTypes, expectedTypes; foreach (const QContactChangeSet::ContactChangeList &changes, changeSet.changedContacts()) { changedIds |= QSet<QContactId>(changes.second.constBegin(), changes.second.constEnd()); - if (changes.second.contains(id)) - changedTypes |= QSet<QContactId>(changes.first.constBegin(), changes.first.constEnd()); + if (changes.second.contains(id)) { + changedTypes |= QSet<QContactDetail::DetailType>(changes.first.constBegin(), changes.first.constEnd()); + } } - QCOMPARE(changedIds, (QSet<QContactId>() << id)); - QCOMPARE(changedTypes, (QSet<QContactDetail::DetailType>() << QContactName::Type << QContactBirthday::Type)); + expectedIds.clear(); expectedIds.insert(id); + expectedTypes.clear(); expectedTypes.insert(QContactName::Type); expectedTypes.insert(QContactBirthday::Type); + QCOMPARE(changedIds, expectedIds); + QCOMPARE(changedTypes, expectedTypes); changeSet.clearChangedContacts(); QVERIFY(changeSet.changedContacts().isEmpty()); @@ -2149,8 +2152,7 @@ void tst_QContactManager::changeSet() changeSet.insertChangedContacts(l1, QList<QContactDetail::DetailType>() << QContactName::Type << QContactBirthday::Type); changeSet.insertChangedContacts(l2, QList<QContactDetail::DetailType>() << QContactBirthday::Type << QContactName::Type << QContactBirthday::Type); QCOMPARE(changeSet.changedContacts().size(), 1); - QList<QContactId> expected((QSet<QContactId>(l1.constBegin(), l1.constEnd()) - | QSet<QContactId>(l2.constBegin(), l2.constEnd())).values()); + QList<QContactId> expected((QSet<QContactId>(l1.constBegin(), l1.constEnd()) | QSet<QContactId>(l2.constBegin(), l2.constEnd())).values()); qSort(expected); QCOMPARE(changeSet.changedContacts().first().second, expected); diff --git a/tests/auto/organizer/qorganizermanager/tst_qorganizermanager.cpp b/tests/auto/organizer/qorganizermanager/tst_qorganizermanager.cpp index 34d10d441..8fb0d218e 100644 --- a/tests/auto/organizer/qorganizermanager/tst_qorganizermanager.cpp +++ b/tests/auto/organizer/qorganizermanager/tst_qorganizermanager.cpp @@ -65,6 +65,12 @@ static inline QOrganizerCollectionId makeCollectionId(uint id) return QOrganizerCollectionId(QStringLiteral("qtorganizer:basic:"), QByteArray(reinterpret_cast<const char *>(&id), sizeof(uint))); } +template<typename T> +static inline QSet<T> convertListToSet(const QList<T> &list) +{ + return QSet<T>(list.constBegin(), list.constEnd()); +} + class tst_QOrganizerManager : public QObject { @@ -2733,15 +2739,13 @@ void tst_QOrganizerManager::changeSet() QSet<QOrganizerItemId> changedIds; QSet<QOrganizerItemDetail::DetailType> changedTypes; foreach (const QOrganizerItemChangeSet::ItemChangeList &changes, changeSet.changedItems()) { - changedIds |= QSet<QOrganizerItemId>(changes.second.constBegin(), - changes.second.constEnd()); + changedIds |= convertListToSet(changes.second); if (changes.second.contains(id)) { - changedTypes |= QSet<QOrganizerItemId>(changes.first.constBegin(), - changes.first.constEnd()); + changedTypes |= convertListToSet(changes.first); } } - QCOMPARE(changedIds, (QSet<QOrganizerItemId>() << id)); - QCOMPARE(changedTypes, (QSet<QOrganizerItemDetail::DetailType>() << QOrganizerItemDetail::TypeDescription << QOrganizerItemDetail::TypeTag)); + QCOMPARE(changedIds, convertListToSet(QList<QOrganizerItemId>() << id)); + QCOMPARE(changedTypes, convertListToSet(QList<QOrganizerItemDetail::DetailType>() << QOrganizerItemDetail::TypeDescription << QOrganizerItemDetail::TypeTag)); changeSet.clearChangedItems(); QVERIFY(changeSet.changedItems().isEmpty()); @@ -2753,9 +2757,7 @@ void tst_QOrganizerManager::changeSet() changeSet.insertChangedItems(l1, QList<QOrganizerItemDetail::DetailType>() << QOrganizerItemDetail::TypeDescription << QOrganizerItemDetail::TypeTag); changeSet.insertChangedItems(l2, QList<QOrganizerItemDetail::DetailType>() << QOrganizerItemDetail::TypeTag << QOrganizerItemDetail::TypeDescription << QOrganizerItemDetail::TypeTag); QCOMPARE(changeSet.changedItems().size(), 1); - QList<QOrganizerItemId> expected( - (QSet<QOrganizerItemId>(l1.constBegin(), l1.constEnd()) - | QSet<QOrganizerItemId>(l2.constBegin(), l2.constEnd())).values()); + QList<QOrganizerItemId> expected((convertListToSet(l1) | convertListToSet(l2)).values()); qSort(expected); QCOMPARE(changeSet.changedItems().first().second, expected); |