From 9f837843c9c4d98e4d1614c624ea75fada282dd7 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sat, 10 Sep 2022 14:15:17 +0200 Subject: Refactor: for loops Replace indexed for loops with ranged for, replace int with qsizetype otherwise as appropriate. Apply const and line breaks in surrounding code. Change-Id: I1c2ee372545b8ab2cbb84c4b4b97ae52dedff1d0 Reviewed-by: Ivan Solovev (cherry picked from commit 366a6379fb80e8c223ae57b2fd791ffdfeacdbf3) Reviewed-by: Volker Hilsheimer --- .../declarativemaps/qdeclarativecirclemapitem.cpp | 53 ++++++------ .../declarativemaps/qdeclarativegeocodemodel.cpp | 6 +- .../declarativemaps/qdeclarativegeomap.cpp | 19 ++--- .../declarativemaps/qdeclarativegeomapitembase_p.h | 11 ++- .../declarativemaps/qdeclarativegeomapitemview.cpp | 10 +-- .../declarativemaps/qdeclarativegeoroutemodel.cpp | 28 +++---- .../qdeclarativegeoserviceprovider.cpp | 4 +- .../declarativemaps/qdeclarativepolygonmapitem.cpp | 14 ++-- .../qdeclarativepolygonmapitem_p_p.h | 6 +- .../qdeclarativepolylinemapitem.cpp | 19 ++--- .../qdeclarativepolylinemapitem_p_p.h | 8 +- .../declarativemaps/qgeomapitemgeometry.cpp | 8 +- .../declarativemaps/qquickgeomapgesturearea.cpp | 4 +- .../declarativeplaces/qdeclarativeplace.cpp | 6 +- .../qdeclarativesearchresultmodel.cpp | 4 +- .../qdeclarativesupportedcategoriesmodel.cpp | 2 +- src/location/labs/qdeclarativenavigator.cpp | 8 +- src/location/labs/qgeojson.cpp | 26 +++--- src/location/labs/qmapobjectview.cpp | 13 ++- src/location/maps/qgeocameratiles.cpp | 96 ++++++++++------------ src/location/maps/qgeofiletilecache.cpp | 18 ++-- src/location/maps/qgeoprojection.cpp | 6 +- src/location/maps/qgeorouteparserosrmv4.cpp | 14 ++-- src/location/maps/qgeorouteparserosrmv5.cpp | 8 +- src/location/maps/qgeoserviceprovider.cpp | 4 +- src/plugins/geoservices/esri/geocodereply_esri.cpp | 19 ++--- .../geoservices/esri/georoutejsonparser_esri.cpp | 2 +- .../geoservices/esri/placesearchreply_esri.cpp | 16 ++-- .../geoservices/mapbox/qgeofiletilecachemapbox.cpp | 35 ++++---- .../mapbox/qgeotiledmappingmanagerenginemapbox.cpp | 4 +- .../geoservices/nokia/qgeofiletilecachenokia.cpp | 10 +-- .../geoservices/nokia/qgeoroutexmlparser.cpp | 95 ++++++++++++--------- .../nokia/qgeoroutingmanagerengine_nokia.cpp | 8 +- 33 files changed, 276 insertions(+), 308 deletions(-) diff --git a/src/location/declarativemaps/qdeclarativecirclemapitem.cpp b/src/location/declarativemaps/qdeclarativecirclemapitem.cpp index 328eaae2..2bec3455 100644 --- a/src/location/declarativemaps/qdeclarativecirclemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativecirclemapitem.cpp @@ -223,24 +223,21 @@ void QGeoMapCircleGeometry::updateScreenPointsInvert(const QList &path: clippedPaths) { QDoubleVector2D lastAddedPoint; - for (int i = 0; i < path.size(); ++i) { + for (qsizetype i = 0; i < path.size(); ++i) { QDoubleVector2D point = p.wrappedMapProjectionToItemPosition(path.at(i)); //point = point - origin; // Do this using ppi.translate() if (i == 0) { ppi.moveTo(point.toPointF()); lastAddedPoint = point; - } else { - if ((point - lastAddedPoint).manhattanLength() > 3 || - i == path.size() - 1) { - ppi.lineTo(point.toPointF()); - lastAddedPoint = point; - } + } else if ((point - lastAddedPoint).manhattanLength() > 3 || i == path.size() - 1) { + ppi.lineTo(point.toPointF()); + lastAddedPoint = point; } } ppi.closeSubpath(); @@ -255,14 +252,14 @@ void QGeoMapCircleGeometry::updateScreenPointsInvert(const QList(ts.indices.data()); - for (int i = 0; i < (ts.indices.size()/3*3); ++i) + for (qsizetype i = 0; i < (ts.indices.size()/3*3); ++i) screenIndices_ << ix[i]; } else { const quint16 *ix = reinterpret_cast(ts.indices.data()); - for (int i = 0; i < (ts.indices.size()/3*3); ++i) + for (qsizetype i = 0; i < (ts.indices.size()/3*3); ++i) screenIndices_ << ix[i]; } - for (int i = 0; i < (ts.vertices.size()/2*2); i += 2) + for (qsizetype i = 0; i < (ts.vertices.size()/2*2); i += 2) screenVertices_ << QPointF(vx[i], vx[i + 1]); screenBounds_ = ppi.boundingRect(); @@ -603,12 +600,12 @@ void QDeclarativeCircleMapItemPrivate::updateCirclePathForRendering(QList wrapPathIndex; + QList wrapPathIndex; QDoubleVector2D prev = p.wrapMapProjection(path.at(0)); - for (int i = 1; i <= path.count(); ++i) { - int index = i % path.count(); - QDoubleVector2D point = p.wrapMapProjection(path.at(index)); + for (qsizetype i = 1; i <= path.count(); ++i) { + const auto index = i % path.count(); + const QDoubleVector2D point = p.wrapMapProjection(path.at(index)); double diff = qAbs(point.x() - prev.x()); if (diff > 0.5) { continue; @@ -616,10 +613,10 @@ void QDeclarativeCircleMapItemPrivate::updateCirclePathForRendering(QList= 0.5 ) { + for (qsizetype i = 1; i <= path.count(); ++i) { + const auto index = i % path.count(); + const QDoubleVector2D point = p.wrapMapProjection(path.at(index)); + if ((qAbs(point.x() - prev.x())) >= 0.5) { wrapPathIndex << index; if (wrapPathIndex.size() == 2 || !(crossNorthPole && crossSouthPole)) break; @@ -638,9 +635,9 @@ void QDeclarativeCircleMapItemPrivate::updateCirclePathForRendering(QList &locations beginResetModel(); qDeleteAll(declarativeLocations_); declarativeLocations_.clear(); - for (int i = 0; i < locations.count(); ++i) { - QDeclarativeGeoLocation *location = new QDeclarativeGeoLocation(locations.at(i), this); - declarativeLocations_.append(location); - } + for (const auto &location : locations) + declarativeLocations_.append(new QDeclarativeGeoLocation(location, this)); endResetModel(); } diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index a26209e1..8a153deb 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -458,12 +458,11 @@ void QDeclarativeGeoMap::populateMap() void QDeclarativeGeoMap::populateParameters() { QObjectList kids = children(); - QList quickKids = childItems(); - for (int i = 0; i < quickKids.count(); ++i) - kids.append(quickKids.at(i)); - for (int i = 0; i < kids.size(); ++i) { - QDeclarativeGeoMapParameter *mapParameter = qobject_cast(kids.at(i)); - if (mapParameter) + const QList quickKids = childItems(); + for (const auto &quickKid : quickKids) + kids.append(quickKid); + for (auto *kid : qAsConst(kids)) { + if (auto *mapParameter = qobject_cast(kid)) addMapParameter(mapParameter); } } @@ -2062,8 +2061,8 @@ void QDeclarativeGeoMap::clearMapItems() if (m_mapItems.isEmpty()) return; - int removed = 0; - for (int i = 0; i < m_mapItemGroups.count(); ++i) { + qsizetype removed = 0; + for (qsizetype i = 0; i < m_mapItemGroups.count(); ++i) { auto item = m_mapItemGroups.at(i); // Processing only top-level groups (!views) if (qobject_cast(item)) @@ -2395,8 +2394,8 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(const QList res; QObjectList kids = children(); - QList quickKids = childItems(); - for (int i = 0; i < quickKids.count(); ++i) - kids.append(quickKids.at(i)); - for (auto kid : qAsConst(kids)) { - auto val = qobject_cast(kid); - if (val) + const QList quickKids = childItems(); + for (const auto &quickKid : quickKids) + kids.append(quickKid); + for (auto *kid : qAsConst(kids)) { + if (auto *val = qobject_cast(kid)) res.push_back(val); } return res; diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp index e5952075..27527d35 100644 --- a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp +++ b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp @@ -188,19 +188,19 @@ void QDeclarativeGeoMapItemView::modelUpdated(const QQmlChangeSet &changeSet, bo // Remove items from the back to the front to retain the mapping to what is received from the changesets const QList &removes = changeSet.removes(); std::map mapRemoves; - for (int i = 0; i < removes.size(); i++) + for (qsizetype i = 0; i < removes.size(); i++) mapRemoves.insert(std::pair(removes.at(i).start(), i)); for (auto rit = mapRemoves.rbegin(); rit != mapRemoves.rend(); ++rit) { const QQmlChangeSet::Change &c = removes.at(rit->second); - for (int idx = c.end() - 1; idx >= c.start(); --idx) + for (auto idx = c.end() - 1; idx >= c.start(); --idx) removeDelegateFromMap(idx); } } QBoolBlocker createBlocker(m_creatingObject, true); for (const QQmlChangeSet::Change &c: changeSet.inserts()) { - for (int idx = c.start(); idx < c.end(); idx++) { + for (auto idx = c.start(); idx < c.end(); idx++) { QObject *delegateInstance = m_delegateModel->object(idx, m_incubationMode); addDelegateToMap(qobject_cast(delegateInstance), idx); } @@ -312,7 +312,7 @@ void QDeclarativeGeoMapItemView::removeInstantiatedItems(bool transition) // with transition = false removeInstantiatedItems aborts ongoing exit transitions //QTBUG-69195 // Backward as removeItemFromMap modifies m_instantiatedItems - for (int i = m_instantiatedItems.size() -1; i >= 0 ; i--) + for (qsizetype i = m_instantiatedItems.size() -1; i >= 0 ; i--) removeDelegateFromMap(i, transition); } @@ -329,7 +329,7 @@ void QDeclarativeGeoMapItemView::instantiateAllItems() // If here, m_delegateModel may contain data, but QQmlInstanceModel::object for each row hasn't been called yet. QBoolBlocker createBlocker(m_creatingObject, true); - for (int i = 0; i < m_delegateModel->count(); i++) { + for (qsizetype i = 0; i < m_delegateModel->count(); i++) { QObject *delegateInstance = m_delegateModel->object(i, m_incubationMode); addDelegateToMap(qobject_cast(delegateInstance), i); } diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp index 0d113959..d4b453b7 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp @@ -63,7 +63,7 @@ static bool compareParameterList(const QList &a, if (a.size() != b.size()) return false; if (a != b) { - for (int i = 0; i < a.size(); ++i) { + for (qsizetype i = 0; i < a.size(); ++i) { if (! (*a.at(i) == *b.at(i))) return false; } @@ -73,7 +73,7 @@ static bool compareParameterList(const QList &a, static int findWaypoint(const QList &waypoints, const QDeclarativeGeoWaypoint *w) { - for (int i = waypoints.size() - 1; i >= 0; --i) { + for (qsizetype i = waypoints.size() - 1; i >= 0; --i) { if (waypoints.at(i) == w || *waypoints.at(i) == *w) return i; } @@ -82,7 +82,7 @@ static int findWaypoint(const QList &waypoints, const static int findWaypoint(const QList &waypoints, const QGeoCoordinate &c) { - for (int i = waypoints.size() - 1; i >= 0; --i) { + for (qsizetype i = waypoints.size() - 1; i >= 0; --i) { if (waypoints.at(i)->coordinate() == c) return i; } @@ -669,10 +669,11 @@ void QDeclarativeGeoRouteModel::routingFinished(QGeoRouteReply *reply) qDeleteAll(routes_); // Convert routes to declarative routes_.clear(); - for (int i = 0; i < reply->routes().size(); ++i) { - QDeclarativeGeoRoute *route = new QDeclarativeGeoRoute(reply->routes().at(i), this); - QQmlEngine::setContextForObject(route, QQmlEngine::contextForObject(this)); - routes_.append(route); + const auto routes = reply->routes(); + for (const auto &route : routes) { + QDeclarativeGeoRoute *declroute = new QDeclarativeGeoRoute(route, this); + QQmlEngine::setContextForObject(declroute, QQmlEngine::contextForObject(this)); + routes_.append(declroute); } endResetModel(); @@ -808,9 +809,9 @@ QList QDeclarativeGeoRouteQuery::featureTypes() { QList list; - for (int i = 0; i < request_.featureTypes().count(); ++i) { - list.append(static_cast(request_.featureTypes().at(i))); - } + const auto featureTypes = request_.featureTypes(); + for (const auto &featureType : featureTypes) + list.append(static_cast(featureType)); return list; } @@ -1259,10 +1260,9 @@ void QDeclarativeGeoRouteQuery::setFeatureWeight(FeatureType featureType, Featur void QDeclarativeGeoRouteQuery::resetFeatureWeights() { // reset all feature types. - QList featureTypes = request_.featureTypes(); - for (int i = 0; i < featureTypes.count(); ++i) { - request_.setFeatureWeight(featureTypes.at(i), QGeoRouteRequest::NeutralFeatureWeight); - } + const auto featureTypes = request_.featureTypes(); + for (const auto &featureType : featureTypes) + request_.setFeatureWeight(featureType, QGeoRouteRequest::NeutralFeatureWeight); if (complete_) { emit featureTypesChanged(); emit queryDetailsChanged(); diff --git a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp index 743cba76..27c32166 100644 --- a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp +++ b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp @@ -654,10 +654,8 @@ QVariantMap QDeclarativeGeoServiceProvider::parameterMap() const { QVariantMap map; - for (int i = 0; i < parameters_.size(); ++i) { - QDeclarativePluginParameter *parameter = parameters_.at(i); + for (const auto *parameter : parameters_) map.insert(parameter->name(), parameter->value()); - } return map; } diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp index 2888ca81..8bba25be 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp @@ -178,8 +178,7 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, wrappedPath.reserve(path.size()); QDoubleVector2D wrappedLeftBound(qInf(), qInf()); // 1) - for (int i = 0; i < path.size(); ++i) { - const QDoubleVector2D &coord = path.at(i); + for (const auto &coord : path) { QDoubleVector2D wrappedProjection = p.wrapMapProjection(coord); // We can get NaN if the map isn't set up correctly, or the projection @@ -235,7 +234,7 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map, QDoubleVector2D origin = p.wrappedMapProjectionToItemPosition(leftBoundWrapped); for (const QList &path: clippedPaths) { QDoubleVector2D lastAddedPoint; - for (int i = 0; i < path.size(); ++i) { + for (qsizetype i = 0; i < path.size(); ++i) { QDoubleVector2D point = p.wrappedMapProjectionToItemPosition(path.at(i)); point = point - origin; // (0,0) if point == geoLeftBound_ @@ -351,7 +350,7 @@ static void wrapPath(const QGeoPolygon &poly ,QDoubleVector2D *leftBoundWrapped = nullptr) { QList > paths; - for (int i = 0; i < 1+poly.holesCount(); ++i) { + for (qsizetype i = 0; i < 1 + poly.holesCount(); ++i) { QList path; if (!i) { for (const QGeoCoordinate &c : poly.perimeter()) @@ -368,12 +367,9 @@ static void wrapPath(const QGeoPolygon &poly QList wrappedPath; // compute 3 sets of "wrapped" coordinates: one w regular mercator, one w regular mercator +- 1.0 - for (int j = 0; j < paths.size(); ++j) { - const QList &path = paths.at(j); + for (const auto &path : paths) { wrappedPath.clear(); - for (int i = 0; i < path.size(); ++i) { - QDoubleVector2D coord = path.at(i); - + for (QDoubleVector2D coord : path) { // We can get NaN if the map isn't set up correctly, or the projection // is faulty -- probably best thing to do is abort if (!qIsFinite(coord.x()) || !qIsFinite(coord.y())) { diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem_p_p.h b/src/location/declarativemaps/qdeclarativepolygonmapitem_p_p.h index be8aa89a..cbea7971 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem_p_p.h +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem_p_p.h @@ -126,16 +126,16 @@ public: geom->allocate(vx.size(), ix.size()); if (geom->indexType() == QSGGeometry::UnsignedShortType) { quint16 *its = geom->indexDataAsUShort(); - for (int i = 0; i < ix.size(); ++i) + for (qsizetype i = 0; i < ix.size(); ++i) its[i] = ix[i]; } else if (geom->indexType() == QSGGeometry::UnsignedIntType) { quint32 *its = geom->indexDataAsUInt(); - for (int i = 0; i < ix.size(); ++i) + for (qsizetype i = 0; i < ix.size(); ++i) its[i] = ix[i]; } QSGGeometry::Point2D *pts = geom->vertexDataAsPoint2D(); - for (int i = 0; i < vx.size(); ++i) + for (qsizetype i = 0; i < vx.size(); ++i) pts[i].set(vx[i].x, vx[i].y); } diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index edfe5e6d..5d9fbb0b 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -145,7 +145,7 @@ static QList > clipLine( // Step 1: build edges std::vector > edges; - for (int i = 1; i < poly.size(); i++) + for (qsizetype i = 1; i < poly.size(); i++) edges.push_back({ { poly.at(i-1).x(), poly.at(i-1).y(), poly.at(i).x(), poly.at(i).y() } }); edges.push_back({ { poly.at(poly.size()-1).x(), poly.at(poly.size()-1).y(), poly.at(0).x(), poly.at(0).y() } }); @@ -153,7 +153,7 @@ static QList > clipLine( QList subLine; std::array intersections = { { 0.0, 0.0, 0.0, 0.0 } }; - for (int i = 0; i < l.size() - 1; ++i) { + for (qsizetype i = 0; i < l.size() - 1; ++i) { SegmentType type = NoIntersection; double t = -1; // valid values are in [0, 1]. Only written if intersects double previousT = t; @@ -388,8 +388,7 @@ QList > QGeoMapPolylineGeometry::clipPath(const QGeoMap & wrappedPath.reserve(path.size()); QDoubleVector2D wrappedLeftBound(qInf(), qInf()); // 1) - for (int i = 0; i < path.size(); ++i) { - const QDoubleVector2D &coord = path.at(i); + for (const auto &coord : path) { QDoubleVector2D wrappedProjection = p.wrapMapProjection(coord); // We can get NaN if the map isn't set up correctly, or the projection @@ -466,7 +465,7 @@ void QGeoMapPolylineGeometry::pathToScreen(const QGeoMap &map, QDoubleVector2D origin = p.wrappedMapProjectionToItemPosition(leftBoundWrapped); for (const QList &path: clippedPaths) { QDoubleVector2D lastAddedPoint; - for (int i = 0; i < path.size(); ++i) { + for (qsizetype i = 0; i < path.size(); ++i) { QDoubleVector2D point = p.wrappedMapProjectionToItemPosition(path.at(i)); point = point - origin; // (0,0) if point == geoLeftBound_ @@ -625,7 +624,7 @@ static void clipPathToRect(const QList &points, qreal lastX = 0; qreal lastY = 0; // or else used uninitialized - for (int i = 0; i < types.size(); ++i) { + for (qsizetype i = 0; i < types.size(); ++i) { if (i > 0 && types[i] != QPainterPath::MoveToElement) { qreal x = points[i * 2], y = points[i * 2 + 1]; clipSegmentToRect(lastX, lastY, x, y, clipRect, outPoints, outTypes); @@ -732,10 +731,10 @@ bool QGeoMapPolylineGeometry::contains(const QPointF &point) const // screenOutline_ for QGeoMapPolylineGeometry is empty (QRectF(0,0 0x0)) const QList &verts = vertices(); QPolygonF tri; - for (int i = 0; i < verts.size(); ++i) { - tri << verts[i]; + for (const auto &v : verts) { + tri << v; if (tri.size() == 3) { - if (tri.containsPoint(point,Qt::OddEvenFill)) + if (tri.containsPoint(point, Qt::OddEvenFill)) return true; tri.remove(0); } @@ -1688,7 +1687,7 @@ void QGeoMapPolylineGeometryOpenGL::allocateAndFillLineStrip(QSGGeometry *geom, geom->allocate(vx.size()); QSGGeometry::Point2D *pts = geom->vertexDataAsPoint2D(); - for (int i = 0; i < vx.size(); ++i) + for (qsizetype i = 0; i < vx.size(); ++i) pts[i].set(vx[i].x, vx[i].y); } diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h index ca2fabce..50a1561b 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h @@ -339,14 +339,14 @@ public: if (m_screenVertices->size()) a = p.wrappedMapProjectionToItemPosition(p.wrapMapProjection(m_screenVertices->first().toDoubleVector2D())); QDoubleVector2D b; - for (int i = 1; i < m_screenVertices->size(); ++i) - { + for (qsizetype i = 1; i < m_screenVertices->size(); ++i) { + const auto &screenVertice = m_screenVertices->at(i); if (!a.isFinite()) { - a = p.wrappedMapProjectionToItemPosition(p.wrapMapProjection(m_screenVertices->at(i).toDoubleVector2D())); + a = p.wrappedMapProjectionToItemPosition(p.wrapMapProjection(screenVertice.toDoubleVector2D())); continue; } - b = p.wrappedMapProjectionToItemPosition(p.wrapMapProjection(m_screenVertices->at(i).toDoubleVector2D())); + b = p.wrappedMapProjectionToItemPosition(p.wrapMapProjection(screenVertice.toDoubleVector2D())); if (!b.isFinite()) { a = b; continue; diff --git a/src/location/declarativemaps/qgeomapitemgeometry.cpp b/src/location/declarativemaps/qgeomapitemgeometry.cpp index 6639f058..60ff4eec 100644 --- a/src/location/declarativemaps/qgeomapitemgeometry.cpp +++ b/src/location/declarativemaps/qgeomapitemgeometry.cpp @@ -62,7 +62,7 @@ QGeoMapItemGeometry::~QGeoMapItemGeometry() */ void QGeoMapItemGeometry::translate(const QPointF &offset) { - for (int i = 0; i < screenVertices_.size(); ++i) + for (qsizetype i = 0; i < screenVertices_.size(); ++i) screenVertices_[i] += offset; firstPointOffset_ += offset; @@ -82,11 +82,11 @@ void QGeoMapItemGeometry::allocateAndFill(QSGGeometry *geom) const geom->allocate(vx.size(), ix.size()); if (geom->indexType() == QSGGeometry::UnsignedShortType) { quint16 *its = geom->indexDataAsUShort(); - for (int i = 0; i < ix.size(); ++i) + for (qsizetype i = 0; i < ix.size(); ++i) its[i] = ix[i]; } else if (geom->indexType() == QSGGeometry::UnsignedIntType) { quint32 *its = geom->indexDataAsUInt(); - for (int i = 0; i < ix.size(); ++i) + for (qsizetype i = 0; i < ix.size(); ++i) its[i] = ix[i]; } } else { @@ -94,7 +94,7 @@ void QGeoMapItemGeometry::allocateAndFill(QSGGeometry *geom) const } QSGGeometry::Point2D *pts = geom->vertexDataAsPoint2D(); - for (int i = 0; i < vx.size(); ++i) + for (qsizetype i = 0; i < vx.size(); ++i) pts[i].set(vx[i].x(), vx[i].y()); } diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp index 4e4b5609..a6db0960 100644 --- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp +++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp @@ -943,14 +943,14 @@ void QQuickGeoMapGestureArea::handleTouchEvent(QPointerEvent *event) // They just dissapear. Child MouseArea will 'eat up' second touch point if first point // is grabbed by child ListView, for example. Maybe it's a bug in 6.2 RC? if (point.state() == QEventPoint::Released || !canBeGrabbed){ - for (int i = 0; i < m_touchPoints.count(); ++i) { + for (qsizetype i = 0; i < m_touchPoints.count(); ++i) { if (m_touchPoints.at(i).id() == point.id()){ m_touchPoints.removeAt(i); } } }else{ bool replaced = false; - for (int i = 0; i < m_touchPoints.count(); ++i) { + for (qsizetype i = 0; i < m_touchPoints.count(); ++i) { if (m_touchPoints.at(i).id() == point.id()){ m_touchPoints.replace(i, point); replaced = true; diff --git a/src/location/declarativeplaces/qdeclarativeplace.cpp b/src/location/declarativeplaces/qdeclarativeplace.cpp index 06fa7c9a..b7efffdc 100644 --- a/src/location/declarativeplaces/qdeclarativeplace.cpp +++ b/src/location/declarativeplaces/qdeclarativeplace.cpp @@ -953,9 +953,9 @@ void QDeclarativePlace::category_clear(QQmlListProperty *p if (object->m_categories.isEmpty()) return; - for (int i = 0; i < object->m_categories.count(); ++i) { - if (object->m_categories.at(i)->parent() == object) - object->m_categoriesToBeDeleted.append(object->m_categories.at(i)); + for (auto *category : qAsConst(object->m_categories)) { + if (category->parent() == object) + object->m_categoriesToBeDeleted.append(category); } object->m_categories.clear(); diff --git a/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index 93e83ce1..443c7fce 100644 --- a/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -909,7 +909,7 @@ void QDeclarativeSearchResultModel::updateLayout(const QList &favoritePl } m_resultsBuffer.clear(); - for (int i = start; i < m_results.count(); ++i) { + for (qsizetype i = start; i < m_results.count(); ++i) { const QPlaceSearchResult &result = m_results.at(i); if (result.type() == QPlaceSearchResult::PlaceResult) { @@ -996,7 +996,7 @@ void QDeclarativeSearchResultModel::removePageRow(int row) */ int QDeclarativeSearchResultModel::getRow(const QString &placeId) const { - for (int i = 0; i < m_places.count(); ++i) { + for (qsizetype i = 0; i < m_places.count(); ++i) { if (!m_places.at(i)) continue; else if (m_places.at(i)->placeId() == placeId) diff --git a/src/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp b/src/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp index 74e4b15f..070d3989 100644 --- a/src/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp @@ -690,7 +690,7 @@ QModelIndex QDeclarativeSupportedCategoriesModel::index(const QString &categoryI int QDeclarativeSupportedCategoriesModel::rowToAddChild(PlaceCategoryNode *node, const QPlaceCategory &category) { Q_ASSERT(node); - for (int i = 0; i < node->childIds.count(); ++i) { + for (qsizetype i = 0; i < node->childIds.count(); ++i) { if (category.name() < m_categoriesTree.value(node->childIds.at(i))->declCategory->name()) return i; } diff --git a/src/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp index d4374719..ffc6c454 100644 --- a/src/location/labs/qdeclarativenavigator.cpp +++ b/src/location/labs/qdeclarativenavigator.cpp @@ -761,10 +761,10 @@ void QDeclarativeNavigationBasicDirections::onAlternativeRoutesChanged() { const QList &routes = m_navigatorPrivate->m_navigator->alternativeRoutes(); QList declarativeRoutes; - for (int i = 0; i < routes.size(); ++i) { - QDeclarativeGeoRoute *route = new QDeclarativeGeoRoute(routes.at(i), &m_routes); - QQmlEngine::setContextForObject(route, QQmlEngine::contextForObject(this)); - declarativeRoutes.append(route); + for (const auto &route : routes) { + QDeclarativeGeoRoute *declroute = new QDeclarativeGeoRoute(route, &m_routes); + QQmlEngine::setContextForObject(declroute, QQmlEngine::contextForObject(this)); + declarativeRoutes.append(declroute); } m_routes.updateData(declarativeRoutes); } diff --git a/src/location/labs/qgeojson.cpp b/src/location/labs/qgeojson.cpp index f5995d9c..c6003432 100644 --- a/src/location/labs/qgeojson.cpp +++ b/src/location/labs/qgeojson.cpp @@ -518,7 +518,7 @@ static QGeoCoordinate importPosition(const QVariant &position) { QGeoCoordinate returnedCoordinates; const QVariantList positionList = position.value(); - for (int i = 0; i < positionList.size(); ++i) { // Iterating Point coordinates arrays + for (qsizetype i = 0; i < positionList.size(); ++i) { // Iterating Point coordinates arrays switch (i) { case 0: returnedCoordinates.setLongitude(positionList.at(i).toDouble()); @@ -538,13 +538,10 @@ static QGeoCoordinate importPosition(const QVariant &position) static QList importArrayOfPositions(const QVariant &arrayOfPositions) { - QList returnedCoordinates; + QList returnedCoordinates; const QVariantList positionsList = arrayOfPositions.value(); - QGeoCoordinate singlePosition; - for (int i = 0; i < positionsList.size(); ++i) { // Iterating the LineString coordinates nested arrays - singlePosition = importPosition((positionsList.at(i))); - returnedCoordinates.append(singlePosition); // Populating the QList of coordinates - } + for (const auto &position : positionsList) // Iterating the LineString coordinates nested arrays + returnedCoordinates.append(importPosition(position)); // Populating the QList of coordinates return returnedCoordinates; } @@ -552,11 +549,8 @@ static QList> importArrayOfArrayOfPositions(const QVariant { QList> returnedCoordinates; const QVariantList positionsList = arrayOfArrayofPositions.value(); - QList arrayOfPositions; - for (int i = 0; i < positionsList.size(); ++i) { // Iterating the Polygon coordinates nested arrays - arrayOfPositions = importArrayOfPositions((positionsList.at(i))); - returnedCoordinates << arrayOfPositions; - } + for (const auto &position : positionsList) // Iterating the Polygon coordinates nested arrays + returnedCoordinates << importArrayOfPositions(position); return returnedCoordinates; } @@ -584,8 +578,8 @@ static QGeoPolygon importPolygon(const QVariantMap &inputMap) { QGeoPolygon returnedObject; const QVariant valueCoordinates = inputMap.value(QStringLiteral("coordinates")); - QList> perimeters = importArrayOfArrayOfPositions(valueCoordinates); - for (int i = 0; i < perimeters.size(); ++i) { // Import an array of QList + const QList> perimeters = importArrayOfArrayOfPositions(valueCoordinates); + for (qsizetype i = 0; i < perimeters.size(); ++i) { // Import an array of QList if (i == 0) returnedObject.setPerimeter(perimeters.at(i)); // External perimeter else @@ -600,8 +594,8 @@ static QVariantList importMultiPoint(const QVariantMap &inputMap) const QVariantList coordinatesList = inputMap.value(QStringLiteral("coordinates")).value(); QVariantMap singlePointMap; QGeoCircle parsedPoint; - for (int i = 0; i < coordinatesList.size(); ++i) { // Iterating MultiPoint coordinates nasted arrays - parsedPoint.setCenter(importPosition(coordinatesList.at(i))); + for (const auto &coordinate : coordinatesList) { // Iterating MultiPoint coordinates nasted arrays + parsedPoint.setCenter(importPosition(coordinate)); singlePointMap.insert(QStringLiteral("type"), QStringLiteral("Point")); singlePointMap.insert(QStringLiteral("data"), QVariant::fromValue(parsedPoint)); returnedObject.append(QVariant::fromValue(singlePointMap)); diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp index 691811fb..4756a522 100644 --- a/src/location/labs/qmapobjectview.cpp +++ b/src/location/labs/qmapobjectview.cpp @@ -186,16 +186,13 @@ QMapObjectView::~QMapObjectView() QList QMapObjectView::geoMapObjectChildren() const { auto kids = QGeoMapObject::geoMapObjectChildren(); - auto size = m_instantiatedMapObjects.count(); - for (int i = 0; i < size; ++i) { - auto obj = qobject_cast(m_instantiatedMapObjects[i]); - if (obj) + for (const auto &object : m_instantiatedMapObjects) { + if (auto *obj = qobject_cast(object)) kids << obj; } - for (int i = 0; i < m_userAddedMapObjects.size(); ++i) { - auto obj = m_userAddedMapObjects.at(i); - if (obj) - kids << obj; + for (const auto &object : m_userAddedMapObjects) { + if (object) + kids << object; } return kids; } diff --git a/src/location/maps/qgeocameratiles.cpp b/src/location/maps/qgeocameratiles.cpp index de72df4d..fc588857 100644 --- a/src/location/maps/qgeocameratiles.cpp +++ b/src/location/maps/qgeocameratiles.cpp @@ -385,16 +385,15 @@ QPair QGeoCameraTilesPrivate::splitPolygonAtAxisVa PolygonVector polygonBelow; PolygonVector polygonAbove; - int size = polygon.size(); + const qsizetype size = polygon.size(); - if (size == 0) { + if (size == 0) return QPair(polygonBelow, polygonAbove); - } - QList comparisons = QList(polygon.size()); + QList comparisons(polygon.size()); - for (int i = 0; i < size; ++i) { - double v = polygon.at(i).get(axis); + for (qsizetype i = 0; i < size; ++i) { + const double v = polygon.at(i).get(axis); if (qFuzzyCompare(v - value + 1.0, 1.0)) { comparisons[i] = 0; } else { @@ -406,11 +405,11 @@ QPair QGeoCameraTilesPrivate::splitPolygonAtAxisVa } } - for (int index = 0; index < size; ++index) { - int prevIndex = index - 1; + for (qsizetype index = 0; index < size; ++index) { + qsizetype prevIndex = index - 1; if (prevIndex < 0) prevIndex += size; - int nextIndex = (index + 1) % size; + const qsizetype nextIndex = (index + 1) % size; int prevComp = comparisons[prevIndex]; int comp = comparisons[index]; @@ -539,9 +538,9 @@ QGeoCameraTilesPrivate::ClippedFootprint QGeoCameraTilesPrivate::clipFootprintTo QPair pair = splitPolygonAtAxisValue(results, 0, 0.0); if (pair.first.isEmpty()) { // if we touched the line but didn't cross it... - for (int i = 0; i < pair.second.size(); ++i) { - if (qFuzzyIsNull(pair.second.at(i).x())) - pair.first.append(pair.second.at(i)); + for (const auto &v : qAsConst(pair.second)) { + if (qFuzzyIsNull(v.x())) + pair.first.append(v); } if (pair.first.size() == 2) { double y0 = pair.first[0].y(); @@ -575,9 +574,9 @@ QGeoCameraTilesPrivate::ClippedFootprint QGeoCameraTilesPrivate::clipFootprintTo QPair pair = splitPolygonAtAxisValue(results, 0, side); if (pair.second.isEmpty()) { // if we touched the line but didn't cross it... - for (int i = 0; i < pair.first.size(); ++i) { - if (qFuzzyCompare(side, pair.first.at(i).x())) - pair.second.append(pair.first.at(i)); + for (const auto &v : qAsConst(pair.first)) { + if (qFuzzyCompare(side, v.x())) + pair.second.append(v); } if (pair.second.size() == 2) { double y0 = pair.second[0].y(); @@ -612,32 +611,29 @@ QGeoCameraTilesPrivate::ClippedFootprint QGeoCameraTilesPrivate::clipFootprintTo } -QList > QGeoCameraTilesPrivate::tileIntersections(double p1, int t1, double p2, int t2) const +QList> QGeoCameraTilesPrivate::tileIntersections(double p1, int t1, double p2, int t2) const { if (t1 == t2) { - QList > results = QList >(); + QList> results = QList>(); results.append(QPair(0.0, t1)); return results; } int step = 1; - if (t1 > t2) { + if (t1 > t2) step = -1; - } - int size = 1 + ((t2 - t1) / step); + qsizetype size = 1 + ((t2 - t1) / step); - QList > results = QList >(); - - results.append(QPair(0.0, t1)); + QList> results = { QPair(0.0, t1) }; if (step == 1) { - for (int i = 1; i < size; ++i) { + for (qsizetype i = 1; i < size; ++i) { double f = (t1 + i - p1) / (p2 - p1); results.append(QPair(f, t1 + i)); } } else { - for (int i = 1; i < size; ++i) { + for (qsizetype i = 1; i < size; ++i) { double f = (t1 - i + 1 - p1) / (p2 - p1); results.append(QPair(f, t1 - i)); } @@ -648,7 +644,7 @@ QList > QGeoCameraTilesPrivate::tileIntersections(double p1, QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector &polygon) const { - int numPoints = polygon.size(); + const qsizetype numPoints = polygon.size(); if (numPoints == 0) return QSet(); @@ -657,9 +653,9 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector QList tilesY(polygon.size()); // grab tiles at the corners of the polygon - for (int i = 0; i < numPoints; ++i) { + for (qsizetype i = 0; i < numPoints; ++i) { - QDoubleVector2D p = polygon.at(i).toVector2D(); + const QDoubleVector2D p = polygon.at(i).toVector2D(); int x = 0; int y = 0; @@ -687,14 +683,14 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector QGeoCameraTilesPrivate::TileMap map; // walk along the edges of the polygon and add all tiles covered by them - for (int i1 = 0; i1 < numPoints; ++i1) { - int i2 = (i1 + 1) % numPoints; + for (qsizetype i1 = 0; i1 < numPoints; ++i1) { + const qsizetype i2 = (i1 + 1) % numPoints; - double x1 = polygon.at(i1).get(0); - double x2 = polygon.at(i2).get(0); + const double x1 = polygon.at(i1).get(0); + const double x2 = polygon.at(i2).get(0); - bool xFixed = qFuzzyCompare(x1, x2); - bool xIntegral = qFuzzyCompare(x1, std::floor(x1)) || qFuzzyCompare(x1 + 1.0, std::floor(x1 + 1.0)); + const bool xFixed = qFuzzyCompare(x1, x2); + const bool xIntegral = qFuzzyCompare(x1, std::floor(x1)) || qFuzzyCompare(x1 + 1.0, std::floor(x1 + 1.0)); QList > xIntersects = tileIntersections(x1, @@ -702,11 +698,11 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector x2, tilesX.at(i2)); - double y1 = polygon.at(i1).get(1); - double y2 = polygon.at(i2).get(1); + const double y1 = polygon.at(i1).get(1); + const double y2 = polygon.at(i2).get(1); - bool yFixed = qFuzzyCompare(y1, y2); - bool yIntegral = qFuzzyCompare(y1, std::floor(y1)) || qFuzzyCompare(y1 + 1.0, std::floor(y1 + 1.0)); + const bool yFixed = qFuzzyCompare(y1, y2); + const bool yIntegral = qFuzzyCompare(y1, std::floor(y1)) || qFuzzyCompare(y1 + 1.0, std::floor(y1 + 1.0)); QList > yIntersects = tileIntersections(y1, @@ -773,10 +769,10 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector map.add(x,y); // top left corner - int iPrev = (i1 + numPoints - 1) % numPoints; - double xPrevious = polygon.at(iPrev).get(0); - double yPrevious = polygon.at(iPrev).get(1); - bool xPreviousFixed = qFuzzyCompare(xPrevious, x1); + const qsizetype iPrev = (i1 + numPoints - 1) % numPoints; + const double xPrevious = polygon.at(iPrev).get(0); + const double yPrevious = polygon.at(iPrev).get(1); + const bool xPreviousFixed = qFuzzyCompare(xPrevious, x1); if (xIntegral && xPreviousFixed && yIntegral && yFixed) { if ((x2 > x1) && (yPrevious > y1)) { if ((x - 1) > 0 && (y - 1) > 0) @@ -791,8 +787,8 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector // the x and y intersection lists are exhausted while (!xIntersects.isEmpty() && !yIntersects.isEmpty()) { - QPair nextX = xIntersects.first(); - QPair nextY = yIntersects.first(); + const QPair nextX = xIntersects.first(); + const QPair nextY = yIntersects.first(); if (nextX.first < nextY.first) { x = nextX.second; map.add(x, y); @@ -832,19 +828,13 @@ QSet QGeoCameraTilesPrivate::tilesFromPolygon(const PolygonVector QSet results; - int z = m_intZoomLevel; - - typedef QMap >::const_iterator iter; - iter i = map.data.constBegin(); - iter end = map.data.constEnd(); - - for (; i != end; ++i) { + const int z = m_intZoomLevel; + for (auto i = map.data.constBegin(); i != map.data.constEnd(); ++i) { int y = i.key(); int minX = i->first; int maxX = i->second; - for (int x = minX; x <= maxX; ++x) { + for (int x = minX; x <= maxX; ++x) results.insert(QGeoTileSpec(m_pluginString, m_mapType.mapId(), z, x, y, m_mapVersion)); - } } return results; diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp index fb596c42..191baa96 100644 --- a/src/location/maps/qgeofiletilecache.cpp +++ b/src/location/maps/qgeofiletilecache.cpp @@ -153,7 +153,7 @@ void QGeoFileTileCache::loadTiles() formats << QLatin1String("*.*"); QDir dir(directory_); - QStringList files = dir.entryList(formats, QDir::Files); + const QStringList files = dir.entryList(formats, QDir::Files); #if 0 // workaround for QTBUG-60581 // Method: // 1. read each queue file then, if each file exists, deserialize the data into the appropriate @@ -196,11 +196,11 @@ void QGeoFileTileCache::loadTiles() // 2. remaining tiles that aren't registered in a queue get pushed into cache here // this is a backup, in case the queue manifest files get deleted or out of sync due to // the application not closing down properly - for (int i = 0; i < files.size(); ++i) { - QGeoTileSpec spec = filenameToTileSpec(files.at(i)); + for (const auto &file : files) { + QGeoTileSpec spec = filenameToTileSpec(file); if (spec.zoom() == -1) continue; - QString filename = dir.filePath(files.at(i)); + QString filename = dir.filePath(file); addToDiskCache(spec, filename); } } @@ -432,22 +432,22 @@ QGeoTileSpec QGeoFileTileCache::filenameToTileSpecDefault(const QString &filenam { QGeoTileSpec emptySpec; - QStringList parts = filename.split(QLatin1Char('.')); + const QStringList parts = filename.split(QLatin1Char('.')); if (parts.length() != 2) return emptySpec; - QString name = parts.at(0); - QStringList fields = name.split(QLatin1Char('-')); + const QString name = parts.at(0); + const QStringList fields = name.split(QLatin1Char('-')); - int length = fields.length(); + qsizetype length = fields.length(); if (length != 5 && length != 6) return emptySpec; QList numbers; bool ok = false; - for (int i = 1; i < length; ++i) { + for (qsizetype i = 1; i < length; ++i) { ok = false; int value = fields.at(i).toInt(&ok); if (!ok) diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp index 47b7ad01..d39c36d6 100644 --- a/src/location/maps/qgeoprojection.cpp +++ b/src/location/maps/qgeoprojection.cpp @@ -499,11 +499,11 @@ QGeoShape QGeoProjectionWebMercator::visibleRegion() const { const QList &visibleRegion = visibleGeometry(); QGeoPolygon poly; - for (int i = 0; i < visibleRegion.size(); ++i) { + for (qsizetype i = 0; i < visibleRegion.size(); ++i) { const QDoubleVector2D &c = visibleRegion.at(i); // If a segment spans more than half of the map longitudinally, split in 2. - if (i && qAbs(visibleRegion.at(i-1).x() - c.x()) >= 0.5) { // This assumes a segment is never >= 1.0 (whole map span) - QDoubleVector2D extraPoint = (visibleRegion.at(i-1) + c) * 0.5; + if (i && qAbs(visibleRegion.at(i - 1).x() - c.x()) >= 0.5) { // This assumes a segment is never >= 1.0 (whole map span) + QDoubleVector2D extraPoint = (visibleRegion.at(i - 1) + c) * 0.5; poly.addCoordinate(wrappedMapProjectionToGeo(extraPoint)); } poly.addCoordinate(wrappedMapProjectionToGeo(c)); diff --git a/src/location/maps/qgeorouteparserosrmv4.cpp b/src/location/maps/qgeorouteparserosrmv4.cpp index 2b1545cc..a69920aa 100644 --- a/src/location/maps/qgeorouteparserosrmv4.cpp +++ b/src/location/maps/qgeorouteparserosrmv4.cpp @@ -253,13 +253,13 @@ static QGeoRoute constructRoute(const QByteArray &geometry, const QJsonArray &in { QGeoRoute route; - QList path = parsePolyline(geometry); + const QList path = parsePolyline(geometry); QGeoRouteSegment firstSegment; int firstPosition = -1; - for (int i = instructions.count() - 1; i >= 0; --i) { - QJsonArray instruction = instructions.at(i).toArray(); + for (qsizetype i = instructions.count() - 1; i >= 0; --i) { + const QJsonArray instruction = instructions.at(i).toArray(); if (instruction.count() < 8) { qWarning("Instruction does not contain enough fields."); @@ -358,16 +358,16 @@ QGeoRouteReply::Error QGeoRouteParserOsrmV4Private::parseReply(QList routes.append(route); - QJsonArray alternativeSummaries = + const QJsonArray alternativeSummaries = object.value(QStringLiteral("alternative_summaries")).toArray(); - QJsonArray alternativeGeometries = + const QJsonArray alternativeGeometries = object.value(QStringLiteral("alternative_geometries")).toArray(); - QJsonArray alternativeInstructions = + const QJsonArray alternativeInstructions = object.value(QStringLiteral("alternative_instructions")).toArray(); if (alternativeSummaries.count() == alternativeGeometries.count() && alternativeSummaries.count() == alternativeInstructions.count()) { - for (int i = 0; i < alternativeSummaries.count(); ++i) { + for (qsizetype i = 0; i < alternativeSummaries.count(); ++i) { route = constructRoute(alternativeGeometries.at(i).toString().toLatin1(), alternativeInstructions.at(i).toArray(), alternativeSummaries.at(i).toObject(), diff --git a/src/location/maps/qgeorouteparserosrmv5.cpp b/src/location/maps/qgeorouteparserosrmv5.cpp index 421b5397..d2d5b5a3 100644 --- a/src/location/maps/qgeorouteparserosrmv5.cpp +++ b/src/location/maps/qgeorouteparserosrmv5.cpp @@ -62,7 +62,7 @@ static QList decodePolyline(const QString &polylineString) if (polylineString.isEmpty()) return path; - QByteArray data = polylineString.toLatin1(); + const QByteArray data = polylineString.toLatin1(); bool parsingLatitude = true; @@ -71,7 +71,7 @@ static QList decodePolyline(const QString &polylineString) QGeoCoordinate coord(0, 0); - for (int i = 0; i < data.length(); ++i) { + for (qsizetype i = 0; i < data.length(); ++i) { unsigned char c = data.at(i) - 63; value |= (c & 0x1f) << shift; @@ -1000,7 +1000,7 @@ QGeoRouteReply::Error QGeoRouteParserOsrmV5Private::parseReply(QList for (const QGeoRouteSegment &s : segments) path.append(s.path()); - for (int i = segments.size() - 1; i > 0; --i) + for (qsizetype i = segments.size() - 1; i > 0; --i) segments[i-1].setNextRouteSegment(segments[i]); route.setDistance(distance); @@ -1031,7 +1031,7 @@ QUrl QGeoRouteParserOsrmV5Private::requestUrl(const QGeoRouteRequest &request, c QString bearings; const QList metadata = request.waypointsMetadata(); const QList waypoints = request.waypoints(); - for (int i = 0; i < waypoints.size(); i++) { + for (qsizetype i = 0; i < waypoints.size(); i++) { const QGeoCoordinate &c = waypoints.at(i); if (notFirst) { routingUrl.append(QLatin1Char(';')); diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index 72bdcf14..fbe25ce3 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -840,7 +840,7 @@ void QGeoServiceProviderPrivate::loadMeta() // figure out which version of the plugin we want // (always latest unless experimental) - for (int i = 0; i < candidates.size(); ++i) { + for (qsizetype i = 0; i < candidates.size(); ++i) { QJsonObject meta = candidates[i]; if (meta.contains(QStringLiteral("Version")) && meta.value(QStringLiteral("Version")).isDouble() @@ -906,7 +906,7 @@ void QGeoServiceProviderPrivate::loadPluginMetadata(QMultiHash meta = l->metaData(); - for (int i = 0; i < meta.size(); ++i) { + for (qsizetype i = 0; i < meta.size(); ++i) { QJsonObject obj = meta.at(i).value(QStringLiteral("MetaData")).toObject(); obj.insert(QStringLiteral("index"), i); list.insert(obj.value(QStringLiteral("Provider")).toString(), obj); diff --git a/src/plugins/geoservices/esri/geocodereply_esri.cpp b/src/plugins/geoservices/esri/geocodereply_esri.cpp index 1ef3c9d6..cc2ea378 100644 --- a/src/plugins/geoservices/esri/geocodereply_esri.cpp +++ b/src/plugins/geoservices/esri/geocodereply_esri.cpp @@ -95,18 +95,14 @@ void GeoCodeReplyEsri::networkReplyFinished() switch (operationType()) { case Geocode: { - QJsonArray candidates = object.value(QStringLiteral("candidates")).toArray(); + const QJsonArray candidates = object.value(QStringLiteral("candidates")).toArray(); QList locations; - for (int i = 0; i < candidates.count(); i++) { - if (!candidates.at(i).isObject()) + for (const auto candidate : candidates) { + if (!candidate.isObject()) continue; - - QJsonObject candidate = candidates.at(i).toObject(); - - QGeoLocation location = parseCandidate(candidate); - locations.append(location); + locations.append(parseCandidate(candidate.toObject())); } setLocations(locations); @@ -116,12 +112,7 @@ void GeoCodeReplyEsri::networkReplyFinished() case ReverseGeocode: { - QGeoLocation location = parseAddress(object); - - QList locations; - locations.append(location); - - setLocations(locations); + setLocations({parseAddress(object)}); setFinished(true); } break; diff --git a/src/plugins/geoservices/esri/georoutejsonparser_esri.cpp b/src/plugins/geoservices/esri/georoutejsonparser_esri.cpp index 34d877df..811f5cba 100644 --- a/src/plugins/geoservices/esri/georoutejsonparser_esri.cpp +++ b/src/plugins/geoservices/esri/georoutejsonparser_esri.cpp @@ -183,7 +183,7 @@ void GeoRouteJsonParserEsri::parseDirection(const QJsonObject &direction) }; QGeoRouteSegment firstSegment; - for (int i = features.size() - 1; i >= 0; --i) + for (qsizetype i = features.size() - 1; i >= 0; --i) { QJsonObject feature = features.at(i).toObject(); QJsonObject attributes = feature.value(kDirectionsFeaturesAttributesKey).toObject(); diff --git a/src/plugins/geoservices/esri/placesearchreply_esri.cpp b/src/plugins/geoservices/esri/placesearchreply_esri.cpp index 2d26d2ca..1c79a6a1 100644 --- a/src/plugins/geoservices/esri/placesearchreply_esri.cpp +++ b/src/plugins/geoservices/esri/placesearchreply_esri.cpp @@ -119,28 +119,22 @@ void PlaceSearchReplyEsri::replyFinished() return; QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); - if (!document.isObject()) - { + if (!document.isObject()) { setError(ParseError, tr("Response parse error")); return; } QJsonValue suggestions = document.object().value(kCandidatesKey); - if (!suggestions.isArray()) - { + if (!suggestions.isArray()) { setError(ParseError, tr("Response parse error")); return; } - QJsonArray resultsArray = suggestions.toArray(); + const QJsonArray resultsArray = suggestions.toArray(); QList results; - for (int i = 0; i < resultsArray.count(); ++i) - { - QJsonObject item = resultsArray.at(i).toObject(); - QPlaceResult placeResult = parsePlaceResult(item); - results.append(placeResult); - } + for (const auto result : resultsArray) + results.append(parsePlaceResult(result.toObject())); setResults(results); setFinished(true); diff --git a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp index 1dbfe018..3abe09c9 100644 --- a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp @@ -43,12 +43,14 @@ QT_BEGIN_NAMESPACE -QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList &mapTypes, int scaleFactor, const QString &directory, QObject *parent) +QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList &mapTypes, + int scaleFactor, const QString &directory, + QObject *parent) :QGeoFileTileCache(directory, parent), m_mapTypes(mapTypes) { m_scaleFactor = qBound(1, scaleFactor, 2); - for (int i=0; i < mapTypes.size(); i++) - m_mapNameToId.insert(mapTypes[i].name(), i+1); + for (qsizetype i = 0; i < mapTypes.size(); i++) + m_mapNameToId.insert(mapTypes[i].name(), i + 1); } QGeoFileTileCacheMapbox::~QGeoFileTileCacheMapbox() @@ -56,7 +58,8 @@ QGeoFileTileCacheMapbox::~QGeoFileTileCacheMapbox() } -QString QGeoFileTileCacheMapbox::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const +QString QGeoFileTileCacheMapbox::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, + const QString &directory) const { QString filename = spec.plugin(); filename += QLatin1String("-"); @@ -93,25 +96,23 @@ QGeoTileSpec QGeoFileTileCacheMapbox::filenameToTileSpec(const QString &filename if (parts.length() != 3) // 3 because the map name has always a dot in it. return QGeoTileSpec(); - QString name = parts.at(0) + QChar('.') + parts.at(1); - QStringList fields = name.split('-'); + const QString name = parts.at(0) + QChar('.') + parts.at(1); + const QStringList fields = name.split('-'); - int length = fields.length(); - if (length != 6 && length != 7) { + const qsizetype length = fields.length(); + if (length != 6 && length != 7) + return QGeoTileSpec(); + const qsizetype scaleIdx = fields.last().indexOf("@"); + if (scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2)) + return QGeoTileSpec(); + const int scaleFactor = fields.last()[scaleIdx + 1].digitValue(); + if (scaleFactor != m_scaleFactor) return QGeoTileSpec(); - } else { - int scaleIdx = fields.last().indexOf("@"); - if (scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2)) - return QGeoTileSpec(); - int scaleFactor = fields.last()[scaleIdx + 1].digitValue(); - if (scaleFactor != m_scaleFactor) - return QGeoTileSpec(); - } QList numbers; bool ok = false; - for (int i = 2; i < length-1; ++i) { // skipping -@_X + for (qsizetype i = 2; i < length - 1; ++i) { // skipping -@_X ok = false; int value = fields.at(i).toInt(&ok); if (!ok) diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp index 01c25f9d..5208e687 100644 --- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp @@ -123,8 +123,8 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q } QList mapIds; - for (int i=0; i < mapTypes.size(); ++i) - mapIds.push_back(mapTypes[i].name()); + for (const auto &mapType : qAsConst(mapTypes)) + mapIds.push_back(mapType.name()); setSupportedMapTypes(mapTypes); diff --git a/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp index 26c27d75..318f34b5 100644 --- a/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp +++ b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp @@ -87,15 +87,15 @@ QGeoTileSpec QGeoFileTileCacheNokia::filenameToTileSpec(const QString &filename) { QGeoTileSpec emptySpec; - QStringList parts = filename.split('.'); + const QStringList parts = filename.split('.'); if (parts.length() != 2) return emptySpec; - QString name = parts.at(0); - QStringList fields = name.split('-'); + const QString name = parts.at(0); + const QStringList fields = name.split('-'); - int length = fields.length(); + const qsizetype length = fields.length(); if (length != 6 && length != 7) return emptySpec; else if (fields.last() != m_ppi) @@ -104,7 +104,7 @@ QGeoTileSpec QGeoFileTileCacheNokia::filenameToTileSpec(const QString &filename) QList numbers; bool ok = false; - for (int i = 1; i < length-1; ++i) { // skipping - + for (qsizetype i = 1; i < length-1; ++i) { // skipping - ok = false; int value = fields.at(i).toInt(&ok); if (!ok) diff --git a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp index 519c8231..e09cc15a 100644 --- a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp @@ -94,7 +94,8 @@ void QGeoRouteXmlParser::run() bool QGeoRouteXmlParser::parseRootElement() { if (!m_reader->readNextStartElement()) { - m_reader->raiseError("Expected a root element named \"CalculateRoute\" (no root element found)."); + m_reader->raiseError(QStringLiteral("Expected a root element named \"CalculateRoute\" " + "(no root element found).")); return false; } @@ -106,8 +107,11 @@ bool QGeoRouteXmlParser::parseRootElement() } bool updateroute = false; - if (m_reader->name() != QLatin1String("CalculateRoute") && m_reader->name() != QLatin1String("GetRoute")) { - m_reader->raiseError(QString("The root element is expected to have the name \"CalculateRoute\" or \"GetRoute\" (root element was named \"%1\").").arg(m_reader->name().toString())); + if (m_reader->name() != QLatin1String("CalculateRoute") + && m_reader->name() != QLatin1String("GetRoute")) { + m_reader->raiseError(QStringLiteral("The root element is expected to have the name " + "\"CalculateRoute\" or \"GetRoute\" (root element " + "was named \"%1\").").arg(m_reader->name().toString())); return false; } else if (m_reader->name() == QLatin1String("GetRoute")) { updateroute = true; @@ -115,7 +119,8 @@ bool QGeoRouteXmlParser::parseRootElement() if (m_reader->readNextStartElement()) { if (m_reader->name() != QLatin1String("Response")) { - m_reader->raiseError(QString("Expected a element named \"Response\" (element was named \"%1\").").arg(m_reader->name().toString())); + m_reader->raiseError(QStringLiteral("Expected a element named \"Response\" (element " + "was named \"%1\").").arg(m_reader->name().toString())); return false; } } @@ -148,8 +153,8 @@ bool QGeoRouteXmlParser::parseRoute(QGeoRoute *route) m_legs.clear(); int legIndex = 0; m_reader->readNext(); - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QLatin1String("Route")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QLatin1String("Route")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QLatin1String("RouteId")) { route->setRouteId(m_reader->readElementText()); @@ -244,11 +249,11 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) // Step 3: populate the linkMap, linkId -> linkContainer - for (int i = 0; i < m_maneuvers.size(); i++) { + for (qsizetype i = 0; i < m_maneuvers.size(); i++) { legSegments << QList(); QList &segments = legSegments[i]; QList &maneuvers = m_maneuvers[i]; - for (int j = 0; j < m_maneuvers.at(i).size(); j++) { + for (qsizetype j = 0; j < m_maneuvers.at(i).size(); j++) { QGeoManeuverContainer &maneuver = maneuvers[j]; QGeoRouteSegment segment; @@ -273,7 +278,7 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) QGeoRouteSegment segment; QGeoRouteSegment firstSegment; for (auto &segments: legSegments) { - for (int j = 0; j < segments.size(); j++) { + for (qsizetype j = 0; j < segments.size(); j++) { if (segment.isValid()) { segment.setNextRouteSegment(segments[j]); } else { @@ -291,25 +296,26 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) route->setFirstRouteSegment(firstSegment); // Step 8: fill route legs. - for (int i = 0; i < m_legs.size(); i++) { - m_legs[i].setTravelMode(route->travelMode()); - m_legs[i].setRequest(route->request()); - m_legs[i].setOverallRoute(*route); - m_legs[i].setLegIndex(i); + for (qsizetype i = 0; i < m_legs.size(); i++) { + auto &leg = m_legs[i]; + leg.setTravelMode(route->travelMode()); + leg.setRequest(route->request()); + leg.setOverallRoute(*route); + leg.setLegIndex(i); - m_legs[i].setFirstRouteSegment(legSegments[i].first()); + leg.setFirstRouteSegment(legSegments[i].first()); // handle path QList path; - QGeoRouteSegment s = m_legs[i].firstRouteSegment(); + QGeoRouteSegment s = leg.firstRouteSegment(); while (s.isValid()) { path.append(s.path()); if (s.isLegLastSegment()) break; s = s.nextRouteSegment(); } - m_legs[i].setPath(path); - m_legs[i].setBounds(QGeoPath(path).boundingGeoRectangle()); + leg.setPath(path); + leg.setBounds(QGeoPath(path).boundingGeoRectangle()); } route->setRouteLegs(m_legs); m_legs.clear(); @@ -349,8 +355,8 @@ bool QGeoRouteXmlParser::parseMode(QGeoRoute *route) Q_ASSERT(m_reader->isStartElement() && m_reader->name() == QLatin1String("Mode")); m_reader->readNext(); - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QLatin1String("Mode")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QLatin1String("Mode")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QLatin1String("TransportModes")) { QString value = m_reader->readElementText(); @@ -386,8 +392,8 @@ bool QGeoRouteXmlParser::parseSummary(QGeoRoute *route) double baseTime = -1, trafficTime = -1; - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QLatin1String("Summary")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QLatin1String("Summary")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QLatin1String("Distance")) { route->setDistance(m_reader->readElementText().toDouble()); @@ -418,8 +424,8 @@ bool QGeoRouteXmlParser::parseCoordinates(QGeoCoordinate &coord) QString currentElement = m_reader->name().toString(); m_reader->readNext(); - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == currentElement) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == currentElement) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { QString name = m_reader->name().toString(); QString value = m_reader->readElementText(); @@ -446,8 +452,8 @@ bool QGeoRouteXmlParser::parseManeuver(QList &maneuvers) maneuverContainter.id = m_reader->attributes().value("id").toString(); m_reader->readNext(); - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QLatin1String("Maneuver")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QLatin1String("Maneuver")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QLatin1String("Position")) { QGeoCoordinate coordinates; @@ -514,8 +520,8 @@ bool QGeoRouteXmlParser::parseLink(QList &links) QGeoRouteSegmentContainer segmentContainer; - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QStringLiteral("Link")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QStringLiteral("Link")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QStringLiteral("LinkId")) { segmentContainer.id = m_reader->readElementText(); @@ -532,7 +538,8 @@ bool QGeoRouteXmlParser::parseLink(QList &links) QGeoDynamicSpeedInfoContainer speedInfo; if (!parseDynamicSpeedInfo(speedInfo)) return false; - const double time = speedInfo.trafficTime >= 0 ? speedInfo.trafficTime : speedInfo.baseTime; + const double time = speedInfo.trafficTime >= 0 + ? speedInfo.trafficTime : speedInfo.baseTime; if (time >= 0) segmentContainer.segment.setTravelTime(time); } else { @@ -548,32 +555,40 @@ bool QGeoRouteXmlParser::parseLink(QList &links) return true; } -bool QGeoRouteXmlParser::parseGeoPoints(const QString &strPoints, QList *geoPoints, const QString &elementName) +bool QGeoRouteXmlParser::parseGeoPoints(const QString &strPoints, QList *geoPoints, + const QString &elementName) { - QStringList rawPoints = strPoints.split(' '); + const QStringList rawPoints = strPoints.split(' '); - for (int i = 0; i < rawPoints.length(); ++i) { - QStringList coords = rawPoints[i].split(','); + for (const auto &rawPoint : rawPoints) { + const QStringList coords = rawPoint.split(','); if (coords.length() != 2) { - m_reader->raiseError(QString("Each of the space separated values of \"%1\" is expected to be a comma separated pair of coordinates (value was \"%2\")").arg(elementName).arg(rawPoints[i])); + m_reader->raiseError(QStringLiteral("Each of the space separated values of \"%1\" " + "is expected to be a comma separated pair of " + "coordinates (value was \"%2\")") + .arg(elementName).arg(rawPoint)); return false; } bool ok = false; - QString latString = coords[0]; + const QString latString = coords[0]; double lat = latString.toDouble(&ok); if (!ok) { - m_reader->raiseError(QString("The latitude portions of \"%1\" are expected to have a value convertable to a double (value was \"%2\")").arg(elementName).arg(latString)); + m_reader->raiseError(QStringLiteral("The latitude portions of \"%1\" are expected to " + "have a value convertable to a double (value was " + "\"%2\")").arg(elementName).arg(latString)); return false; } - QString lngString = coords[1]; + const QString lngString = coords[1]; double lng = lngString.toDouble(&ok); if (!ok) { - m_reader->raiseError(QString("The longitude portions of \"%1\" are expected to have a value convertable to a double (value was \"%2\")").arg(elementName).arg(lngString)); + m_reader->raiseError(QStringLiteral("The longitude portions of \"%1\" are expected to " + "have a value convertable to a double (value was " + "\"%2\")").arg(elementName).arg(lngString)); return false; } @@ -592,8 +607,8 @@ bool QGeoRouteXmlParser::parseBoundingBox(QGeoRectangle &bounds) QGeoCoordinate br; m_reader->readNext(); - while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == QLatin1String("BoundingBox")) && - !m_reader->hasError()) { + while (!(m_reader->tokenType() == QXmlStreamReader::EndElement + && m_reader->name() == QLatin1String("BoundingBox")) && !m_reader->hasError()) { if (m_reader->tokenType() == QXmlStreamReader::StartElement) { if (m_reader->name() == QLatin1String("TopLeft")) { QGeoCoordinate coordinates; diff --git a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp index 6d40a417..4dd4d72d 100644 --- a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp @@ -163,13 +163,13 @@ QGeoRouteReply *QGeoRoutingManagerEngineNokia::updateRoute(const QGeoRoute &rout bool QGeoRoutingManagerEngineNokia::checkEngineSupport(const QGeoRouteRequest &request, QGeoRouteRequest::TravelModes travelModes) const { - QList featureTypeList = request.featureTypes(); + const QList featureTypeList = request.featureTypes(); QGeoRouteRequest::FeatureTypes featureTypeFlag = QGeoRouteRequest::NoFeature; QGeoRouteRequest::FeatureWeights featureWeightFlag = QGeoRouteRequest::NeutralFeatureWeight; - for (int i = 0; i < featureTypeList.size(); ++i) { - featureTypeFlag |= featureTypeList.at(i); - featureWeightFlag |= request.featureWeight(featureTypeList.at(i)); + for (const auto &featureType : featureTypeList) { + featureTypeFlag |= featureType; + featureWeightFlag |= request.featureWeight(featureType); } if ((featureTypeFlag & supportedFeatureTypes()) != featureTypeFlag) -- cgit v1.2.3