diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-09-16 12:21:25 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-09-17 06:48:29 +0000 |
commit | 02fb93fe705c424cffdc25712120264f7de1b187 (patch) | |
tree | 81be0265dec253de305823914229eb614beae994 /src | |
parent | dd9e3fbf7a5a826e1cca728ec04bdc5b25d9d801 (diff) | |
download | qtivi-02fb93fe705c424cffdc25712120264f7de1b187.tar.gz |
Eradicate Q_FOREACH loops and mark the module as Q_FOREACH-free
Made QIviServiceManagerPrivate::findServiceByInterface() const to avoid
the use of qAsConst() there; required to mark loadServiceBackendInterface()
as const, too.
In the tests, replaced patterns of the form
zones = ...;
zones.removeall("Dummy");
Q_FOREACH(..., zones)
with
const zones = ...
for (... : zones) {
if ( == QLatin1String("Dummy"))
continue;
Change-Id: Ia9537e10f2d9133cbfb88beffabb0a072c3ffefc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
Diffstat (limited to 'src')
8 files changed, 23 insertions, 17 deletions
diff --git a/src/ivicore/qiviabstractfeature.cpp b/src/ivicore/qiviabstractfeature.cpp index ad8f52f..b2ef32f 100644 --- a/src/ivicore/qiviabstractfeature.cpp +++ b/src/ivicore/qiviabstractfeature.cpp @@ -546,7 +546,7 @@ QIviAbstractFeature::DiscoveryResult QIviAbstractFeature::startAutoDiscovery() qWarning() << "There is more than one backend implementing" << d->m_interface << "."; bool serviceObjectSet = false; - foreach (QIviServiceObject* object, serviceObjects) { + for (QIviServiceObject* object : qAsConst(serviceObjects)) { if (setServiceObject(object)) { serviceObjectSet = true; break; diff --git a/src/ivicore/qiviabstractzonedfeature.cpp b/src/ivicore/qiviabstractzonedfeature.cpp index bc98896..117bb19 100644 --- a/src/ivicore/qiviabstractzonedfeature.cpp +++ b/src/ivicore/qiviabstractzonedfeature.cpp @@ -228,7 +228,8 @@ void QIviAbstractZonedFeature::initializeZones() return; Q_D(QIviAbstractZonedFeature); - foreach (const QString &zone, backend()->availableZones()) { + const auto zones = backend()->availableZones(); + for (const QString &zone : zones) { QIviAbstractZonedFeature* f = zoneAt(zone); if (!f) { if (this->zone() == zone) @@ -271,7 +272,7 @@ QStringList QIviAbstractZonedFeature::availableZones() const QIviAbstractZonedFeature *QIviAbstractZonedFeature::zoneAt(const QString &zone) const { Q_D(const QIviAbstractZonedFeature); - foreach (QIviAbstractZonedFeature *f, d->m_zoneFeatures) + for (QIviAbstractZonedFeature *f : d->m_zoneFeatures) if (f->zone() == zone) return f; return 0; diff --git a/src/ivicore/qiviqmlconversion_helper.h b/src/ivicore/qiviqmlconversion_helper.h index 7d8ff78..9e59d6d 100644 --- a/src/ivicore/qiviqmlconversion_helper.h +++ b/src/ivicore/qiviqmlconversion_helper.h @@ -71,7 +71,8 @@ template <typename T> QVariant qtivi_convertValue(const T &val) template <typename T> QVariantList qtivi_convertAvailableValues(const QVector<T> &aValues) { QVariantList list; - Q_FOREACH (const T &val, aValues) { + list.reserve(aValues.size()); + for (const T &val : aValues) { //As QML doesn't support Enums in Lists we need to convert it to int list.append(qtivi_convertValue<T>(val)); } diff --git a/src/ivicore/qiviservicemanager.cpp b/src/ivicore/qiviservicemanager.cpp index 650f6bb..bffd693 100644 --- a/src/ivicore/qiviservicemanager.cpp +++ b/src/ivicore/qiviservicemanager.cpp @@ -65,11 +65,11 @@ QIviServiceManagerPrivate *QIviServiceManagerPrivate::get(QIviServiceManager *se return serviceManager->d_ptr; } -QList<QIviServiceObject *> QIviServiceManagerPrivate::findServiceByInterface(const QString &interface, QIviServiceManager::SearchFlags searchFlags) +QList<QIviServiceObject *> QIviServiceManagerPrivate::findServiceByInterface(const QString &interface, QIviServiceManager::SearchFlags searchFlags) const { QList<QIviServiceObject*> list; - foreach (Backend *backend, m_backends) { + for (Backend *backend : m_backends) { if (backend->metaData[QLatin1String("interfaces")].toStringList().contains(interface)) { bool isSimulation = backend->metaData[QLatin1String("fileName")].toString().contains(QLatin1String("_simulation.")); @@ -92,7 +92,8 @@ QList<QIviServiceObject *> QIviServiceManagerPrivate::findServiceByInterface(con void QIviServiceManagerPrivate::searchPlugins() { bool found = false; - foreach (const QString &pluginDir, QCoreApplication::libraryPaths()) { + const auto pluginDirs = QCoreApplication::libraryPaths(); + for (const QString &pluginDir : pluginDirs) { QDir dir(pluginDir); QString path = pluginDir + QDir::separator() + QLatin1Literal(QIVI_PLUGIN_DIRECTORY); @@ -100,8 +101,8 @@ void QIviServiceManagerPrivate::searchPlugins() if (!QDir(path).exists(QStringLiteral("."))) continue; - QStringList plugins = QDir(path).entryList(QDir::Files); - foreach (const QString &pluginPath, plugins) { + const QStringList plugins = QDir(path).entryList(QDir::Files); + for (const QString &pluginPath : plugins) { if (!QLibrary::isLibrary(pluginPath)) continue; QString fileName = QDir::cleanPath(path + QLatin1Char('/') + pluginPath); @@ -202,9 +203,9 @@ void QIviServiceManagerPrivate::addBackend(Backend *backend) m_backends.append(backend); q->endInsertRows(); - foreach (const QString &interface, backend->metaData[QLatin1String("interfaces")].toStringList()) { + const auto interfaces = backend->metaData[QLatin1String("interfaces")].toStringList(); + for (const QString &interface : interfaces) m_interfaceNames.insert(interface); - } } namespace { @@ -218,7 +219,7 @@ static QIviServiceInterface *warn(const char *what, const QPluginLoader *loader) } } // unnamed namespace -QIviServiceInterface *QIviServiceManagerPrivate::loadServiceBackendInterface(struct Backend *backend) +QIviServiceInterface *QIviServiceManagerPrivate::loadServiceBackendInterface(struct Backend *backend) const { if (backend->interface) { return backend->interface; diff --git a/src/ivicore/qiviservicemanager_p.h b/src/ivicore/qiviservicemanager_p.h index f7ce588..6294ec3 100644 --- a/src/ivicore/qiviservicemanager_p.h +++ b/src/ivicore/qiviservicemanager_p.h @@ -86,7 +86,7 @@ public: static QIviServiceManagerPrivate* get(QIviServiceManager *serviceManager); - QList<QIviServiceObject*> findServiceByInterface(const QString &interface, QIviServiceManager::SearchFlags searchFlags); + QList<QIviServiceObject*> findServiceByInterface(const QString &interface, QIviServiceManager::SearchFlags searchFlags) const; void searchPlugins(); void registerBackend(const QString &fileName, const QJsonObject &metaData); @@ -95,7 +95,7 @@ public: void unloadAllBackends(); - QIviServiceInterface *loadServiceBackendInterface(struct Backend *backend); + QIviServiceInterface *loadServiceBackendInterface(struct Backend *backend) const; QList<Backend*> m_backends; QSet<QString> m_interfaceNames; diff --git a/src/ivivehiclefunctions/doc/src/qtivivehiclefunctions.qdoc b/src/ivivehiclefunctions/doc/src/qtivivehiclefunctions.qdoc index 4d69846..80f4409 100644 --- a/src/ivivehiclefunctions/doc/src/qtivivehiclefunctions.qdoc +++ b/src/ivivehiclefunctions/doc/src/qtivivehiclefunctions.qdoc @@ -101,7 +101,8 @@ Looping zones is done with QIviAbstractZonedFeature::zones(): \code - foreach (QClimateControl* z, m_climateControl->zones()) + const auto zones = m_climateControl->zones(); + for (QClimateControl *z : zones) if (z->zone() == "FrontSeat") z->setSeatHeater(true); \endcode diff --git a/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/climatecontrolbackend.cpp b/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/climatecontrolbackend.cpp index f3a61e5..149692c 100644 --- a/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/climatecontrolbackend.cpp +++ b/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/climatecontrolbackend.cpp @@ -131,7 +131,8 @@ void ClimateControlBackend::initializeAttributes() emit automaticClimateFanIntensityLevelChanged(m_automaticClimateFanIntensityLevel); emit automaticClimateFanIntensityLevelAttributeChanged(QIviPropertyAttribute<int>(false)); - foreach (QString zone, availableZones()) { + const auto zones = availableZones(); + for (const QString &zone : zones) { emit targetTemperatureAttributeChanged(m_zoneMap[zone].targetTemperatureAttribute, zone); emit targetTemperatureChanged(m_zoneMap[zone].targetTemperature, zone); emit seatCoolerAttributeChanged(m_zoneMap[zone].seatCoolerAttribute, zone); diff --git a/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/windowcontrolbackend.cpp b/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/windowcontrolbackend.cpp index e79bc5b..e2a8b04 100644 --- a/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/windowcontrolbackend.cpp +++ b/src/plugins/ivivehiclefunctions/vehiclefunction_simulator/windowcontrolbackend.cpp @@ -216,7 +216,8 @@ QStringList WindowControlBackend::availableZones() const void WindowControlBackend::initializeAttributes() { - foreach (QString zone, availableZones()) { + const auto zones = availableZones(); + for (const QString &zone : zones) { emit heaterModeChanged(m_zoneMap[zone].heaterMode, zone); emit heaterModeAttributeChanged(m_zoneMap[zone].heaterModeAttribute, zone); emit heaterEnabledChanged(m_zoneMap[zone].heaterEnabled, zone); |