summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-08 13:26:07 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-14 17:17:53 +0200
commitcfce084e080ba1e3f6d4000e084a5ecbce91612b (patch)
treea3a54e005325b94dfbe9f023511f29eb570402c9
parentbff36a2e34d8ffc4d14d9eb07d81259d848f7122 (diff)
downloadqtlocation-cfce084e080ba1e3f6d4000e084a5ecbce91612b.tar.gz
Refactor QDeclarativeGeoMapItemUtils into a namespace
The class was exported, but none of the static members or nested types are used outside the library, including tests. So turn the class into a namespace. Fix coding style issues, and convert to ranged-for loops. Change-Id: I57bc78eb91be721943608bacfc1b54ecd5b272a8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 3af758a4cf133a1d8b465a23e4967d64f0e52237) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemutils.cpp73
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemutils_p.h52
2 files changed, 67 insertions, 58 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemutils.cpp b/src/location/declarativemaps/qdeclarativegeomapitemutils.cpp
index 6bb70aa8..db5189ee 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemutils.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomapitemutils.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com>
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtLocation module of the Qt Toolkit.
@@ -50,13 +50,15 @@
QT_BEGIN_NAMESPACE
-void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QGeoCoordinate> &perimeter,
- const QGeoCoordinate &geoLeftBound,
- const QGeoProjectionWebMercator &p,
- QList<QDoubleVector2D> &wrappedPath,
- QList<QDoubleVector2D> &wrappedPathMinus1,
- QList<QDoubleVector2D> &wrappedPathPlus1,
- QDoubleVector2D *leftBoundWrapped)
+namespace QDeclarativeGeoMapItemUtils {
+
+void wrapPath(const QList<QGeoCoordinate> &perimeter,
+ const QGeoCoordinate &geoLeftBound,
+ const QGeoProjectionWebMercator &p,
+ QList<QDoubleVector2D> &wrappedPath,
+ QList<QDoubleVector2D> &wrappedPathMinus1,
+ QList<QDoubleVector2D> &wrappedPathPlus1,
+ QDoubleVector2D *leftBoundWrapped)
{
QList<QDoubleVector2D> path;
for (const QGeoCoordinate &c : perimeter)
@@ -66,9 +68,7 @@ void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QGeoCoordinate> &perimete
wrappedPathPlus1.clear();
wrappedPathMinus1.clear();
// compute 3 sets of "wrapped" coordinates: one w regular mercator, one w regular mercator +- 1.0
- 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()))
@@ -90,11 +90,11 @@ void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QGeoCoordinate> &perimete
*leftBoundWrapped = leftBound;
}
-void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QGeoCoordinate> &perimeter,
- const QGeoCoordinate &geoLeftBound,
- const QGeoProjectionWebMercator &p,
- QList<QDoubleVector2D> &wrappedPath,
- QDoubleVector2D *leftBoundWrapped)
+void wrapPath(const QList<QGeoCoordinate> &perimeter,
+ const QGeoCoordinate &geoLeftBound,
+ const QGeoProjectionWebMercator &p,
+ QList<QDoubleVector2D> &wrappedPath,
+ QDoubleVector2D *leftBoundWrapped)
{
QList<QDoubleVector2D> path;
for (const QGeoCoordinate &c : perimeter)
@@ -105,15 +105,13 @@ void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QGeoCoordinate> &perimete
*leftBoundWrapped = leftBound;
}
-void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QDoubleVector2D> &path,
- const QDoubleVector2D &geoLeftBound,
- QList<QDoubleVector2D> &wrappedPath)
+void wrapPath(const QList<QDoubleVector2D> &path,
+ const QDoubleVector2D &geoLeftBound,
+ QList<QDoubleVector2D> &wrappedPath)
{
wrappedPath.clear();
// compute 3 sets of "wrapped" coordinates: one w regular mercator, one w regular mercator +- 1.0
- 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()))
@@ -128,7 +126,11 @@ void QDeclarativeGeoMapItemUtils::wrapPath(const QList<QDoubleVector2D> &path,
}
}
-void QDeclarativeGeoMapItemUtils::clipPolygon(const QList<QDoubleVector2D> &wrappedPath, const QGeoProjectionWebMercator &p, QList<QList<QDoubleVector2D> > &clippedPaths, QDoubleVector2D *leftBoundWrapped, const bool closed)
+void clipPolygon(const QList<QDoubleVector2D> &wrappedPath,
+ const QGeoProjectionWebMercator &p,
+ QList<QList<QDoubleVector2D>> &clippedPaths,
+ QDoubleVector2D *leftBoundWrapped,
+ bool closed)
{
// 2) Clip bounding box
clippedPaths.clear();
@@ -143,11 +145,13 @@ void QDeclarativeGeoMapItemUtils::clipPolygon(const QList<QDoubleVector2D> &wrap
if (leftBoundWrapped) {
// 2.1) update srcOrigin_ and leftBoundWrapped with the point with minimum X
QDoubleVector2D lb(qInf(), qInf());
- for (const QList<QDoubleVector2D> &path: clippedPaths)
- for (const QDoubleVector2D &p: path)
+ for (const QList<QDoubleVector2D> &path : clippedPaths) {
+ for (const QDoubleVector2D &p : path) {
if (p.x() < lb.x() || (p.x() == lb.x() && p.y() < lb.y()))
// y-minimization needed to find the same point on polygon and border
lb = p;
+ }
+ }
if (qIsInf(lb.x())) // e.g., when the polygon is clipped entirely
return;
@@ -164,17 +168,24 @@ void QDeclarativeGeoMapItemUtils::clipPolygon(const QList<QDoubleVector2D> &wrap
}
}
-void QDeclarativeGeoMapItemUtils::projectBbox(const QList<QDoubleVector2D> &clippedBbox, const QGeoProjectionWebMercator &p, QPainterPath &projectedBbox)
+void projectBbox(const QList<QDoubleVector2D> &clippedBbox,
+ const QGeoProjectionWebMercator &p,
+ QPainterPath &projectedBbox)
{
- projectedBbox = QPainterPath(); // clear() is added in 5.13..
- for (int i = 0; i < clippedBbox.size(); ++i) {
- QDoubleVector2D point = p.wrappedMapProjectionToItemPosition(clippedBbox.at(i));
- if (i == 0)
+ projectedBbox.clear();
+ bool first = true;
+ for (const auto &coord : clippedBbox) {
+ QDoubleVector2D point = p.wrappedMapProjectionToItemPosition(coord);
+ if (first) {
+ first = false;
projectedBbox.moveTo(point.toPointF());
- else
+ } else {
projectedBbox.lineTo(point.toPointF());
+ }
}
projectedBbox.closeSubpath();
}
+} // namespace QDeclarativeGeoMapItemUtils
+
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemutils_p.h b/src/location/declarativemaps/qdeclarativegeomapitemutils_p.h
index 634bd262..8b636ff7 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemutils_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomapitemutils_p.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com>
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtLocation module of the Qt Toolkit.
@@ -59,9 +59,8 @@
QT_BEGIN_NAMESPACE
-class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapItemUtils
+namespace QDeclarativeGeoMapItemUtils
{
-public:
struct vec2 {
float x;
float y;
@@ -89,34 +88,33 @@ public:
}
};
- static void wrapPath(const QList<QGeoCoordinate> &perimeter
- , const QGeoCoordinate &geoLeftBound
- , const QGeoProjectionWebMercator &p
- , QList<QDoubleVector2D> &wrappedPath
- , QList<QDoubleVector2D> &wrappedPathMinus1
- , QList<QDoubleVector2D> &wrappedPathPlus1
- , QDoubleVector2D *leftBoundWrapped = nullptr);
+ void wrapPath(const QList<QGeoCoordinate> &perimeter
+ , const QGeoCoordinate &geoLeftBound
+ , const QGeoProjectionWebMercator &p
+ , QList<QDoubleVector2D> &wrappedPath
+ , QList<QDoubleVector2D> &wrappedPathMinus1
+ , QList<QDoubleVector2D> &wrappedPathPlus1
+ , QDoubleVector2D *leftBoundWrapped = nullptr);
- static void wrapPath(const QList<QGeoCoordinate> &perimeter
- , const QGeoCoordinate &geoLeftBound
- , const QGeoProjectionWebMercator &p
- , QList<QDoubleVector2D> &wrappedPath
- , QDoubleVector2D *leftBoundWrapped = nullptr);
+ void wrapPath(const QList<QGeoCoordinate> &perimeter
+ , const QGeoCoordinate &geoLeftBound
+ , const QGeoProjectionWebMercator &p
+ , QList<QDoubleVector2D> &wrappedPath
+ , QDoubleVector2D *leftBoundWrapped = nullptr);
- static void wrapPath(const QList<QDoubleVector2D> &path
- , const QDoubleVector2D &geoLeftBound
- , QList<QDoubleVector2D> &wrappedPath);
+ void wrapPath(const QList<QDoubleVector2D> &path
+ , const QDoubleVector2D &geoLeftBound
+ , QList<QDoubleVector2D> &wrappedPath);
+ void clipPolygon(const QList<QDoubleVector2D> &wrappedPath
+ , const QGeoProjectionWebMercator &p
+ , QList<QList<QDoubleVector2D> > &clippedPaths
+ , QDoubleVector2D *leftBoundWrapped = nullptr
+ , bool closed = true);
- static void clipPolygon(const QList<QDoubleVector2D> &wrappedPath
- , const QGeoProjectionWebMercator &p
- , QList<QList<QDoubleVector2D> > &clippedPaths
- , QDoubleVector2D *leftBoundWrapped = nullptr
- , bool closed = true);
-
- static void projectBbox(const QList<QDoubleVector2D> &clippedBbox
- , const QGeoProjectionWebMercator &p
- , QPainterPath &projectedBbox);
+ void projectBbox(const QList<QDoubleVector2D> &clippedBbox
+ , const QGeoProjectionWebMercator &p
+ , QPainterPath &projectedBbox);
};