diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-14 11:08:18 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-15 07:56:46 +0000 |
commit | a0ade068004ad869d6235ae8d6cd5e2050bf765d (patch) | |
tree | 42c949ba2fa7fcd4ab5356293d1ef3cad1c436f6 /src | |
parent | 84f0e76c647e7f09529b79525b2d4fbc698576d8 (diff) |
Replace foreach with for loop and set QT_NO_FOREACH
To avoid unnecessary copies, const is used wherever possible.
Change-Id: Ic743716512751cfd24fad5bd37c244b115dd26fe
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
42 files changed, 134 insertions, 95 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 72208a87..193ed217 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -1,6 +1,6 @@ TARGET = QtBluetooth QT = core core-private - +DEFINES += QT_NO_FOREACH QMAKE_DOCS = $$PWD/doc/qtbluetooth.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index f798088e..2beb533c 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -331,7 +331,8 @@ QtBluezDiscoveryManager::~QtBluezDiscoveryManager() { qCDebug(QT_BT_BLUEZ) << "Destroying QtBluezDiscoveryManager"; - foreach (const QString &adapterPath, d->references.keys()) { + const QList<QString> adapterPaths = d->references.keys(); + for (const QString &adapterPath : adapterPaths) { AdapterData *data = d->references.take(adapterPath); delete data->propteryListener; @@ -416,7 +417,8 @@ void QtBluezDiscoveryManager::unregisterDiscoveryInterest(const QString &adapter // if (d->references.isEmpty()) { // qCDebug(QT_BT_BLUEZ) << "No running registration"; // } else { -// foreach (const QString &path, d->references.keys()) { +// const QList<QString> paths = d->references.keys(); +// for (const QString &path : paths) { // qCDebug(QT_BT_BLUEZ) << path << "->" << d->references[path]->reference; // } // } @@ -536,7 +538,7 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = if (wantedAddress.isNull()) return localAdapters.front().first; // -> return first found adapter - foreach (const AddressForPathType &pair, localAdapters) { + for (const AddressForPathType &pair : qAsConst(localAdapters)) { if (pair.second == wantedAddress) return pair.first; // -> found local adapter with wanted address } diff --git a/src/bluetooth/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm index e228d6db..9fbc2c12 100644 --- a/src/bluetooth/osx/osxbtobexsession.mm +++ b/src/bluetooth/osx/osxbtobexsession.mm @@ -537,14 +537,14 @@ QT_USE_NAMESPACE const OBEXConnectCommandResponseData *const response = &event->u.connectCommandResponseData; if (response->headerDataPtr && response->headerDataLength >= 2) { // 2 == 1 byte headerID + at least 1 byte headerValue ... - QList<OBEXHeader> headers(qt_bluetooth_headers(static_cast<const uint8_t *>(response->headerDataPtr), + const QList<OBEXHeader> headers(qt_bluetooth_headers(static_cast<const uint8_t *>(response->headerDataPtr), response->headerDataLength)); // ConnectionID is used when multiplexing OBEX connections // to identify which particular connection this object is // being sent on. When used, this _must_ be the first // header sent. - foreach (const OBEXHeader &header, headers) { + for (const OBEXHeader &header : headers) { if (header.headerID == kOBEXHeaderIDConnectionID) { connectionID = header.value.value<quint32>(); connectionIDFound = true; diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm index a0bfdeef..6df2d16e 100644 --- a/src/bluetooth/osx/osxbtsdpinquiry.mm +++ b/src/bluetooth/osx/osxbtsdpinquiry.mm @@ -188,7 +188,7 @@ using namespace OSXBluetooth; return kIOReturnError; } - foreach (const QBluetoothUuid &qUuid, qtFilters) { + for (const QBluetoothUuid &qUuid : qtFilters) { ObjCStrongReference<IOBluetoothSDPUUID> uuid(iobluetooth_uuid(qUuid)); if (uuid) [array addObject:uuid]; diff --git a/src/bluetooth/osx/osxbtservicerecord.mm b/src/bluetooth/osx/osxbtservicerecord.mm index d12169bb..23d55d13 100644 --- a/src/bluetooth/osx/osxbtservicerecord.mm +++ b/src/bluetooth/osx/osxbtservicerecord.mm @@ -386,7 +386,7 @@ bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray return false; const Sequence sequence(var.value<Sequence>()); - foreach (const QVariant &var, sequence) { + for (const QVariant &var : sequence) { if (var.canConvert<Sequence>()) { NSMutableArray *const nested = [NSMutableArray array]; add_sequence_attribute(var, key, nested); @@ -411,7 +411,7 @@ bool add_sequence_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeI NSMutableArray *const list = [NSMutableArray array]; const Sequence sequence(var.value<Sequence>()); - foreach (const QVariant &element, sequence) { + for (const QVariant &element : sequence) { if (!add_sequence_attribute(element, key, list)) add_attribute(element, key, list); } @@ -433,7 +433,7 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn dict.reset([[NSMutableDictionary alloc] init]); - foreach (quint16 key, attributeIds) { + for (quint16 key : attributeIds) { if (key == QSInfo::ProtocolDescriptorList) // We handle it in a special way. continue; // TODO: check if non-sequence QVariant still must be diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index 5f142f1a..a9e35960 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -210,7 +210,7 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent( { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 3cc3354a..3d09a4df 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -360,7 +360,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres if (dict.value(QStringLiteral("RSSI")).isValid()) device.setRssi(dict.value(QStringLiteral("RSSI")).toInt()); QList<QBluetoothUuid> uuids; - foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList()) + const QStringList uuidStrings + = dict.value(QLatin1String("UUIDs")).toStringList(); + for (const QString &u : uuidStrings) uuids.append(QBluetoothUuid(u)); device.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); device.setCached(dict.value(QStringLiteral("Cached")).toBool()); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index fed33bb2..4657da82 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -553,7 +553,7 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent( { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index c247f679..8612fd5c 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -249,7 +249,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() if (reply.isError()) return localDevices; - foreach (const QDBusObjectPath &path, reply.value()) { + const QList<QDBusObjectPath> paths = reply.value(); + for (const QDBusObjectPath &path : paths) { QBluetoothHostInfo hostinfo; OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); @@ -770,7 +771,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() if (reply.isError()) return; - foreach (const QDBusObjectPath &path, reply.value()) { + const QList<QDBusObjectPath> paths = reply.value(); + for (const QDBusObjectPath &path : paths) { OrgBluezAdapterInterface *tmpAdapter = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); @@ -1067,7 +1069,7 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &device) { - foreach (OrgBluezDeviceInterface *deviceInterface, devices) { + for (OrgBluezDeviceInterface *deviceInterface : qAsConst(devices)) { if (deviceInterface->path() == device.path()) { devices.remove(deviceInterface); delete deviceInterface; // deviceDisconnected is already emitted by _q_devicePropertyChanged @@ -1113,7 +1115,8 @@ void QBluetoothLocalDevicePrivate::createCache() qCWarning(QT_BT_BLUEZ) << reply.error().message(); return; } - foreach (const QDBusObjectPath &device, reply.value()) { + const QList<QDBusObjectPath> knownDevices = reply.value(); + for (const QDBusObjectPath &device : knownDevices) { OrgBluezDeviceInterface *deviceInterface = new OrgBluezDeviceInterface(QStringLiteral("org.bluez"), device.path(), diff --git a/src/bluetooth/qbluetoothserver_android.cpp b/src/bluetooth/qbluetoothserver_android.cpp index b001adb8..3c2cc507 100644 --- a/src/bluetooth/qbluetoothserver_android.cpp +++ b/src/bluetooth/qbluetoothserver_android.cpp @@ -142,7 +142,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 por if (!localAdapter.isNull()) { bool found = false; - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == localAdapter) { found = true; break; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 05d62ab1..e24876e4 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -177,7 +177,7 @@ QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoot { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index 51db091e..63601058 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -427,7 +427,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_fetchUuidsTimeout() QPair<QBluetoothDeviceInfo,QList<QBluetoothUuid> > pair; const QList<QBluetoothAddress> keys = sdpCache.keys(); - foreach (const QBluetoothAddress &key, keys) { + for (const QBluetoothAddress &key : keys) { pair = sdpCache.take(key); populateDiscoveredServices(pair.first, pair.second); } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index ea9f354b..82939c26 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -223,7 +223,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::runExternalSdpScan( // No filter implies PUBLIC_BROWSE_GROUP based SDP scan if (!uuidFilter.isEmpty()) { arguments << QLatin1String("-u"); // cmd line option for list of uuids - foreach (const QBluetoothUuid& uuid, uuidFilter) + for (const QBluetoothUuid& uuid : qAsConst(uuidFilter)) arguments << uuid.toString(); } @@ -286,14 +286,16 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD errorString = errorDescription; emit q->error(error); } else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) { - foreach (const QString &record, xmlRecords) { + for (const QString &record : xmlRecords) { const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); //apply uuidFilter if (!uuidFilter.isEmpty()) { bool serviceNameMatched = uuidFilter.contains(serviceInfo.serviceUuid()); bool serviceClassMatched = false; - foreach (const QBluetoothUuid &id, serviceInfo.serviceClassUuids()) { + const QList<QBluetoothUuid> serviceClassUuids + = serviceInfo.serviceClassUuids(); + for (const QBluetoothUuid &id : serviceClassUuids) { if (uuidFilter.contains(id)) { serviceClassMatched = true; break; @@ -519,7 +521,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::discoverServices(const QString &dev _q_serviceDiscoveryFinished(); } else { QString pattern; - foreach (const QBluetoothUuid &uuid, uuidFilter) + for (const QBluetoothUuid &uuid : qAsConst(uuidFilter)) pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' '); pattern = pattern.trimmed(); @@ -558,13 +560,13 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC return; } - ServiceMap map = reply.value(); + const ServiceMap map = reply.value(); qCDebug(QT_BT_BLUEZ) << "Parsing xml" << discoveredDevices.at(0).address().toString() << discoveredDevices.count() << map.count(); - foreach (const QString &record, reply.value()) { + for (const QString &record : map) { QBluetoothServiceInfo serviceInfo = parseServiceXml(record); if (!serviceInfo.isValid()) @@ -578,7 +580,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC // to our own naming resolution. if (serviceInfo.serviceName().isEmpty() && !serviceInfo.serviceClassUuids().isEmpty()) { - foreach (const QBluetoothUuid &classUuid, serviceInfo.serviceClassUuids()) { + const QList<QBluetoothUuid> classUuids = serviceInfo.serviceClassUuids(); + for (const QBluetoothUuid &classUuid : classUuids) { bool ok = false; QBluetoothUuid::ServiceClassUuid clsId = static_cast<QBluetoothUuid::ServiceClassUuid>(classUuid.toUInt16(&ok)); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index 1d0cc7da..61d3bcc2 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -441,7 +441,7 @@ QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoot { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp index 77310d01..09523c75 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp @@ -537,7 +537,9 @@ void QBluetoothServiceDiscoveryAgentPrivate::processFoundService(quint64 deviceA if (!uuidFilter.isEmpty()) { bool serviceNameMatched = uuidFilter.contains(info.serviceUuid()); bool serviceClassMatched = false; - for (const QBluetoothUuid &id : info.serviceClassUuids()) { + const QList<QBluetoothUuid> serviceClassUuids + = info.serviceClassUuids(); + for (const QBluetoothUuid &id : serviceClassUuids) { if (uuidFilter.contains(id)) { serviceClassMatched = true; break; @@ -553,7 +555,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::processFoundService(quint64 deviceA QBluetoothServiceInfo returnInfo(info); bool deviceFound; - for (const QBluetoothDeviceInfo &deviceInfo : discoveredDevices) { + for (const QBluetoothDeviceInfo &deviceInfo : qAsConst(discoveredDevices)) { if (deviceInfo.address().toUInt64() == deviceAddress) { deviceFound = true; returnInfo.setDevice(deviceInfo); @@ -576,7 +578,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::onScanFinished(quint64 deviceAddres { Q_Q(QBluetoothServiceDiscoveryAgent); bool deviceFound; - for (const QBluetoothDeviceInfo &deviceInfo : discoveredDevices) { + for (const QBluetoothDeviceInfo &deviceInfo : qAsConst(discoveredDevices)) { if (deviceInfo.address().toUInt64() == deviceAddress) { deviceFound = true; discoveredDevices.removeOne(deviceInfo); diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp index d706e4a7..d98e616f 100644 --- a/src/bluetooth/qbluetoothserviceinfo.cpp +++ b/src/bluetooth/qbluetoothserviceinfo.cpp @@ -606,12 +606,12 @@ static void dumpAttributeVariant(QDebug dbg, const QVariant &var, const QString& } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) { dbg << QString::asprintf("%sSequence\n", indent.toUtf8().constData()); const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(var.data()); - foreach (const QVariant &v, *sequence) + for (const QVariant &v : *sequence) dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t')); } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) { dbg << QString::asprintf("%sAlternative\n", indent.toUtf8().constData()); const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(var.data()); - foreach (const QVariant &v, *alternative) + for (const QVariant &v : *alternative) dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t')); } break; @@ -626,7 +626,8 @@ QDebug operator<<(QDebug dbg, const QBluetoothServiceInfo &info) { QDebugStateSaver saver(dbg); dbg.noquote() << "\n"; - foreach (quint16 id, info.attributes()) { + QList<quint16> attributes = info.attributes(); + for (quint16 id : attributes) { dumpAttributeVariant(dbg, info.attribute(id), QStringLiteral("(%1)\t").arg(id)); } return dbg; @@ -637,7 +638,9 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfoPrivate::protocolDescriptor if (!attributes.contains(QBluetoothServiceInfo::ProtocolDescriptorList)) return QBluetoothServiceInfo::Sequence(); - foreach (const QVariant &v, attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>()) { + const QBluetoothServiceInfo::Sequence sequence + = attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>(); + for (const QVariant &v : sequence) { QBluetoothServiceInfo::Sequence parameters = v.value<QBluetoothServiceInfo::Sequence>(); if (parameters.empty()) continue; diff --git a/src/bluetooth/qbluetoothserviceinfo_android.cpp b/src/bluetooth/qbluetoothserviceinfo_android.cpp index 0b46e11b..b0193f73 100644 --- a/src/bluetooth/qbluetoothserviceinfo_android.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_android.cpp @@ -95,7 +95,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& loca if (!localAdapter.isNull()) { bool found = false; - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == localAdapter) { found = true; break; diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp index 87c715c4..312b5a7a 100644 --- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp @@ -158,13 +158,13 @@ static void writeAttribute(QXmlStreamWriter *stream, const QVariant &attribute) stream->writeStartElement(QStringLiteral("sequence")); const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(attribute.data()); - foreach (const QVariant &v, *sequence) + for (const QVariant &v : *sequence) writeAttribute(stream, v); stream->writeEndElement(); } else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) { const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(attribute.data()); - foreach (const QVariant &v, *alternative) + for (const QVariant &v : *alternative) writeAttribute(stream, v); stream->writeEndElement(); } diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index 755e85c9..27da70fc 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -359,12 +359,12 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent) } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) { qDebug("%sSequence", indent.toLocal8Bit().constData()); const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(var.data()); - foreach (const QVariant &v, *sequence) + for (const QVariant &v : *sequence) dumpAttributeVariant(v, indent + QLatin1Char('\t')); } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) { qDebug("%sAlternative", indent.toLocal8Bit().constData()); const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(var.data()); - foreach (const QVariant &v, *alternative) + for (const QVariant &v : *alternative) dumpAttributeVariant(v, indent + QLatin1Char('\t')); } break; @@ -375,7 +375,8 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent) QDebug operator << (QDebug dbg, const QBluetoothServiceInfo &info) { - foreach (quint16 id, info.attributes()) { + const QList<quint16> attributes = info.attributes(); + for (quint16 id : attributes) { dumpAttributeVariant(info.attribute(id), QString::fromLatin1("(%1)\t").arg(id)); } return dbg; @@ -386,7 +387,9 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfoPrivate::protocolDescriptor if (!attributes.contains(QBluetoothServiceInfo::ProtocolDescriptorList)) return QBluetoothServiceInfo::Sequence(); - foreach (const QVariant &v, attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>()) { + const QBluetoothServiceInfo::Sequence sequence + = attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>(); + for (const QVariant &v : sequence) { QBluetoothServiceInfo::Sequence parameters = v.value<QBluetoothServiceInfo::Sequence>(); if (parameters.empty()) continue; diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp index 5400c001..df3e97b9 100644 --- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp @@ -290,7 +290,7 @@ static ComPtr<IBuffer> bufferFromAttribute(const QVariant &attribute) HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataWriter).Get(), &tmpWriter); Q_ASSERT_SUCCEEDED(hr); - foreach (const QVariant &v, *sequence) { + for (const QVariant &v : *sequence) { ComPtr<IBuffer> tmpBuffer = bufferFromAttribute(v); if (!tmpBuffer) { qCWarning(QT_BT_WINRT) << "Could not create buffer from attribute in sequence"; @@ -468,7 +468,8 @@ bool QBluetoothServiceInfoPrivate::writeSdpAttributes() ComPtr<IMap<UINT32, IBuffer *>> rawAttributes; hr = serviceProvider->get_SdpRawAttributes(&rawAttributes); Q_ASSERT_SUCCEEDED(hr); - for (quint16 key : attributes.keys()) { + const QList<quint16> keys = attributes.keys(); + for (quint16 key : keys) { // The SDP Class Id List and RFCOMM and L2CAP protocol descriptors are automatically // generated by the RfcommServiceProvider. Do not specify it in the SDP raw attribute map. if (key == QBluetoothServiceInfo::ServiceClassIds diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index bff5a590..47daed25 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -273,7 +273,8 @@ void QLeAdvertiserBluez::setServicesData(const QLowEnergyAdvertisingData &src, A QVector<quint16> services16; QVector<quint32> services32; QVector<quint128> services128; - foreach (const QBluetoothUuid &service, src.services()) { + const QList<QBluetoothUuid> services = src.services(); + for (const QBluetoothUuid &service : services) { bool ok; const quint16 service16 = service.toUInt16(&ok); if (ok) { @@ -393,7 +394,9 @@ void QLeAdvertiserBluez::setWhiteList() if (parameters().filterPolicy() == QLowEnergyAdvertisingParameters::IgnoreWhiteList) return; queueCommand(OcfLeClearWhiteList, QByteArray()); - foreach (const auto &addressInfo, parameters().whiteList()) { + const QList<QLowEnergyAdvertisingParameters::AddressInfo> whiteListInfos + = parameters().whiteList(); + for (const auto &addressInfo : whiteListInfos) { WhiteListParams commandParam; static_assert(sizeof commandParam == 7, "unexpected struct size"); commandParam.addrType = addressInfo.type; diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index a8b4c449..82db1c7b 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -380,7 +380,7 @@ QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const std::sort(descriptorKeys.begin(), descriptorKeys.end()); - foreach (const QLowEnergyHandle descHandle, descriptorKeys) { + for (const QLowEnergyHandle descHandle : qAsConst(descriptorKeys)) { QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle); result.append(descriptor); } diff --git a/src/bluetooth/qlowenergycharacteristicdata.cpp b/src/bluetooth/qlowenergycharacteristicdata.cpp index 9e0d69ad..700566a6 100644 --- a/src/bluetooth/qlowenergycharacteristicdata.cpp +++ b/src/bluetooth/qlowenergycharacteristicdata.cpp @@ -157,7 +157,7 @@ QList<QLowEnergyDescriptorData> QLowEnergyCharacteristicData::descriptors() cons void QLowEnergyCharacteristicData::setDescriptors(const QList<QLowEnergyDescriptorData> &descriptors) { d->descriptors.clear(); - foreach (const QLowEnergyDescriptorData &desc, descriptors) + for (const QLowEnergyDescriptorData &desc : descriptors) addDescriptor(desc); } diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 54665f7b..35d943fc 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -501,7 +501,7 @@ void QLowEnergyControllerPrivateAndroid::servicesDiscovered( if (errorCode == QLowEnergyController::NoError) { //Android delivers all services in one go const QStringList list = foundServices.split(QStringLiteral(" "), QString::SkipEmptyParts); - foreach (const QString &entry, list) { + for (const QString &entry : list) { const QBluetoothUuid service(entry); if (service.isNull()) return; @@ -550,7 +550,7 @@ void QLowEnergyControllerPrivateAndroid::serviceDetailsDiscoveryFinished( const QStringList list = javaIncludes.toString() .split(QStringLiteral(" "), QString::SkipEmptyParts); - foreach (const QString &entry, list) { + for (const QString &entry : list) { const QBluetoothUuid service(entry); if (service.isNull()) return; diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 502f42ad..7229821e 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1215,7 +1215,7 @@ void QLowEnergyControllerPrivateBluez::processReply( lastHandle = parseReadByTypeIncludeDiscovery( &includedServices, &data[offset], elementLength); p->includedServices = includedServices; - foreach (const QBluetoothUuid &uuid, includedServices) { + for (const QBluetoothUuid &uuid : qAsConst(includedServices)) { if (serviceList.contains(uuid)) serviceList[uuid]->type |= QLowEnergyService::IncludedService; } @@ -2495,7 +2495,7 @@ void QLowEnergyControllerPrivateBluez::handleReadMultipleRequest(const QByteArra } const QVector<Attribute> results = getAttributes(handles.first(), handles.last()); QByteArray response(1, ATT_OP_READ_MULTIPLE_RESPONSE); - foreach (const Attribute &attr, results) { + for (const Attribute &attr : results) { const int error = checkReadPermissions(attr); if (error) { sendErrorResponse(packet.at(0), attr.handle, error); @@ -2577,7 +2577,7 @@ void QLowEnergyControllerPrivateBluez::updateLocalAttributeValue( QLowEnergyDescriptor &descriptor) { localAttributes[handle].value = value; - foreach (const auto &service, localServices) { + for (const auto &service : qAsConst(localServices)) { if (handle < service->startHandle || handle > service->endHandle) continue; for (auto charIt = service->characteristicList.begin(); @@ -2623,7 +2623,7 @@ void QLowEnergyControllerPrivateBluez::writeCharacteristicForPeripheral( = attribute.properties & QLowEnergyCharacteristic::Indicate; if (!hasNotifyProperty && !hasIndicateProperty) return; - foreach (const QLowEnergyServicePrivate::DescData &desc, charData.descriptorList) { + for (const QLowEnergyServicePrivate::DescData &desc : qAsConst(charData.descriptorList)) { if (desc.uuid != QBluetoothUuid::ClientCharacteristicConfiguration) continue; @@ -2925,7 +2925,7 @@ void QLowEnergyControllerPrivateBluez::handleExecuteWriteRequest(const QByteArra QVector<QLowEnergyCharacteristic> characteristics; QVector<QLowEnergyDescriptor> descriptors; if (!cancel) { - foreach (const WriteRequest &request, requests) { + for (const WriteRequest &request : qAsConst(requests)) { Attribute &attribute = localAttributes[request.handle]; if (request.valueOffset > attribute.value.count()) { sendErrorResponse(packet.at(0), request.handle, ATT_ERROR_INVALID_OFFSET); @@ -2952,9 +2952,9 @@ void QLowEnergyControllerPrivateBluez::handleExecuteWriteRequest(const QByteArra sendPacket(QByteArray(1, ATT_OP_EXECUTE_WRITE_RESPONSE)); - foreach (const QLowEnergyCharacteristic &characteristic, characteristics) + for (const QLowEnergyCharacteristic &characteristic : qAsConst(characteristics)) emit characteristic.d_ptr->characteristicChanged(characteristic, characteristic.value()); - foreach (const QLowEnergyDescriptor &descriptor, descriptors) + for (const QLowEnergyDescriptor &descriptor : qAsConst(descriptors)) emit descriptor.d_ptr->descriptorWritten(descriptor, descriptor.value()); } @@ -3153,7 +3153,7 @@ bool QLowEnergyControllerPrivateBluez::isBonded() const QVector<QLowEnergyControllerPrivateBluez::TempClientConfigurationData> QLowEnergyControllerPrivateBluez::gatherClientConfigData() { QVector<TempClientConfigurationData> data; - foreach (const auto &service, localServices) { + for (const auto &service : qAsConst(localServices)) { for (auto charIt = service->characteristicList.begin(); charIt != service->characteristicList.end(); ++charIt) { QLowEnergyServicePrivate::CharData &charData = charIt.value(); @@ -3179,7 +3179,7 @@ void QLowEnergyControllerPrivateBluez::storeClientConfigurations() } QVector<ClientConfigurationData> clientConfigs; const QVector<TempClientConfigurationData> &tempConfigList = gatherClientConfigData(); - foreach (const auto &tempConfigData, tempConfigList) { + for (const auto &tempConfigData : tempConfigList) { Q_ASSERT(tempConfigData.descData->value.count() == 2); const quint16 value = bt_get_le16(tempConfigData.descData->value.constData()); if (value != 0) { @@ -3196,9 +3196,9 @@ void QLowEnergyControllerPrivateBluez::restoreClientConfigurations() const QVector<ClientConfigurationData> &restoredClientConfigs = isBonded() ? clientConfigData.value(remoteDevice.toUInt64()) : QVector<ClientConfigurationData>(); QVector<QLowEnergyHandle> notifications; - foreach (const auto &tempConfigData, tempConfigList) { + for (const auto &tempConfigData : tempConfigList) { bool wasRestored = false; - foreach (const auto &restoredData, restoredClientConfigs) { + for (const auto &restoredData : restoredClientConfigs) { if (restoredData.charValueHandle == tempConfigData.charValueHandle) { Q_ASSERT(tempConfigData.descData->value.count() == 2); putBtData(restoredData.configValue, tempConfigData.descData->value.data()); @@ -3219,7 +3219,7 @@ void QLowEnergyControllerPrivateBluez::restoreClientConfigurations() localAttributes[tempConfigData.configHandle].value = tempConfigData.descData->value; } - foreach (const QLowEnergyHandle handle, notifications) + for (const QLowEnergyHandle handle : qAsConst(notifications)) sendNotification(handle); sendNextIndication(); } @@ -3318,7 +3318,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg serviceAttribute.properties = QLowEnergyCharacteristic::Read; serviceAttribute.value = uuidToByteArray(service.uuid()); QLowEnergyHandle currentHandle = startHandle; - foreach (const QLowEnergyService * const service, service.includedServices()) { + const QList<QLowEnergyService *> includedServices = service.includedServices(); + for (const QLowEnergyService * const service : includedServices) { Attribute attribute; attribute.handle = ++currentHandle; attribute.type = QBluetoothUuid(GATT_INCLUDED_SERVICE); @@ -3332,7 +3333,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg putDataAndIncrement(service->serviceUuid(), valueData); localAttributes[attribute.handle] = attribute; } - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { + const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics(); + for (const QLowEnergyCharacteristicData &cd : characteristics) { Attribute attribute; // Characteristic declaration; @@ -3359,7 +3361,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg attribute.maxLength = cd.maximumValueLength(); localAttributes[attribute.handle] = attribute; - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { + const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors(); + for (const QLowEnergyDescriptorData &dd : descriptors) { attribute.handle = ++currentHandle; attribute.groupEndHandle = attribute.handle; attribute.type = dd.uuid(); diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index 2958e6ed..46782a22 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -880,7 +880,9 @@ quint16 QLowEnergyControllerPrivateOSX::updateValueOfDescriptor(QLowEnergyHandle QSharedPointer<QLowEnergyServicePrivate> QLowEnergyControllerPrivateOSX::serviceForHandle(QLowEnergyHandle handle) { - foreach (QSharedPointer<QLowEnergyServicePrivate> service, discoveredServices.values()) { + const QList<QSharedPointer<QLowEnergyServicePrivate>> services + = discoveredServices.values(); + for (QSharedPointer<QLowEnergyServicePrivate> service : services) { if (service->startHandle <= handle && handle <= service->endHandle) return service; } @@ -963,7 +965,9 @@ void QLowEnergyControllerPrivateOSX::setErrorDescription(QLowEnergyController::E void QLowEnergyControllerPrivateOSX::invalidateServices() { - foreach (const QSharedPointer<QLowEnergyServicePrivate> service, discoveredServices.values()) { + const QList<QSharedPointer<QLowEnergyServicePrivate>> services + = discoveredServices.values(); + for (const QSharedPointer<QLowEnergyServicePrivate> service : services) { service->setController(nullptr); service->setState(QLowEnergyService::InvalidService); } diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index 917f3790..f6cca42c 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -292,7 +292,7 @@ QLowEnergyControllerPrivateWinRT::~QLowEnergyControllerPrivateWinRT() mDevice->remove_ConnectionStatusChanged(mStatusChangedToken); qCDebug(QT_BT_WINRT) << "Unregistering " << mValueChangedTokens.count() << " value change tokens"; - for (const ValueChangedEntry &entry : mValueChangedTokens) + for (const ValueChangedEntry &entry : qAsConst(mValueChangedTokens)) entry.characteristic->remove_ValueChanged(entry.token); } @@ -469,7 +469,7 @@ void QLowEnergyControllerPrivateWinRT::registerForValueChanges(const QBluetoothU { qCDebug(QT_BT_WINRT) << "Registering characteristic" << charUuid << "in service" << serviceUuid << "for value changes"; - for (const ValueChangedEntry &entry : mValueChangedTokens) { + for (const ValueChangedEntry &entry : qAsConst(mValueChangedTokens)) { GUID guuid; HRESULT hr; hr = entry.characteristic->get_Uuid(&guuid); @@ -662,7 +662,7 @@ void QLowEnergyControllerPrivateWinRT::discoverServiceDetails(const QBluetoothUu HRESULT hr; hr = QEventDispatcherWinRT::runOnXamlThread([indicateChars, service, this]() { - for (const QBluetoothUuid &indicateChar : indicateChars) + for (const QBluetoothUuid &indicateChar : qAsConst(indicateChars)) registerForValueChanges(service, indicateChar); return S_OK; }); diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp index c7b9ec0b..8b4c2c10 100644 --- a/src/bluetooth/qlowenergycontrollerbase.cpp +++ b/src/bluetooth/qlowenergycontrollerbase.cpp @@ -70,7 +70,7 @@ bool QLowEnergyControllerPrivate::isValidLocalAdapter() const QList<QBluetoothHostInfo> foundAdapters = QBluetoothLocalDevice::allDevices(); bool adapterFound = false; - foreach (const QBluetoothHostInfo &info, foundAdapters) { + for (const QBluetoothHostInfo &info : foundAdapters) { if (info.address() == localAdapter) { adapterFound = true; break; @@ -255,7 +255,7 @@ quint16 QLowEnergyControllerPrivate::updateValueOfDescriptor( void QLowEnergyControllerPrivate::invalidateServices() { - foreach (const QSharedPointer<QLowEnergyServicePrivate> service, serviceList.values()) { + for (QSharedPointer<QLowEnergyServicePrivate> service : serviceList.values()) { service->setController(0); service->setState(QLowEnergyService::InvalidService); } @@ -278,7 +278,8 @@ QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( servicePrivate->uuid = service.uuid(); servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; - foreach (QLowEnergyService * const includedService, service.includedServices()) { + const QList<QLowEnergyService *> includedServices = service.includedServices(); + for (QLowEnergyService * const includedService : includedServices) { servicePrivate->includedServices << includedService->serviceUuid(); includedService->d_ptr->type |= QLowEnergyService::IncludedService; } @@ -287,14 +288,16 @@ QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { + const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics(); + for (const QLowEnergyCharacteristicData &cd : characteristics) { const QLowEnergyHandle declHandle = ++this->lastLocalHandle; QLowEnergyServicePrivate::CharData charData; charData.valueHandle = ++this->lastLocalHandle; charData.uuid = cd.uuid(); charData.properties = cd.properties(); charData.value = cd.value(); - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { + const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors(); + for (const QLowEnergyDescriptorData &dd : descriptors) { QLowEnergyServicePrivate::DescData descData; descData.uuid = dd.uuid(); descData.value = dd.value(); diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 357d3901..1529d3c2 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -510,7 +510,7 @@ QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const QList<QLowEnergyHandle> handles = d_ptr->characteristicList.keys(); std::sort(handles.begin(), handles.end()); - foreach (const QLowEnergyHandle &handle, handles) { + for (const QLowEnergyHandle &handle : qAsConst(handles)) { QLowEnergyCharacteristic characteristic(d_ptr, handle); results.append(characteristic); } diff --git a/src/bluetooth/qlowenergyservice_osx.mm b/src/bluetooth/qlowenergyservice_osx.mm index 4423887a..c294b693 100644 --- a/src/bluetooth/qlowenergyservice_osx.mm +++ b/src/bluetooth/qlowenergyservice_osx.mm @@ -129,7 +129,7 @@ QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const std::sort(handles.begin(), handles.end()); - foreach (const QLowEnergyHandle &handle, handles) { + for (const QLowEnergyHandle &handle : qAsConst(handles)) { QLowEnergyCharacteristic characteristic(d_ptr, handle); result.append(characteristic); } diff --git a/src/bluetooth/qlowenergyservicedata.cpp b/src/bluetooth/qlowenergyservicedata.cpp index f40addd2..c536da14 100644 --- a/src/bluetooth/qlowenergyservicedata.cpp +++ b/src/bluetooth/qlowenergyservicedata.cpp @@ -170,7 +170,7 @@ QList<QLowEnergyCharacteristicData> QLowEnergyServiceData::characteristics() con void QLowEnergyServiceData::setCharacteristics(const QList<QLowEnergyCharacteristicData> &characteristics) { d->characteristics.clear(); - foreach (const QLowEnergyCharacteristicData &cd, characteristics) + for (const QLowEnergyCharacteristicData &cd : characteristics) addCharacteristic(cd); } diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp index a9528462..c6c53ba4 100644 --- a/src/imports/nfc/qdeclarativenearfield.cpp +++ b/src/imports/nfc/qdeclarativenearfield.cpp @@ -211,7 +211,7 @@ void QDeclarativeNearField::registerMessageHandler() QNdefFilter ndefFilter; ndefFilter.setOrderMatch(m_orderMatch); - foreach (const QDeclarativeNdefFilter *filter, m_filterList) { + for (const QDeclarativeNdefFilter *filter : qAsConst(m_filterList)) { const QString type = filter->type(); uint min = filter->minimum() < 0 ? UINT_MAX : filter->minimum(); uint max = filter->maximum() < 0 ? UINT_MAX : filter->maximum(); @@ -236,7 +236,7 @@ void QDeclarativeNearField::_q_handleNdefMessage(const QNdefMessage &message) listRef.clear(); - foreach (const QNdefRecord &record, message) + for (const QNdefRecord &record : message) listRef.append(qNewDeclarativeNdefRecordForNdefRecord(record)); m_messageUpdating = false; diff --git a/src/nfc/android/androidmainnewintentlistener.cpp b/src/nfc/android/androidmainnewintentlistener.cpp index 09738cb8..2076453d 100644 --- a/src/nfc/android/androidmainnewintentlistener.cpp +++ b/src/nfc/android/androidmainnewintentlistener.cpp @@ -61,7 +61,7 @@ MainNfcNewIntentListener::~MainNfcNewIntentListener() bool MainNfcNewIntentListener::handleNewIntent(JNIEnv */*env*/, jobject intent) { listenersLock.lockForRead(); - foreach (AndroidNfc::AndroidNfcListenerInterface *listener, listeners) { + for (AndroidNfc::AndroidNfcListenerInterface *listener : qAsConst(listeners)) { listener->newIntent(QAndroidJniObject(intent)); } listenersLock.unlock(); diff --git a/src/nfc/neard/neard_helper.cpp b/src/nfc/neard/neard_helper.cpp index 9922c1a8..90781a5b 100644 --- a/src/nfc/neard/neard_helper.cpp +++ b/src/nfc/neard/neard_helper.cpp @@ -80,7 +80,8 @@ OrgFreedesktopDBusObjectManagerInterface *NeardHelper::dbusObjectManager() void NeardHelper::interfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList) { - foreach (const QString &key, interfaceList.keys()) { + const QList<QString> keys = interfaceList.keys(); + for (const QString &key : keys) { if (key == QStringLiteral("org.neard.Tag")) { emit tagFound(path); break; diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro index ae65640a..ed88b79a 100644 --- a/src/nfc/nfc.pro +++ b/src/nfc/nfc.pro @@ -1,5 +1,6 @@ TARGET = QtNfc QT = core +DEFINES += QT_NO_FOREACH QMAKE_DOCS = $$PWD/doc/qtnfc.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator diff --git a/src/nfc/qllcpsocket_android_p.cpp b/src/nfc/qllcpsocket_android_p.cpp index 26b50c34..97b8db16 100644 --- a/src/nfc/qllcpsocket_android_p.cpp +++ b/src/nfc/qllcpsocket_android_p.cpp @@ -208,7 +208,7 @@ qint64 QLlcpSocketPrivate::writeData(const char *data, qint64 len) qint64 QLlcpSocketPrivate::bytesAvailable() const { /*qint64 available = 0; - foreach (const QByteArray &datagram, m_receivedDatagrams) + for (const QByteArray &datagram : qAsConst(m_receivedDatagrams)) available += datagram.length(); return available;*/ @@ -217,7 +217,7 @@ qint64 QLlcpSocketPrivate::bytesAvailable() const bool QLlcpSocketPrivate::canReadLine() const { - /*foreach (const QByteArray &datagram, m_receivedDatagrams) { + /*for (const QByteArray &datagram : qAsConst(m_receivedDatagrams)) { if (datagram.contains('\n')) return true; }*/ diff --git a/src/nfc/qnearfieldmanager_android.cpp b/src/nfc/qnearfieldmanager_android.cpp index 297f8ef8..0b305501 100644 --- a/src/nfc/qnearfieldmanager_android.cpp +++ b/src/nfc/qnearfieldmanager_android.cpp @@ -65,7 +65,7 @@ extern "C" { QNearFieldManager::AdapterState adapterState = static_cast<QNearFieldManager::AdapterState>((int) state); - for (const auto listener : *broadcastListener) { + for (const auto listener : qAsConst(*broadcastListener)) { Q_EMIT listener->adapterStateChanged(adapterState); } } @@ -153,7 +153,7 @@ void QNearFieldManagerPrivateImpl::handlerNdefMessageRead(const QNdefMessage &me filterRecords.append(vr); } - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { for (int j = 0; matched && (j < filterRecords.count()); ++j) { VerifyRecord &vr = filterRecords[j]; diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp index 7c1c6e05..4df1e0ef 100644 --- a/src/nfc/qnearfieldmanager_neard.cpp +++ b/src/nfc/qnearfieldmanager_neard.cpp @@ -62,9 +62,11 @@ QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() } bool found = false; - foreach (const QDBusObjectPath &path, reply.value().keys()) { + const QList<QDBusObjectPath> paths = reply.value().keys(); + for (const QDBusObjectPath &path : paths) { const InterfaceList ifaceList = reply.value().value(path); - foreach (const QString &iface, ifaceList.keys()) { + const QStringList ifaces = ifaceList.keys(); + for (const QString &iface : ifaces) { if (iface == QStringLiteral("org.neard.Adapter")) { found = true; m_adapterPath = path.path(); @@ -106,7 +108,8 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const return false; } - foreach (const QDBusObjectPath &path, reply.value().keys()) { + const QList<QDBusObjectPath> paths = reply.value().keys(); + for (const QDBusObjectPath &path : paths) { if (m_adapterPath == path.path()) return true; } diff --git a/src/nfc/qnearfieldmanagervirtualbase.cpp b/src/nfc/qnearfieldmanagervirtualbase.cpp index 3fd97508..82e272ce 100644 --- a/src/nfc/qnearfieldmanagervirtualbase.cpp +++ b/src/nfc/qnearfieldmanagervirtualbase.cpp @@ -173,7 +173,7 @@ void QNearFieldManagerPrivateVirtualBase::ndefReceived(const QNdefMessage &messa filterRecords.append(vr); } - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { for (int j = 0; matched && (j < filterRecords.count()); ++j) { VerifyRecord &vr = filterRecords[j]; diff --git a/src/nfc/qnearfieldtagtype1.cpp b/src/nfc/qnearfieldtagtype1.cpp index 7f27fbe9..b3479203 100644 --- a/src/nfc/qnearfieldtagtype1.cpp +++ b/src/nfc/qnearfieldtagtype1.cpp @@ -279,11 +279,11 @@ void QNearFieldTagType1Private::progressToNextNdefWriteMessageState() m_tlvWriter = new QTlvWriter(q); // write old TLVs - foreach (const Tlv &tlv, m_tlvs) + for (const Tlv &tlv : qAsConst(m_tlvs)) m_tlvWriter->writeTlv(tlv.first, tlv.second); // write new NDEF message TLVs - foreach (const QNdefMessage &message, m_ndefWriteMessages) + for (const QNdefMessage &message : qAsConst(m_ndefWriteMessages)) m_tlvWriter->writeTlv(0x03, message.toByteArray()); // write terminator TLV diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h index 625cee67..9844d99e 100644 --- a/src/nfc/qnearfieldtarget_neard_p.h +++ b/src/nfc/qnearfieldtarget_neard_p.h @@ -348,7 +348,7 @@ private: if (m_readRequested) { qCDebug(QT_NFC_NEARD) << "creating Ndef message, reading" << m_recordPaths.length() << "record paths"; QNdefMessage newNdefMessage; - foreach (const QDBusObjectPath &recordPath, m_recordPaths) + for (const QDBusObjectPath &recordPath : qAsConst(m_recordPaths)) newNdefMessage.append(readRecord(recordPath)); if (!newNdefMessage.isEmpty()) { diff --git a/src/nfc/qtlv.cpp b/src/nfc/qtlv.cpp index 7aa87ac0..3168854c 100644 --- a/src/nfc/qtlv.cpp +++ b/src/nfc/qtlv.cpp @@ -284,7 +284,8 @@ bool QTlvReader::readMoreData(int sparseOffset) int QTlvReader::absoluteOffset(int sparseOffset) const { int absoluteOffset = sparseOffset; - foreach (int offset, m_reservedMemory.keys()) { + const QList<int> offsets = m_reservedMemory.keys(); + for (const int offset : offsets) { if (offset <= absoluteOffset) absoluteOffset += m_reservedMemory.value(offset); } @@ -298,7 +299,8 @@ int QTlvReader::absoluteOffset(int sparseOffset) const */ int QTlvReader::dataLength(int startOffset) const { - foreach (int offset, m_reservedMemory.keys()) { + const QList<int> offsets = m_reservedMemory.keys(); + for (const int offset : offsets) { if (offset <= startOffset) continue; |