summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-14 21:44:54 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-19 14:52:41 +0200
commitff4207b1a41db4d23d4d0183152776e73f252a3a (patch)
tree7462fc69d09ac167b9af512220d4e819ac0c4b42
parent29bf63108f954119a0df6c70dd283367777a7e23 (diff)
downloadqtlocation-ff4207b1a41db4d23d4d0183152776e73f252a3a.tar.gz
Cleanup: de-virtualize QGeoCodeReplyPrivate
The only call to the single virtual function, extraData(), was commented out. The subclass in the OSM plugin only wrote extra data for debug runs and the subclass in the mock plugin is never used to test anything anyway. So remove all this overhead. As a drive-by, refactor to member initialization and use qsizetype for members that refer to indices in a QList. Change-Id: I600b4637bc367ae45d51b2a7f9a3ae0b78fb77c4 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
-rw-r--r--src/location/declarativemaps/qdeclarativegeocodemodel.cpp1
-rw-r--r--src/location/maps/qgeocodereply.cpp38
-rw-r--r--src/location/maps/qgeocodereply.h9
-rw-r--r--src/location/maps/qgeocodereply_p.h10
-rw-r--r--src/plugins/geoservices/osm/qgeocodereplyosm.cpp19
-rw-r--r--src/plugins/geoservices/osm/qgeocodereplyosm.h10
-rw-r--r--src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp10
-rw-r--r--tests/auto/geotestplugin/qgeocodingmanagerengine_test.h33
8 files changed, 19 insertions, 111 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp
index c80323bd..0b958216 100644
--- a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp
+++ b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp
@@ -391,7 +391,6 @@ void QDeclarativeGeocodeModel::geocodeFinished(QGeoCodeReply *reply)
reply->deleteLater();
reply_ = 0;
int oldCount = declarativeLocations_.count();
- // const QVariantMap &extraData = QGeoCodeReplyPrivate::get(*reply)->extraData();
setLocations(reply->locations());
setError(NoError, QString());
setStatus(QDeclarativeGeocodeModel::Ready);
diff --git a/src/location/maps/qgeocodereply.cpp b/src/location/maps/qgeocodereply.cpp
index 75b78659..d9a23160 100644
--- a/src/location/maps/qgeocodereply.cpp
+++ b/src/location/maps/qgeocodereply.cpp
@@ -103,19 +103,13 @@ QGeoCodeReply::QGeoCodeReply(QObject *parent)
: QObject(parent),
d_ptr(new QGeoCodeReplyPrivate()) {}
-QGeoCodeReply::QGeoCodeReply(QGeoCodeReplyPrivate &dd, QObject *parent)
- : QObject(parent),
- d_ptr(&dd)
-{
-
-}
-
/*!
Constructs a geocode reply with a given \a error and \a errorString and the specified \a parent.
*/
QGeoCodeReply::QGeoCodeReply(Error error, const QString &errorString, QObject *parent)
: QObject(parent),
- d_ptr(new QGeoCodeReplyPrivate(error, errorString)) {}
+ d_ptr(new QGeoCodeReplyPrivate(error, errorString))
+{}
/*!
Destroys this reply object.
@@ -268,7 +262,7 @@ void QGeoCodeReply::abort()
This may be more than locations().length() if the number of responses
was less than the number requested.
*/
-int QGeoCodeReply::limit() const
+qsizetype QGeoCodeReply::limit() const
{
return d_ptr->limit;
}
@@ -277,7 +271,7 @@ int QGeoCodeReply::limit() const
Returns the offset into the entire result set at which to start
fetching results.
*/
-int QGeoCodeReply::offset() const
+qsizetype QGeoCodeReply::offset() const
{
return d_ptr->offset;
}
@@ -287,7 +281,7 @@ int QGeoCodeReply::offset() const
If \a limit is -1 then all available responses will be returned.
*/
-void QGeoCodeReply::setLimit(int limit)
+void QGeoCodeReply::setLimit(qsizetype limit)
{
d_ptr->limit = limit;
}
@@ -296,7 +290,7 @@ void QGeoCodeReply::setLimit(int limit)
Sets the offset in the entire result set at which to start
fetching result to \a offset.
*/
-void QGeoCodeReply::setOffset(int offset)
+void QGeoCodeReply::setOffset(qsizetype offset)
{
d_ptr->offset = offset;
}
@@ -333,25 +327,11 @@ void QGeoCodeReply::setOffset(int offset)
/*******************************************************************************
*******************************************************************************/
-QGeoCodeReplyPrivate::QGeoCodeReplyPrivate()
- : error(QGeoCodeReply::NoError),
- isFinished(false),
- limit(-1),
- offset(0) {}
+QGeoCodeReplyPrivate::QGeoCodeReplyPrivate() = default;
QGeoCodeReplyPrivate::QGeoCodeReplyPrivate(QGeoCodeReply::Error error, const QString &errorString)
- : error(error),
- errorString(errorString),
- isFinished(true),
- limit(-1),
- offset(0) {}
-
-QGeoCodeReplyPrivate::~QGeoCodeReplyPrivate() = default;
-
-QVariantMap QGeoCodeReplyPrivate::extraData() const
-{
- return QVariantMap();
-}
+ : error(error), errorString(errorString), isFinished(true)
+{}
const QGeoCodeReplyPrivate *QGeoCodeReplyPrivate::get(const QGeoCodeReply &reply)
{
diff --git a/src/location/maps/qgeocodereply.h b/src/location/maps/qgeocodereply.h
index 98547c01..016f430a 100644
--- a/src/location/maps/qgeocodereply.h
+++ b/src/location/maps/qgeocodereply.h
@@ -75,8 +75,8 @@ public:
QGeoShape viewport() const;
QList<QGeoLocation> locations() const;
- int limit() const;
- int offset() const;
+ qsizetype limit() const;
+ qsizetype offset() const;
virtual void abort();
@@ -87,7 +87,6 @@ Q_SIGNALS:
protected:
explicit QGeoCodeReply(QObject *parent = nullptr);
- explicit QGeoCodeReply(QGeoCodeReplyPrivate &dd, QObject *parent = nullptr);
void setError(Error error, const QString &errorString);
void setFinished(bool finished);
@@ -96,8 +95,8 @@ protected:
void addLocation(const QGeoLocation &location);
void setLocations(const QList<QGeoLocation> &locations);
- void setLimit(int limit);
- void setOffset(int offset);
+ void setLimit(qsizetype limit);
+ void setOffset(qsizetype offset);
private:
QGeoCodeReplyPrivate *d_ptr;
diff --git a/src/location/maps/qgeocodereply_p.h b/src/location/maps/qgeocodereply_p.h
index f0897bd3..3f3770fe 100644
--- a/src/location/maps/qgeocodereply_p.h
+++ b/src/location/maps/qgeocodereply_p.h
@@ -67,21 +67,19 @@ class Q_LOCATION_PRIVATE_EXPORT QGeoCodeReplyPrivate
public:
QGeoCodeReplyPrivate();
QGeoCodeReplyPrivate(QGeoCodeReply::Error error, const QString &errorString);
- virtual ~QGeoCodeReplyPrivate();
- virtual QVariantMap extraData() const;
static const QGeoCodeReplyPrivate *get(const QGeoCodeReply &reply);
static QGeoCodeReplyPrivate *get(QGeoCodeReply &reply);
- QGeoCodeReply::Error error;
+ QGeoCodeReply::Error error = QGeoCodeReply::NoError;
QString errorString;
- bool isFinished;
+ bool isFinished = false;
QGeoShape viewport;
QList<QGeoLocation> locations;
- int limit;
- int offset;
+ qsizetype limit = -1;
+ qsizetype offset = 0;
private:
Q_DISABLE_COPY(QGeoCodeReplyPrivate)
};
diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
index 22a6d1eb..6f1262a0 100644
--- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
+++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp
@@ -51,7 +51,7 @@
QT_BEGIN_NAMESPACE
QGeoCodeReplyOsm::QGeoCodeReplyOsm(QNetworkReply *reply, bool includeExtraData, QObject *parent)
-: QGeoCodeReply(*new QGeoCodeReplyOsmPrivate, parent), m_includeExtraData(includeExtraData)
+: QGeoCodeReply(parent), m_includeExtraData(includeExtraData)
{
if (!reply) {
setError(UnknownError, QStringLiteral("Null reply"));
@@ -202,21 +202,4 @@ void QGeoCodeReplyOsm::networkReplyError(QNetworkReply::NetworkError error)
setError(QGeoCodeReply::CommunicationError, reply->errorString());
}
-QGeoCodeReplyOsmPrivate::QGeoCodeReplyOsmPrivate()
-{
-
-}
-
-QGeoCodeReplyOsmPrivate::~QGeoCodeReplyOsmPrivate()
-{
-
-}
-
-QVariantMap QGeoCodeReplyOsmPrivate::extraData() const
-{
- return m_extraData;
-}
-
QT_END_NAMESPACE
-
-
diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.h b/src/plugins/geoservices/osm/qgeocodereplyosm.h
index f00a8bb2..a82d3e71 100644
--- a/src/plugins/geoservices/osm/qgeocodereplyosm.h
+++ b/src/plugins/geoservices/osm/qgeocodereplyosm.h
@@ -62,16 +62,6 @@ private:
bool m_includeExtraData = false;
};
-class QGeoCodeReplyOsmPrivate : public QGeoCodeReplyPrivate
-{
-public:
- QGeoCodeReplyOsmPrivate();
- ~QGeoCodeReplyOsmPrivate();
- QVariantMap extraData() const override;
-
- QVariantMap m_extraData;
-};
-
QT_END_NAMESPACE
#endif // QGEOCODEREPLYOSM_H
diff --git a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp
index d91815b2..2ca0bb8f 100644
--- a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp
@@ -132,11 +132,6 @@ QGeoCodeReply *QGeoCodingManagerEngineOsm::geocode(const QString &address, int l
QNetworkReply *reply = m_networkManager->get(request);
QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, m_includeExtraData, this);
- if (m_debugQuery) {
- QGeoCodeReplyOsmPrivate *replyPrivate
- = static_cast<QGeoCodeReplyOsmPrivate *>(QGeoCodeReplyPrivate::get(*geocodeReply));
- replyPrivate->m_extraData["request_url"] = url;
- }
connect(geocodeReply, &QGeoCodeReplyOsm::finished,
this, &QGeoCodingManagerEngineOsm::replyFinished);
@@ -169,11 +164,6 @@ QGeoCodeReply *QGeoCodingManagerEngineOsm::reverseGeocode(const QGeoCoordinate &
QNetworkReply *reply = m_networkManager->get(request);
QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, m_includeExtraData, this);
- if (m_debugQuery) {
- QGeoCodeReplyOsmPrivate *replyPrivate
- = static_cast<QGeoCodeReplyOsmPrivate *>(QGeoCodeReplyPrivate::get(*geocodeReply));
- replyPrivate->m_extraData["request_url"] = url;
- }
connect(geocodeReply, &QGeoCodeReplyOsm::finished,
this, &QGeoCodingManagerEngineOsm::replyFinished);
diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
index 6706a19a..8f5f9362 100644
--- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
@@ -45,29 +45,11 @@
QT_USE_NAMESPACE
-
-class GeocodeReplyTestPrivate : public QGeoCodeReplyPrivate
-{
-public:
- GeocodeReplyTestPrivate()
- {
- }
- ~GeocodeReplyTestPrivate()
- {
- }
- QVariantMap extraData() const override
- {
- return m_extraData;
- }
-
- QVariantMap m_extraData;
-};
-
class GeocodeReplyTest :public QGeoCodeReply
{
Q_OBJECT
public:
- GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply (*new GeocodeReplyTestPrivate, parent) {}
+ using QGeoCodeReply::QGeoCodeReply;
void callAddLocation ( const QGeoLocation & location ) {addLocation(location);}
void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);}
@@ -129,8 +111,6 @@ public:
if (errorCode_ == QGeoCodeReply::NoError)
setLocations(geocodeReply_, searchString, limit, offset);
- if (includeExtendedData_)
- injectExtra(geocodeReply_, extendedReplyData_);
if (finishRequestImmediately_) {
// check if we should finish with error
@@ -152,8 +132,6 @@ public:
geocodeReply_ = new GeocodeReplyTest();
connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted()));
geocodeReply_->callSetViewport(bounds);
- if (includeExtendedData_)
- injectExtra(geocodeReply_, extendedReplyData_);
if (address.street().startsWith("error")) {
errorString_ = address.street();
@@ -249,8 +227,6 @@ public:
setLocations(geocodeReply_, coordinate);
geocodeReply_->callSetViewport(bounds);
- if (includeExtendedData_)
- injectExtra(geocodeReply_, extendedReplyData_);
if (coordinate.latitude() > 70) {
errorString_ = "error";
@@ -292,13 +268,6 @@ protected:
emit finished(geocodeReply_);
}
- static void injectExtra(QGeoCodeReply *reply, const QVariantMap &extra)
- {
- GeocodeReplyTestPrivate *replyPrivate
- = static_cast<GeocodeReplyTestPrivate *>(QGeoCodeReplyPrivate::get(*reply));
- replyPrivate->m_extraData = extra;
- }
-
static void injectExtra(QGeoLocation &location, const QVariantMap &extra)
{
location.setExtendedAttributes(extra);