summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2012-02-14 13:58:22 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-20 00:22:40 +0100
commitf2f8d5dc1c74024827019378424dcf59ba3096ed (patch)
treea73bb19ba75a8b4dc664f6201bb5bd6cde139fb4
parent9b7cf2b63fb9f9ff7b3c5f05b8e916c85c66403b (diff)
downloadqtlocation-f2f8d5dc1c74024827019378424dcf59ba3096ed.tar.gz
Convert QGeoBoundingArea to use value type semantics.
This simplifies the API while keeping the same functionality. Objects of type QGeoBoundingCircle and QGeoBoundingBox can still be passed around as QGeoBoundingArea without losing their identity. QGeoBoundingArea::isValid(), ::isEmpty() and ::contains() function as one would expect. This change removes the necessity of the application developer to track and delete pointers. Change-Id: I1ee70af90319da4c77225c6a0a03601d5ff431f1 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
-rw-r--r--doc/src/snippets/places/requesthandler.h10
-rw-r--r--src/imports/location/qdeclarativegeoboundingarea_p.h2
-rw-r--r--src/imports/location/qdeclarativegeoboundingbox.cpp4
-rw-r--r--src/imports/location/qdeclarativegeoboundingbox_p.h2
-rw-r--r--src/imports/location/qdeclarativegeoboundingcircle.cpp4
-rw-r--r--src/imports/location/qdeclarativegeoboundingcircle_p.h2
-rw-r--r--src/imports/location/qdeclarativegeocodemodel.cpp8
-rw-r--r--src/imports/location/qdeclarativegeocodemodel_p.h2
-rw-r--r--src/location/location.pro1
-rw-r--r--src/location/maps/qgeocodereply.cpp6
-rw-r--r--src/location/maps/qgeocodereply.h4
-rw-r--r--src/location/maps/qgeocodereply_p.h2
-rw-r--r--src/location/maps/qgeocodingmanager.cpp6
-rw-r--r--src/location/maps/qgeocodingmanager.h6
-rw-r--r--src/location/maps/qgeocodingmanagerengine.cpp6
-rw-r--r--src/location/maps/qgeocodingmanagerengine.h6
-rw-r--r--src/location/places/qplacesearchrequest.cpp68
-rw-r--r--src/location/places/qplacesearchrequest.h4
-rw-r--r--src/location/qgeoboundingarea.cpp143
-rw-r--r--src/location/qgeoboundingarea.h39
-rw-r--r--src/location/qgeoboundingarea_p.h89
-rw-r--r--src/location/qgeoboundingbox.cpp313
-rw-r--r--src/location/qgeoboundingbox.h29
-rw-r--r--src/location/qgeoboundingbox_p.h13
-rw-r--r--src/location/qgeoboundingcircle.cpp172
-rw-r--r--src/location/qgeoboundingcircle.h22
-rw-r--r--src/location/qgeoboundingcircle_p.h13
-rw-r--r--src/plugins/geoservices/nokia/placesv1/qplacerestmanager.cpp29
-rw-r--r--src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp9
-rw-r--r--src/plugins/geoservices/nokia/qgeocodereply_nokia.h2
-rw-r--r--src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp8
-rw-r--r--src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h8
-rw-r--r--src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp16
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp157
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/declarative_core/declarative_core.pro1
-rw-r--r--tests/auto/geotestplugin/qgeocodingmanagerengine_test.h8
-rw-r--r--tests/auto/qgeoboundingarea/qgeoboundingarea.pro4
-rw-r--r--tests/auto/qgeoboundingarea/tst_qgeoboundingarea.cpp77
-rw-r--r--tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp174
-rw-r--r--tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp128
-rw-r--r--tests/auto/qgeocodereply/tst_qgeocodereply.cpp4
-rw-r--r--tests/auto/qgeocodereply/tst_qgeocodereply.h2
-rw-r--r--tests/auto/qgeocodingmanager/tst_qgeocodingmanager.cpp14
-rw-r--r--tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h8
-rw-r--r--tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp46
-rw-r--r--tests/auto/qplacesearchreply/tst_qplacesearchreply.cpp4
-rw-r--r--tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp72
48 files changed, 1054 insertions, 694 deletions
diff --git a/doc/src/snippets/places/requesthandler.h b/doc/src/snippets/places/requesthandler.h
index da151323..88f03760 100644
--- a/doc/src/snippets/places/requesthandler.h
+++ b/doc/src/snippets/places/requesthandler.h
@@ -67,7 +67,7 @@ public:
//1) Make an appropriate request
QPlaceSearchRequest searchRequest;
searchRequest.setSearchTerm("ice cream");
- searchRequest.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
+ searchRequest.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
//2) Use the manager to initiate a request and retreive a reply object
QPlaceSearchReply * searchReply = manager->search(searchRequest);
@@ -84,7 +84,7 @@ public:
//instantiate request and set parameters
QPlaceSearchRequest searchRequest;
searchRequest.setSearchTerm("ice cream");
- searchRequest.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
+ searchRequest.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
//send off a search request
/*QPlaceSearchReply * */ searchReply = manager->search(searchRequest);
@@ -153,7 +153,7 @@ public:
//! [Suggestion request]
QPlaceSearchRequest request;
request.setSearchTerm("piz");
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
/* QPlaceSearchSuggestion * */suggestionReply = manager->searchSuggestions(request);
connect(suggestionReply, SIGNAL(finished()), this, SLOT(handleSuggestionReply()));
//! [Suggestion request]
@@ -163,7 +163,7 @@ public:
{
//! [Recommendation]
QPlaceSearchRequest request;
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(12.34, 56.78)));
/* QPlaceSearchReply * */ recommendationReply = manager->recommendations(place.placeId(), request);
connect(recommendationReply, SIGNAL(finished()), this, SLOT(handleRecommendationReply()));
@@ -242,7 +242,7 @@ public:
searchRequest.setSearchTerm("Fast food"); //search term for what we are interested in
//set a search center
- searchRequest.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(2.3, 48.87)));
+ searchRequest.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(2.3, 48.87)));
//set a distance hint as a relevancy hint.
//closer places have greater weighting in the ranking of results.
diff --git a/src/imports/location/qdeclarativegeoboundingarea_p.h b/src/imports/location/qdeclarativegeoboundingarea_p.h
index 1f6a4d32..a88f1a17 100644
--- a/src/imports/location/qdeclarativegeoboundingarea_p.h
+++ b/src/imports/location/qdeclarativegeoboundingarea_p.h
@@ -56,7 +56,7 @@ class QDeclarativeGeoBoundingArea : public QObject
public:
QDeclarativeGeoBoundingArea(QObject *parent) :QObject(parent){}
- virtual QGeoBoundingArea *area() const = 0;
+ virtual QGeoBoundingArea area() const = 0;
};
QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativegeoboundingbox.cpp b/src/imports/location/qdeclarativegeoboundingbox.cpp
index ceb70e5f..750a8faf 100644
--- a/src/imports/location/qdeclarativegeoboundingbox.cpp
+++ b/src/imports/location/qdeclarativegeoboundingbox.cpp
@@ -95,9 +95,9 @@ QGeoBoundingBox QDeclarativeGeoBoundingBox::box()
return m_box;
}
-QGeoBoundingArea *QDeclarativeGeoBoundingBox::area() const
+QGeoBoundingArea QDeclarativeGeoBoundingBox::area() const
{
- return m_box.clone();
+ return m_box;
}
/*!
diff --git a/src/imports/location/qdeclarativegeoboundingbox_p.h b/src/imports/location/qdeclarativegeoboundingbox_p.h
index 639b2ca6..ba09ecf3 100644
--- a/src/imports/location/qdeclarativegeoboundingbox_p.h
+++ b/src/imports/location/qdeclarativegeoboundingbox_p.h
@@ -69,7 +69,7 @@ public:
explicit QDeclarativeGeoBoundingBox(const QGeoBoundingBox &box, QObject *parent = 0);
void setBox(const QGeoBoundingBox& box);
QGeoBoundingBox box();
- virtual QGeoBoundingArea *area() const;
+ QGeoBoundingArea area() const;
Q_INVOKABLE bool contains(QDeclarativeCoordinate* coordinate);
QDeclarativeCoordinate* bottomLeft();
diff --git a/src/imports/location/qdeclarativegeoboundingcircle.cpp b/src/imports/location/qdeclarativegeoboundingcircle.cpp
index 8b923dda..898fa6ee 100644
--- a/src/imports/location/qdeclarativegeoboundingcircle.cpp
+++ b/src/imports/location/qdeclarativegeoboundingcircle.cpp
@@ -93,9 +93,9 @@ QGeoBoundingCircle QDeclarativeGeoBoundingCircle::circle() const
return m_circle;
}
-QGeoBoundingArea *QDeclarativeGeoBoundingCircle::area() const
+QGeoBoundingArea QDeclarativeGeoBoundingCircle::area() const
{
- return m_circle.clone();
+ return circle();
}
/*!
diff --git a/src/imports/location/qdeclarativegeoboundingcircle_p.h b/src/imports/location/qdeclarativegeoboundingcircle_p.h
index 9a459ad5..4a671339 100644
--- a/src/imports/location/qdeclarativegeoboundingcircle_p.h
+++ b/src/imports/location/qdeclarativegeoboundingcircle_p.h
@@ -65,7 +65,7 @@ public:
explicit QDeclarativeGeoBoundingCircle(const QGeoBoundingCircle &circle, QObject *parent = 0);
void setCircle(const QGeoBoundingCircle& circle);
QGeoBoundingCircle circle() const;
- virtual QGeoBoundingArea *area() const;
+ QGeoBoundingArea area() const;
Q_INVOKABLE bool contains(QDeclarativeCoordinate* coordinate);
QDeclarativeCoordinate* center();
diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp
index cd8a666f..1529d738 100644
--- a/src/imports/location/qdeclarativegeocodemodel.cpp
+++ b/src/imports/location/qdeclarativegeocodemodel.cpp
@@ -141,14 +141,14 @@ void QDeclarativeGeocodeModel::componentComplete()
update();
}
-QGeoBoundingArea* QDeclarativeGeocodeModel::boundingArea()
+QGeoBoundingArea QDeclarativeGeocodeModel::boundingArea()
{
if (qobject_cast<QDeclarativeGeoBoundingBox*>(boundingArea_) && boundingBox_.isValid()) {
- return &boundingBox_;
+ return boundingBox_;
} else if (qobject_cast<QDeclarativeGeoBoundingCircle*>(boundingArea_) && boundingCircle_.isValid()) {
- return &boundingCircle_;
+ return boundingCircle_;
}
- return 0;
+ return QGeoBoundingArea();
}
/*!
diff --git a/src/imports/location/qdeclarativegeocodemodel_p.h b/src/imports/location/qdeclarativegeocodemodel_p.h
index ea15e53f..13d727bc 100644
--- a/src/imports/location/qdeclarativegeocodemodel_p.h
+++ b/src/imports/location/qdeclarativegeocodemodel_p.h
@@ -170,7 +170,7 @@ protected:
private:
void setLocations(const QList<QGeoLocation> &locations);
- QGeoBoundingArea* boundingArea();
+ QGeoBoundingArea boundingArea();
void abortRequest();
QGeocodeReply* reply_;
diff --git a/src/location/location.pro b/src/location/location.pro
index 7e0d0934..f3ea2d49 100644
--- a/src/location/location.pro
+++ b/src/location/location.pro
@@ -38,6 +38,7 @@ PUBLIC_HEADERS += \
PRIVATE_HEADERS += \
qgeoaddress_p.h \
+ qgeoboundingarea_p.h \
qgeoboundingbox_p.h \
qgeoboundingcircle_p.h \
qgeolocation_p.h \
diff --git a/src/location/maps/qgeocodereply.cpp b/src/location/maps/qgeocodereply.cpp
index 1f782347..75ad6809 100644
--- a/src/location/maps/qgeocodereply.cpp
+++ b/src/location/maps/qgeocodereply.cpp
@@ -186,7 +186,7 @@ QString QGeocodeReply::errorString() const
/*!
Sets the viewport which contains the results to \a viewport.
*/
-void QGeocodeReply::setViewport(QGeoBoundingArea *viewport)
+void QGeocodeReply::setViewport(const QGeoBoundingArea &viewport)
{
d_ptr->viewport = viewport;
}
@@ -197,7 +197,7 @@ void QGeocodeReply::setViewport(QGeoBoundingArea *viewport)
This function will return 0 if no viewport bias
was specified in the QGeocodingManager function which created this reply.
*/
-QGeoBoundingArea* QGeocodeReply::viewport() const
+QGeoBoundingArea QGeocodeReply::viewport() const
{
return d_ptr->viewport;
}
@@ -317,7 +317,6 @@ QGeocodeReplyPrivate::QGeocodeReplyPrivate()
: error(QGeocodeReply::NoError),
errorString(QLatin1String("")),
isFinished(false),
- viewport(0),
limit(-1),
offset(0) {}
@@ -325,7 +324,6 @@ QGeocodeReplyPrivate::QGeocodeReplyPrivate(QGeocodeReply::Error error, const QSt
: error(error),
errorString(errorString),
isFinished(true),
- viewport(0),
limit(-1),
offset(0) {}
diff --git a/src/location/maps/qgeocodereply.h b/src/location/maps/qgeocodereply.h
index 0456aa7d..41b50c95 100644
--- a/src/location/maps/qgeocodereply.h
+++ b/src/location/maps/qgeocodereply.h
@@ -77,7 +77,7 @@ public:
Error error() const;
QString errorString() const;
- QGeoBoundingArea* viewport() const;
+ QGeoBoundingArea viewport() const;
QList<QGeoLocation>locations() const;
int limit() const;
@@ -95,7 +95,7 @@ protected:
void setError(Error error, const QString &errorString);
void setFinished(bool finished);
- void setViewport(QGeoBoundingArea *viewport);
+ void setViewport(const QGeoBoundingArea &viewport);
void addLocation(const QGeoLocation &location);
void setLocations(const QList<QGeoLocation> &locations);
diff --git a/src/location/maps/qgeocodereply_p.h b/src/location/maps/qgeocodereply_p.h
index 13124219..35bf67f9 100644
--- a/src/location/maps/qgeocodereply_p.h
+++ b/src/location/maps/qgeocodereply_p.h
@@ -74,7 +74,7 @@ public:
QString errorString;
bool isFinished;
- QGeoBoundingArea* viewport;
+ QGeoBoundingArea viewport;
QList<QGeoLocation> locations;
int limit;
diff --git a/src/location/maps/qgeocodingmanager.cpp b/src/location/maps/qgeocodingmanager.cpp
index a78d52be..bb44c98e 100644
--- a/src/location/maps/qgeocodingmanager.cpp
+++ b/src/location/maps/qgeocodingmanager.cpp
@@ -173,7 +173,7 @@ int QGeocodingManager::managerVersion() const
QGeocodingManager::error(), QGeocodeReply::finished() or
QGeocodeReply::error() with deleteLater().
*/
-QGeocodeReply* QGeocodingManager::geocode(const QGeoAddress &address, QGeoBoundingArea *bounds)
+QGeocodeReply* QGeocodingManager::geocode(const QGeoAddress &address, const QGeoBoundingArea &bounds)
{
// if (!d_ptr->engine)
// return new QGeocodeReply(QGeocodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
@@ -218,7 +218,7 @@ QGeocodeReply* QGeocodingManager::geocode(const QGeoAddress &address, QGeoBoundi
QGeocodingManager::error(), QGeocodeReply::finished() or
QGeocodeReply::error() with deleteLater().
*/
-QGeocodeReply* QGeocodingManager::reverseGeocode(const QGeoCoordinate &coordinate, QGeoBoundingArea *bounds)
+QGeocodeReply* QGeocodingManager::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoBoundingArea &bounds)
{
// if (!d_ptr->engine)
// return new QGeocodeReply(QGeocodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
@@ -258,7 +258,7 @@ QGeocodeReply* QGeocodingManager::reverseGeocode(const QGeoCoordinate &coordinat
QGeocodeReply* QGeocodingManager::geocode(const QString &address,
int limit,
int offset,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
// if (!d_ptr->engine)
// return new QGeocodeReply(QGeocodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
diff --git a/src/location/maps/qgeocodingmanager.h b/src/location/maps/qgeocodingmanager.h
index 1f3394ec..da85132d 100644
--- a/src/location/maps/qgeocodingmanager.h
+++ b/src/location/maps/qgeocodingmanager.h
@@ -70,14 +70,14 @@ public:
int managerVersion() const;
QGeocodeReply* geocode(const QGeoAddress &address,
- QGeoBoundingArea *bounds = 0);
+ const QGeoBoundingArea &bounds = QGeoBoundingArea());
QGeocodeReply* geocode(const QString &searchString,
int limit = -1,
int offset = 0,
- QGeoBoundingArea *bounds = 0);
+ const QGeoBoundingArea &bounds = QGeoBoundingArea());
QGeocodeReply* reverseGeocode(const QGeoCoordinate &coordinate,
- QGeoBoundingArea *bounds = 0);
+ const QGeoBoundingArea &bounds = QGeoBoundingArea());
bool supportsGeocoding() const;
bool supportsReverseGeocoding() const;
diff --git a/src/location/maps/qgeocodingmanagerengine.cpp b/src/location/maps/qgeocodingmanagerengine.cpp
index a2ffe1b5..5d9412e2 100644
--- a/src/location/maps/qgeocodingmanagerengine.cpp
+++ b/src/location/maps/qgeocodingmanagerengine.cpp
@@ -175,7 +175,7 @@ int QGeocodingManagerEngine::managerVersion() const
QGeocodeReply::error() with deleteLater().
*/
QGeocodeReply* QGeocodingManagerEngine::geocode(const QGeoAddress &address,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
Q_UNUSED(address)
Q_UNUSED(bounds)
@@ -220,7 +220,7 @@ QGeocodeReply* QGeocodingManagerEngine::geocode(const QGeoAddress &address,
QGeocodeReply::error() with deleteLater().
*/
QGeocodeReply* QGeocodingManagerEngine::reverseGeocode(const QGeoCoordinate &coordinate,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
Q_UNUSED(coordinate)
Q_UNUSED(bounds)
@@ -260,7 +260,7 @@ QGeocodeReply* QGeocodingManagerEngine::reverseGeocode(const QGeoCoordinate &coo
QGeocodeReply* QGeocodingManagerEngine::geocode(const QString &address,
int limit,
int offset,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
Q_UNUSED(address)
Q_UNUSED(limit)
diff --git a/src/location/maps/qgeocodingmanagerengine.h b/src/location/maps/qgeocodingmanagerengine.h
index 8aaa4d7c..49069dd5 100644
--- a/src/location/maps/qgeocodingmanagerengine.h
+++ b/src/location/maps/qgeocodingmanagerengine.h
@@ -68,13 +68,13 @@ public:
int managerVersion() const;
virtual QGeocodeReply* geocode(const QGeoAddress &address,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
virtual QGeocodeReply* geocode(const QString &address,
int limit,
int offset,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
virtual QGeocodeReply* reverseGeocode(const QGeoCoordinate &coordinate,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
diff --git a/src/location/places/qplacesearchrequest.cpp b/src/location/places/qplacesearchrequest.cpp
index 57387c2c..2403bae8 100644
--- a/src/location/places/qplacesearchrequest.cpp
+++ b/src/location/places/qplacesearchrequest.cpp
@@ -62,7 +62,7 @@ public:
QString searchTerm;
QList<QPlaceCategory> categories;
- QGeoBoundingArea *searchArea;
+ QGeoBoundingArea searchArea;
int dymNumber;
QtLocation::VisibilityScope visibilityScope;
QPlaceSearchRequest::RelevanceHint relevanceHint;
@@ -71,10 +71,9 @@ public:
};
QPlaceSearchRequestPrivate::QPlaceSearchRequestPrivate()
- : QSharedData(),
- searchArea(0), dymNumber(0),
- visibilityScope(QtLocation::UnspecifiedVisibility), relevanceHint(QPlaceSearchRequest::UnspecifiedHint),
- limit(-1), offset(0)
+: QSharedData(), dymNumber(0),
+ visibilityScope(QtLocation::UnspecifiedVisibility), relevanceHint(QPlaceSearchRequest::UnspecifiedHint),
+ limit(-1), offset(0)
{
}
@@ -82,22 +81,17 @@ QPlaceSearchRequestPrivate::QPlaceSearchRequestPrivate(const QPlaceSearchRequest
: QSharedData(other),
searchTerm(other.searchTerm),
categories(other.categories),
+ searchArea(other.searchArea),
dymNumber(other.dymNumber),
visibilityScope(other.visibilityScope),
relevanceHint(other.relevanceHint),
limit(other.limit),
offset(other.offset)
{
-
- if (other.searchArea)
- searchArea = other.searchArea->clone();
- else
- searchArea = 0;
}
QPlaceSearchRequestPrivate::~QPlaceSearchRequestPrivate()
{
- delete searchArea;
}
QPlaceSearchRequestPrivate &QPlaceSearchRequestPrivate::operator=(const QPlaceSearchRequestPrivate &other)
@@ -105,10 +99,7 @@ QPlaceSearchRequestPrivate &QPlaceSearchRequestPrivate::operator=(const QPlaceSe
if (this != &other) {
searchTerm = other.searchTerm;
categories = other.categories;
- if (other.searchArea)
- searchArea = other.searchArea->clone();
- else
- searchArea = 0;
+ searchArea = other.searchArea;
dymNumber = other.dymNumber;
visibilityScope = other.visibilityScope;
relevanceHint = other.relevanceHint;
@@ -121,28 +112,14 @@ QPlaceSearchRequestPrivate &QPlaceSearchRequestPrivate::operator=(const QPlaceSe
bool QPlaceSearchRequestPrivate::operator==(const QPlaceSearchRequestPrivate &other) const
{
- bool searchAreaMatch = false;
- if ((searchArea == 0) && (other.searchArea == 0)) {
- searchAreaMatch = true;
- } else if (searchArea && other.searchArea) {
- if (*searchArea == *(other.searchArea))
- searchAreaMatch = true;
- else
- searchAreaMatch = false;
- } else {
- searchAreaMatch = false;
- }
-
- return (
- searchTerm == other.searchTerm
- && categories == other.categories
- && dymNumber == other.dymNumber
- && searchAreaMatch
- && visibilityScope == other.visibilityScope
- && relevanceHint == other.relevanceHint
- && limit == other.limit
- && offset == other.offset
- );
+ return searchTerm == other.searchTerm &&
+ categories == other.categories &&
+ searchArea == other.searchArea &&
+ dymNumber == other.dymNumber &&
+ visibilityScope == other.visibilityScope &&
+ relevanceHint == other.relevanceHint &&
+ limit == other.limit &&
+ offset == other.offset;
}
void QPlaceSearchRequestPrivate::clear()
@@ -151,8 +128,7 @@ void QPlaceSearchRequestPrivate::clear()
offset = 0;
searchTerm.clear();
categories.clear();
- delete searchArea;
- searchArea = 0;
+ searchArea = QGeoBoundingArea();
dymNumber = 0;
visibilityScope = QtLocation::UnspecifiedVisibility;
relevanceHint = QPlaceSearchRequest::UnspecifiedHint;
@@ -315,25 +291,21 @@ void QPlaceSearchRequest::setCategories(const QList<QPlaceCategory> &categories)
}
/*!
- Returns search area. The default search area is a null pointer.
+ Returns the search area which will be used to limit search results. The default search area is
+ an invalid QGeoBoundingArea, indicating that no specific search area is defined.
*/
-QGeoBoundingArea *QPlaceSearchRequest::searchArea() const
+QGeoBoundingArea QPlaceSearchRequest::searchArea() const
{
Q_D(const QPlaceSearchRequest);
return d->searchArea;
}
/*!
- Sets the search request to search within the given \a area. Ownership of the \a area is
- transferred to the request, who is now responsible for pointer deletion. If a new \a area
- is being assigned, the old area is deleted.
+ Sets the search request to search within the given \a area.
*/
-void QPlaceSearchRequest::setSearchArea(QGeoBoundingArea *area)
+void QPlaceSearchRequest::setSearchArea(const QGeoBoundingArea &area)
{
Q_D(QPlaceSearchRequest);
- if (d->searchArea != area)
- delete d->searchArea;
-
d->searchArea = area;
}
diff --git a/src/location/places/qplacesearchrequest.h b/src/location/places/qplacesearchrequest.h
index 9102ea41..6cbcc5ad 100644
--- a/src/location/places/qplacesearchrequest.h
+++ b/src/location/places/qplacesearchrequest.h
@@ -83,8 +83,8 @@ public:
void setCategory(const QPlaceCategory &category);
void setCategories(const QList<QPlaceCategory> &categories);
- QGeoBoundingArea *searchArea() const;
- void setSearchArea(QGeoBoundingArea *area);
+ QGeoBoundingArea searchArea() const;
+ void setSearchArea(const QGeoBoundingArea &area);
int maximumCorrections() const;
void setMaximumCorrections(int number);
diff --git a/src/location/qgeoboundingarea.cpp b/src/location/qgeoboundingarea.cpp
index bfbb2b71..e9f82f7f 100644
--- a/src/location/qgeoboundingarea.cpp
+++ b/src/location/qgeoboundingarea.cpp
@@ -40,9 +40,24 @@
****************************************************************************/
#include "qgeoboundingarea.h"
+#include "qgeoboundingarea_p.h"
QT_BEGIN_NAMESPACE
+QGeoBoundingAreaPrivate::QGeoBoundingAreaPrivate(QGeoBoundingArea::AreaType type)
+: type(type)
+{
+}
+
+QGeoBoundingAreaPrivate::~QGeoBoundingAreaPrivate()
+{
+}
+
+bool QGeoBoundingAreaPrivate::operator==(const QGeoBoundingAreaPrivate &other) const
+{
+ return type == other.type;
+}
+
/*!
\class QGeoBoundingArea
\inmodule QtLocation
@@ -69,59 +84,125 @@ QT_BEGIN_NAMESPACE
\value CircleType A circular bounding area.
*/
-/*!
- Destroys this bounding area.
-*/
-QGeoBoundingArea::~QGeoBoundingArea() {}
+inline QGeoBoundingAreaPrivate *QGeoBoundingArea::d_func()
+{
+ return static_cast<QGeoBoundingAreaPrivate *>(d_ptr.data());
+}
-/*!
-\fn virtual QGeoBoundingArea::AreaType QGeoBoundingArea::type() const
+inline const QGeoBoundingAreaPrivate *QGeoBoundingArea::d_func() const
+{
+ return static_cast<const QGeoBoundingAreaPrivate *>(d_ptr.constData());
+}
-Returns the type of this area.
-*/
+QGeoBoundingArea::QGeoBoundingArea()
+{
+}
-/*!
-\fn bool QGeoBoundingArea::isValid() const
+QGeoBoundingArea::QGeoBoundingArea(const QGeoBoundingArea &other)
+: d_ptr(other.d_ptr)
+{
+}
-Returns whether this bounding area is valid.
+QGeoBoundingArea::QGeoBoundingArea(QGeoBoundingAreaPrivate *d)
+: d_ptr(d)
+{
+}
-An area is considered to be invalid if some of the data that is required to
-unambiguously describe the area has not been set or has been set to an
-unsuitable value.
+/*!
+ Destroys this bounding area.
*/
+QGeoBoundingArea::~QGeoBoundingArea()
+{
+}
/*!
-\fn bool QGeoBoundingArea::isEmpty() const
-
-Returns whether this bounding area is empty.
-
-An empty area is a region which has a geometrical area of 0.
+ Returns the type of this area.
*/
+QGeoBoundingArea::AreaType QGeoBoundingArea::type() const
+{
+ Q_D(const QGeoBoundingArea);
+
+ if (d)
+ return d->type;
+ else
+ return UnknownType;
+}
/*!
-\fn bool QGeoBoundingArea::contains(const QGeoCoordinate &coordinate) const
+ Returns whether this bounding area is valid.
-Returns whether the coordinate \a coordinate is contained within this
-area.
+ An area is considered to be invalid if some of the data that is required to
+ unambiguously describe the area has not been set or has been set to an
+ unsuitable value.
*/
+bool QGeoBoundingArea::isValid() const
+{
+ Q_D(const QGeoBoundingArea);
+
+ if (d)
+ return d->isValid();
+ else
+ return false;
+}
/*!
-\fn QGeoBoundingArea* QGeoBoundingArea::clone() const
+ Returns whether this bounding area is empty.
-Creates a new QGeoBoundingArea that is a deep copy of this bounding area.
+ An empty area is a region which has a geometrical area of 0.
*/
+bool QGeoBoundingArea::isEmpty() const
+{
+ Q_D(const QGeoBoundingArea);
-/*!
-\fn bool QGeoBoundingArea::operator==(const QGeoBoundingArea &other) const
+ if (d)
+ return d->isEmpty();
+ else
+ return true;
+}
- Returns true if the \a other bounding area is equivalent to this bounding area,
- otherwise returns false.
+/*!
+ Returns whether the coordinate \a coordinate is contained within this area.
*/
+bool QGeoBoundingArea::contains(const QGeoCoordinate &coordinate) const
+{
+ Q_D(const QGeoBoundingArea);
+
+ if (d)
+ return d->contains(coordinate);
+ else
+ return false;
+}
+
/*!
- \fn bool QGeoBoundingArea::operator!=(const QGeoBoundingArea &other) const
- Returns true if \a other is not equivalent to this bounding area,
- otherwise returns false.
+ Returns true if the \a other bounding area is equivalent to this bounding area, otherwise
+ returns false
*/
+bool QGeoBoundingArea::operator==(const QGeoBoundingArea &other) const
+{
+ Q_D(const QGeoBoundingArea);
+
+ if (d == other.d_func())
+ return true;
+
+ if (d && !other.d_func())
+ return false;
+
+ if (!d && other.d_func())
+ return false;
+
+ return *d == *other.d_func();
+}
+
+bool QGeoBoundingArea::operator!=(const QGeoBoundingArea &other) const
+{
+ return !(*this == other);
+}
+
+QGeoBoundingArea &QGeoBoundingArea::operator=(const QGeoBoundingArea &other)
+{
+ d_ptr = other.d_ptr;
+ return *this;
+}
QT_END_NAMESPACE
diff --git a/src/location/qgeoboundingarea.h b/src/location/qgeoboundingarea.h
index 7a3e3a8e..e1b8c8f2 100644
--- a/src/location/qgeoboundingarea.h
+++ b/src/location/qgeoboundingarea.h
@@ -42,38 +42,53 @@
#ifndef QGEOBOUNDINGAREA_H
#define QGEOBOUNDINGAREA_H
-#include "qgeocoordinate.h"
-
-#include <QSharedDataPointer>
+#include <QtCore/QSharedDataPointer>
+#include <QtLocation/QGeoCoordinate>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
+class QGeoBoundingAreaPrivate;
class Q_LOCATION_EXPORT QGeoBoundingArea
{
public:
+ QGeoBoundingArea();
+ QGeoBoundingArea(const QGeoBoundingArea &other);
+ ~QGeoBoundingArea();
+
enum AreaType {
+ UnknownType,
BoxType,
CircleType
};
- virtual ~QGeoBoundingArea();
+ AreaType type() const;
+
+ bool isValid() const;
+ bool isEmpty() const;
+ bool contains(const QGeoCoordinate &coordinate) const;
- virtual AreaType type() const = 0;
+ bool operator==(const QGeoBoundingArea &other) const;
+ bool operator!=(const QGeoBoundingArea &other) const;
- virtual bool isValid() const = 0;
- virtual bool isEmpty() const = 0;
- virtual bool contains(const QGeoCoordinate &coordinate) const = 0;
- virtual QGeoBoundingArea *clone() const = 0;
- virtual bool operator == (const QGeoBoundingArea &other) const = 0;
- virtual bool operator != (const QGeoBoundingArea &other) const = 0;
+ QGeoBoundingArea &operator=(const QGeoBoundingArea &other);
+
+protected:
+ QGeoBoundingArea(QGeoBoundingAreaPrivate *d);
+
+ QSharedDataPointer<QGeoBoundingAreaPrivate> d_ptr;
+
+private:
+ inline QGeoBoundingAreaPrivate *d_func();
+ inline const QGeoBoundingAreaPrivate *d_func() const;
};
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QGeoBoundingArea)
+
QT_END_HEADER
#endif // QGEOBOUNDINGAREA_H
diff --git a/src/location/qgeoboundingarea_p.h b/src/location/qgeoboundingarea_p.h
new file mode 100644
index 00000000..ce0ba069
--- /dev/null
+++ b/src/location/qgeoboundingarea_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOBOUNDINGAREA_P_H
+#define QGEOBOUNDINGAREA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QSharedData>
+
+#include "qgeoboundingarea.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGeoBoundingAreaPrivate : public QSharedData
+{
+public:
+ QGeoBoundingAreaPrivate(QGeoBoundingArea::AreaType type);
+ virtual ~QGeoBoundingAreaPrivate();
+
+ virtual bool isValid() const = 0;
+ virtual bool isEmpty() const = 0;
+ virtual bool contains(const QGeoCoordinate &coordinate) const = 0;
+
+ virtual QGeoBoundingAreaPrivate *clone() const = 0;
+
+ virtual bool operator==(const QGeoBoundingAreaPrivate &other) const;
+
+ QGeoBoundingArea::AreaType type;
+};
+
+// don't use the copy constructor when detaching from a QSharedDataPointer, use virtual clone()
+// call instead.
+template <>
+Q_INLINE_TEMPLATE QGeoBoundingAreaPrivate *QSharedDataPointer<QGeoBoundingAreaPrivate>::clone()
+{
+ return d->clone();
+}
+
+QT_END_NAMESPACE
+
+#endif // QGEOBOUNDINGAREA_P_H
diff --git a/src/location/qgeoboundingbox.cpp b/src/location/qgeoboundingbox.cpp
index d5a1ffae..b394aea9 100644
--- a/src/location/qgeoboundingbox.cpp
+++ b/src/location/qgeoboundingbox.cpp
@@ -75,11 +75,23 @@ QT_BEGIN_NAMESPACE
in the center of the bounding box.
*/
+inline QGeoBoundingBoxPrivate *QGeoBoundingBox::d_func()
+{
+ return static_cast<QGeoBoundingBoxPrivate *>(d_ptr.data());
+}
+
+inline const QGeoBoundingBoxPrivate *QGeoBoundingBox::d_func() const
+{
+ return static_cast<const QGeoBoundingBoxPrivate *>(d_ptr.constData());
+}
+
/*!
Constructs a new, invalid bounding box.
*/
QGeoBoundingBox::QGeoBoundingBox()
- : d_ptr(new QGeoBoundingBoxPrivate()) {}
+: QGeoBoundingArea(new QGeoBoundingBoxPrivate)
+{
+}
/*!
Constructs a new bounding box centered at \a center with a
@@ -92,10 +104,10 @@ QGeoBoundingBox::QGeoBoundingBox()
the center of the truncated bounding box.
*/
QGeoBoundingBox::QGeoBoundingBox(const QGeoCoordinate &center, double degreesWidth, double degreesHeight)
- : d_ptr(new QGeoBoundingBoxPrivate(center, center))
{
- setWidth(degreesWidth);
- setHeight(degreesHeight);
+ d_ptr = new QGeoBoundingBoxPrivate(center, center);
+ setWidth(degreesWidth);
+ setHeight(degreesHeight);
}
/*!
@@ -103,14 +115,27 @@ QGeoBoundingBox::QGeoBoundingBox(const QGeoCoordinate &center, double degreesWid
topLeft and a bottom right coordinate \a bottomRight.
*/
QGeoBoundingBox::QGeoBoundingBox(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight)
- : d_ptr(new QGeoBoundingBoxPrivate(topLeft, bottomRight)) {}
+{
+ d_ptr = new QGeoBoundingBoxPrivate(topLeft, bottomRight);
+}
/*!
Constructs a bounding box from the contents of \a other.
*/
QGeoBoundingBox::QGeoBoundingBox(const QGeoBoundingBox &other)
- : QGeoBoundingArea(other),
- d_ptr(other.d_ptr) {}
+: QGeoBoundingArea(other)
+{
+}
+
+/*!
+ Constructs a bounding box from the contents of \a other.
+*/
+QGeoBoundingBox::QGeoBoundingBox(const QGeoBoundingArea &other)
+: QGeoBoundingArea(other)
+{
+ if (type() != QGeoBoundingArea::BoxType)
+ d_ptr = new QGeoBoundingBoxPrivate;
+}
/*!
Destroys this bounding box.
@@ -129,31 +154,13 @@ QGeoBoundingBox& QGeoBoundingBox::operator = (const QGeoBoundingBox & other)
}
/*!
- Returns whether this bounding box is equal to the \a other area.
-*/
-bool QGeoBoundingBox::operator == (const QGeoBoundingArea &other) const
-{
- if (other.type() == QGeoBoundingArea::BoxType) {
- const QGeoBoundingBox *otherPointer = static_cast<const QGeoBoundingBox*>(&other);
- return ((*(d_ptr.constData()) == *(otherPointer->d_ptr.constData())));
- } else {
- return false;
- }
-}
-
-/*!
Returns whether this bounding box is equal to \a other.
*/
bool QGeoBoundingBox::operator == (const QGeoBoundingBox &other) const
{
- return ((*(d_ptr.constData()) == *(other.d_ptr.constData())));
-}
+ Q_D(const QGeoBoundingBox);
-/*!
- Returns whether this bounding box is not equal to \a other.
-*/
-bool QGeoBoundingBox::operator != (const QGeoBoundingArea &other) const {
- return !(*this == other);
+ return *d == *other.d_func();
}
/*!
@@ -161,45 +168,24 @@ bool QGeoBoundingBox::operator != (const QGeoBoundingArea &other) const {
*/
bool QGeoBoundingBox::operator != (const QGeoBoundingBox &other) const
{
- return !(this->operator==(other));
-}
+ Q_D(const QGeoBoundingBox);
-/*!
- Returns QGeoBoundingArea::BoxType to identify this as
- a QGeoBoundingBox instance.
-
- This function is provided to help find the specific type of
- aQGeoBoundingArea instance.
-*/
-QGeoBoundingArea::AreaType QGeoBoundingBox::type() const
-{
- return QGeoBoundingArea::BoxType;
+ return !(*d == *other.d_func());
}
-/*!
- Returns whether this bounding box is valid.
-
- A valid bounding box has valid top left and bottom right coordinates and
- has a top left coordinate with latitude greater than or equal to the
- latitude of the bottom right coordinate.
-*/
-bool QGeoBoundingBox::isValid() const
+bool QGeoBoundingBoxPrivate::isValid() const
{
- return (d_ptr->topLeft.isValid()
- && d_ptr->bottomRight.isValid()
- && d_ptr->topLeft.latitude() >= d_ptr->bottomRight.latitude());
+ return topLeft.isValid() && bottomRight.isValid() &&
+ topLeft.latitude() >= bottomRight.latitude();
}
-/*!
- Returns whether this bounding box has a geometrical area of 0.
-
- Returns true if this bounding box is invalid.
-*/
-bool QGeoBoundingBox::isEmpty() const
+bool QGeoBoundingBoxPrivate::isEmpty() const
{
- return (!isValid()
- || (d_ptr->topLeft.latitude() == d_ptr->bottomRight.latitude())
- || (d_ptr->topLeft.longitude() == d_ptr->bottomRight.longitude()));
+ if (!isValid())
+ return true;
+
+ return topLeft.latitude() == bottomRight.latitude() ||
+ topLeft.longitude() == bottomRight.longitude();
}
/*!
@@ -207,7 +193,9 @@ bool QGeoBoundingBox::isEmpty() const
*/
void QGeoBoundingBox::setTopLeft(const QGeoCoordinate &topLeft)
{
- d_ptr->topLeft = topLeft;
+ Q_D(QGeoBoundingBox);
+
+ d->topLeft = topLeft;
}
/*!
@@ -215,7 +203,9 @@ void QGeoBoundingBox::setTopLeft(const QGeoCoordinate &topLeft)
*/
QGeoCoordinate QGeoBoundingBox::topLeft() const
{
- return d_ptr->topLeft;
+ Q_D(const QGeoBoundingBox);
+
+ return d->topLeft;
}
/*!
@@ -223,8 +213,10 @@ QGeoCoordinate QGeoBoundingBox::topLeft() const
*/
void QGeoBoundingBox::setTopRight(const QGeoCoordinate &topRight)
{
- d_ptr->topLeft.setLatitude(topRight.latitude());
- d_ptr->bottomRight.setLongitude(topRight.longitude());
+ Q_D(QGeoBoundingBox);
+
+ d->topLeft.setLatitude(topRight.latitude());
+ d->bottomRight.setLongitude(topRight.longitude());
}
/*!
@@ -236,7 +228,9 @@ QGeoCoordinate QGeoBoundingBox::topRight() const
if (!isValid())
return QGeoCoordinate();
- return QGeoCoordinate(d_ptr->topLeft.latitude(), d_ptr->bottomRight.longitude());
+ Q_D(const QGeoBoundingBox);
+
+ return QGeoCoordinate(d->topLeft.latitude(), d->bottomRight.longitude());
}
/*!
@@ -244,8 +238,10 @@ QGeoCoordinate QGeoBoundingBox::topRight() const
*/
void QGeoBoundingBox::setBottomLeft(const QGeoCoordinate &bottomLeft)
{
- d_ptr->bottomRight.setLatitude(bottomLeft.latitude());
- d_ptr->topLeft.setLongitude(bottomLeft.longitude());
+ Q_D(QGeoBoundingBox);
+
+ d->bottomRight.setLatitude(bottomLeft.latitude());
+ d->topLeft.setLongitude(bottomLeft.longitude());
}
/*!
@@ -257,7 +253,9 @@ QGeoCoordinate QGeoBoundingBox::bottomLeft() const
if (!isValid())
return QGeoCoordinate();
- return QGeoCoordinate(d_ptr->bottomRight.latitude(), d_ptr->topLeft.longitude());
+ Q_D(const QGeoBoundingBox);
+
+ return QGeoCoordinate(d->bottomRight.latitude(), d->topLeft.longitude());
}
/*!
@@ -265,7 +263,9 @@ QGeoCoordinate QGeoBoundingBox::bottomLeft() const
*/
void QGeoBoundingBox::setBottomRight(const QGeoCoordinate &bottomRight)
{
- d_ptr->bottomRight = bottomRight;
+ Q_D(QGeoBoundingBox);
+
+ d->bottomRight = bottomRight;
}
/*!
@@ -273,7 +273,9 @@ void QGeoBoundingBox::setBottomRight(const QGeoCoordinate &bottomRight)
*/
QGeoCoordinate QGeoBoundingBox::bottomRight() const
{
- return d_ptr->bottomRight;
+ Q_D(const QGeoBoundingBox);
+
+ return d->bottomRight;
}
/*!
@@ -288,9 +290,11 @@ QGeoCoordinate QGeoBoundingBox::bottomRight() const
*/
void QGeoBoundingBox::setCenter(const QGeoCoordinate &center)
{
+ Q_D(QGeoBoundingBox);
+
if (!isValid()) {
- d_ptr->topLeft = center;
- d_ptr->bottomRight = center;
+ d->topLeft = center;
+ d->bottomRight = center;
return;
}
double width = this->width();
@@ -336,8 +340,8 @@ void QGeoBoundingBox::setCenter(const QGeoCoordinate &center)
brLon = 180.0;
}
- d_ptr->topLeft = QGeoCoordinate(tlLat, tlLon);
- d_ptr->bottomRight = QGeoCoordinate(brLat, brLon);
+ d->topLeft = QGeoCoordinate(tlLat, tlLon);
+ d->bottomRight = QGeoCoordinate(brLat, brLon);
}
/*!
@@ -348,10 +352,12 @@ QGeoCoordinate QGeoBoundingBox::center() const
if (!isValid())
return QGeoCoordinate();
- double cLat = (d_ptr->topLeft.latitude() + d_ptr->bottomRight.latitude()) / 2.0;
+ Q_D(const QGeoBoundingBox);
+
+ double cLat = (d->topLeft.latitude() + d->bottomRight.latitude()) / 2.0;
- double cLon = (d_ptr->bottomRight.longitude() + d_ptr->topLeft.longitude()) / 2.0;
- if (d_ptr->topLeft.longitude() > d_ptr->bottomRight.longitude()) {
+ double cLon = (d->bottomRight.longitude() + d->topLeft.longitude()) / 2.0;
+ if (d->topLeft.longitude() > d->bottomRight.longitude()) {
cLon = cLon - 180.0;
}
@@ -383,14 +389,16 @@ void QGeoBoundingBox::setWidth(double degreesWidth)
if (degreesWidth < 0.0)
return;
+ Q_D(QGeoBoundingBox);
+
if (degreesWidth >= 360.0) {
- d_ptr->topLeft.setLongitude(-180.0);
- d_ptr->bottomRight.setLongitude(180.0);
+ d->topLeft.setLongitude(-180.0);
+ d->bottomRight.setLongitude(180.0);
return;
}
- double tlLat = d_ptr->topLeft.latitude();
- double brLat = d_ptr->bottomRight.latitude();
+ double tlLat = d->topLeft.latitude();
+ double brLat = d->bottomRight.latitude();
QGeoCoordinate c = center();
@@ -408,8 +416,8 @@ void QGeoBoundingBox::setWidth(double degreesWidth)
if (brLon > 180.0)
brLon -= 360.0;
- d_ptr->topLeft = QGeoCoordinate(tlLat, tlLon);
- d_ptr->bottomRight = QGeoCoordinate(brLat, brLon);
+ d->topLeft = QGeoCoordinate(tlLat, tlLon);
+ d->bottomRight = QGeoCoordinate(brLat, brLon);
}
/*!
@@ -422,7 +430,9 @@ double QGeoBoundingBox::width() const
if (!isValid())
return qQNaN();
- double result = d_ptr->bottomRight.longitude() - d_ptr->topLeft.longitude();
+ Q_D(const QGeoBoundingBox);
+
+ double result = d->bottomRight.longitude() - d->topLeft.longitude();
if (result < 0.0)
result += 360.0;
if (result > 360.0)
@@ -460,8 +470,10 @@ void QGeoBoundingBox::setHeight(double degreesHeight)
degreesHeight = 180.0;
}
- double tlLon = d_ptr->topLeft.longitude();
- double brLon = d_ptr->bottomRight.longitude();
+ Q_D(QGeoBoundingBox);
+
+ double tlLon = d->topLeft.longitude();
+ double brLon = d->bottomRight.longitude();
QGeoCoordinate c = center();
@@ -488,8 +500,8 @@ void QGeoBoundingBox::setHeight(double degreesHeight)
brLat = -90.0;
}
- d_ptr->topLeft = QGeoCoordinate(tlLat, tlLon);
- d_ptr->bottomRight = QGeoCoordinate(brLat, brLon);
+ d->topLeft = QGeoCoordinate(tlLat, tlLon);
+ d->bottomRight = QGeoCoordinate(brLat, brLon);
}
/*!
@@ -502,26 +514,23 @@ double QGeoBoundingBox::height() const
if (!isValid())
return qQNaN();
- double result = d_ptr->topLeft.latitude() - d_ptr->bottomRight.latitude();
+ Q_D(const QGeoBoundingBox);
+
+ double result = d->topLeft.latitude() - d->bottomRight.latitude();
if (result < 0.0)
result = qQNaN();
return result;
}
-/*!
- Returns whether the coordinate \a coordinate is contained within this
- bounding box.
-*/
-bool QGeoBoundingBox::contains(const QGeoCoordinate &coordinate) const
+bool QGeoBoundingBoxPrivate::contains(const QGeoCoordinate &coordinate) const
{
-
if (!isValid() || !coordinate.isValid())
return false;
- double left = d_ptr->topLeft.longitude();
- double right = d_ptr->bottomRight.longitude();
- double top = d_ptr->topLeft.latitude();
- double bottom = d_ptr->bottomRight.latitude();
+ double left = topLeft.longitude();
+ double right = bottomRight.longitude();
+ double top = topLeft.latitude();
+ double bottom = bottomRight.latitude();
double lon = coordinate.longitude();
double lat = coordinate.latitude();
@@ -554,10 +563,12 @@ bool QGeoBoundingBox::contains(const QGeoCoordinate &coordinate) const
*/
bool QGeoBoundingBox::contains(const QGeoBoundingBox &boundingBox) const
{
- return (contains(boundingBox.topLeft())
- && contains(boundingBox.topRight())
- && contains(boundingBox.bottomLeft())
- && contains(boundingBox.bottomRight()));
+ Q_D(const QGeoBoundingBox);
+
+ return (d->contains(boundingBox.topLeft())
+ && d->contains(boundingBox.topRight())
+ && d->contains(boundingBox.bottomLeft())
+ && d->contains(boundingBox.bottomRight()));
}
/*!
@@ -570,15 +581,17 @@ bool QGeoBoundingBox::contains(const QGeoBoundingBox &boundingBox) const
*/
bool QGeoBoundingBox::intersects(const QGeoBoundingBox &boundingBox) const
{
- double left1 = d_ptr->topLeft.longitude();
- double right1 = d_ptr->bottomRight.longitude();
- double top1 = d_ptr->topLeft.latitude();
- double bottom1 = d_ptr->bottomRight.latitude();
+ Q_D(const QGeoBoundingBox);
+
+ double left1 = d->topLeft.longitude();
+ double right1 = d->bottomRight.longitude();
+ double top1 = d->topLeft.latitude();
+ double bottom1 = d->bottomRight.latitude();
- double left2 = boundingBox.d_ptr->topLeft.longitude();
- double right2 = boundingBox.d_ptr->bottomRight.longitude();
- double top2 = boundingBox.d_ptr->topLeft.latitude();
- double bottom2 = boundingBox.d_ptr->bottomRight.latitude();
+ double left2 = boundingBox.d_func()->topLeft.longitude();
+ double right2 = boundingBox.d_func()->bottomRight.longitude();
+ double top2 = boundingBox.d_func()->topLeft.latitude();
+ double bottom2 = boundingBox.d_func()->bottomRight.latitude();
if (top1 < bottom2)
return false;
@@ -627,10 +640,12 @@ void QGeoBoundingBox::translate(double degreesLatitude, double degreesLongitude)
{
// TODO handle dlat, dlon larger than 360 degrees
- double tlLat = d_ptr->topLeft.latitude();
- double tlLon = d_ptr->topLeft.longitude();
- double brLat = d_ptr->bottomRight.latitude();
- double brLon = d_ptr->bottomRight.longitude();
+ Q_D(QGeoBoundingBox);
+
+ double tlLat = d->topLeft.latitude();
+ double tlLon = d->topLeft.longitude();
+ double brLat = d->bottomRight.latitude();
+ double brLon = d->bottomRight.longitude();
if ((tlLat != 90.0) || (brLat != -90.0)) {
tlLat += degreesLatitude;
@@ -664,8 +679,8 @@ void QGeoBoundingBox::translate(double degreesLatitude, double degreesLongitude)
if (brLat < -90.0)
brLat = -90.0;
- d_ptr->topLeft = QGeoCoordinate(tlLat, tlLon);
- d_ptr->bottomRight = QGeoCoordinate(brLat, brLon);
+ d->topLeft = QGeoCoordinate(tlLat, tlLon);
+ d->bottomRight = QGeoCoordinate(brLat, brLon);
}
/*!
@@ -725,15 +740,17 @@ QGeoBoundingBox& QGeoBoundingBox::operator |= (const QGeoBoundingBox & boundingB
{
// If non-intersecting goes for most narrow box
- double left1 = d_ptr->topLeft.longitude();
- double right1 = d_ptr->bottomRight.longitude();
- double top1 = d_ptr->topLeft.latitude();
- double bottom1 = d_ptr->bottomRight.latitude();
+ Q_D(QGeoBoundingBox);
- double left2 = boundingBox.d_ptr->topLeft.longitude();
- double right2 = boundingBox.d_ptr->bottomRight.longitude();
- double top2 = boundingBox.d_ptr->topLeft.latitude();
- double bottom2 = boundingBox.d_ptr->bottomRight.latitude();
+ double left1 = d->topLeft.longitude();
+ double right1 = d->bottomRight.longitude();
+ double top1 = d->topLeft.latitude();
+ double bottom1 = d->bottomRight.latitude();
+
+ double left2 = boundingBox.d_func()->topLeft.longitude();
+ double right2 = boundingBox.d_func()->bottomRight.longitude();
+ double top2 = boundingBox.d_func()->topLeft.latitude();
+ double bottom2 = boundingBox.d_func()->bottomRight.latitude();
double top = qMax(top1, top2);
double bottom = qMin(bottom1, bottom2);
@@ -816,49 +833,47 @@ QGeoBoundingBox& QGeoBoundingBox::operator |= (const QGeoBoundingBox & boundingB
right = 180;
}
- d_ptr->topLeft = QGeoCoordinate(top, left);
- d_ptr->bottomRight = QGeoCoordinate(bottom, right);
+ d->topLeft = QGeoCoordinate(top, left);
+ d->bottomRight = QGeoCoordinate(bottom, right);
return *this;
}
-/*!
- Returns a pointer to a deep copy of this bounding box.
-*/
-QGeoBoundingArea *QGeoBoundingBox::clone() const
-{
- return new QGeoBoundingBox(*this);
-}
-
/*******************************************************************************
*******************************************************************************/
QGeoBoundingBoxPrivate::QGeoBoundingBoxPrivate()
- : QSharedData() {}
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::BoxType)
+{
+}
-QGeoBoundingBoxPrivate::QGeoBoundingBoxPrivate(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight)
- : QSharedData(),
- topLeft(topLeft),
- bottomRight(bottomRight) {}
+QGeoBoundingBoxPrivate::QGeoBoundingBoxPrivate(const QGeoCoordinate &topLeft,
+ const QGeoCoordinate &bottomRight)
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::BoxType), topLeft(topLeft), bottomRight(bottomRight)
+{
+}
QGeoBoundingBoxPrivate::QGeoBoundingBoxPrivate(const QGeoBoundingBoxPrivate &other)
- : QSharedData(),
- topLeft(other.topLeft),
- bottomRight(other.bottomRight) {}
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::BoxType), topLeft(other.topLeft),
+ bottomRight(other.bottomRight)
+{
+}
QGeoBoundingBoxPrivate::~QGeoBoundingBoxPrivate() {}
-QGeoBoundingBoxPrivate& QGeoBoundingBoxPrivate::operator= (const QGeoBoundingBoxPrivate & other)
+QGeoBoundingAreaPrivate *QGeoBoundingBoxPrivate::clone() const
{
- topLeft = other.topLeft;
- bottomRight = other.bottomRight;
-
- return *this;
+ return new QGeoBoundingBoxPrivate(*this);
}
-bool QGeoBoundingBoxPrivate::operator== (const QGeoBoundingBoxPrivate &other) const
+bool QGeoBoundingBoxPrivate::operator==(const QGeoBoundingAreaPrivate &other) const
{
- return ((topLeft == other.topLeft) && (bottomRight == other.bottomRight));
+ if (!QGeoBoundingAreaPrivate::operator==(other))
+ return false;
+
+ const QGeoBoundingBoxPrivate &otherBox = static_cast<const QGeoBoundingBoxPrivate &>(other);
+
+ return topLeft == otherBox.topLeft && bottomRight == otherBox.bottomRight;
}
QT_END_NAMESPACE
diff --git a/src/location/qgeoboundingbox.h b/src/location/qgeoboundingbox.h
index 8f72a1d1..106d1b37 100644
--- a/src/location/qgeoboundingbox.h
+++ b/src/location/qgeoboundingbox.h
@@ -42,16 +42,12 @@
#ifndef QGEOBOUNDINGBOX_H
#define QGEOBOUNDINGBOX_H
-#include "qgeoboundingarea.h"
-
-#include <QSharedDataPointer>
+#include <QtLocation/QGeoBoundingArea>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
-
class QGeoCoordinate;
class QGeoBoundingBoxPrivate;
@@ -61,22 +57,18 @@ public:
QGeoBoundingBox();
QGeoBoundingBox(const QGeoCoordinate &center, double degreesWidth, double degreesHeight);
QGeoBoundingBox(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight);
-
QGeoBoundingBox(const QGeoBoundingBox &other);
+ QGeoBoundingBox(const QGeoBoundingArea &other);
+
~QGeoBoundingBox();
QGeoBoundingBox& operator = (const QGeoBoundingBox &other);
- bool operator == (const QGeoBoundingArea &other) const;
- bool operator == (const QGeoBoundingBox &other) const;
-
- bool operator != (const QGeoBoundingArea &other) const;
- bool operator != (const QGeoBoundingBox &other) const;
+ using QGeoBoundingArea::operator==;
+ bool operator==(const QGeoBoundingBox &other) const;
- QGeoBoundingArea::AreaType type() const;
-
- bool isValid() const;
- bool isEmpty() const;
+ using QGeoBoundingArea::operator!=;
+ bool operator!=(const QGeoBoundingBox &other) const;
void setTopLeft(const QGeoCoordinate &topLeft);
QGeoCoordinate topLeft() const;
@@ -99,7 +91,7 @@ public:
void setHeight(double degreesHeight);
double height() const;
- bool contains(const QGeoCoordinate &coordinate) const;
+ using QGeoBoundingArea::contains;
bool contains(const QGeoBoundingBox &boundingBox) const;
bool intersects(const QGeoBoundingBox &boundingBox) const;
@@ -110,10 +102,9 @@ public:
QGeoBoundingBox operator | (const QGeoBoundingBox &boundingBox) const;
QGeoBoundingBox& operator |= (const QGeoBoundingBox &boundingBox);
- QGeoBoundingArea *clone() const;
-
private:
- QSharedDataPointer<QGeoBoundingBoxPrivate> d_ptr;
+ inline QGeoBoundingBoxPrivate *d_func();
+ inline const QGeoBoundingBoxPrivate *d_func() const;
};
inline QGeoBoundingBox QGeoBoundingBox::operator | (const QGeoBoundingBox &boundingBox) const
diff --git a/src/location/qgeoboundingbox_p.h b/src/location/qgeoboundingbox_p.h
index b7fa5485..2c956ba1 100644
--- a/src/location/qgeoboundingbox_p.h
+++ b/src/location/qgeoboundingbox_p.h
@@ -53,13 +53,12 @@
// We mean it.
//
+#include "qgeoboundingarea_p.h"
#include "qgeocoordinate.h"
-#include <QSharedData>
-
QT_BEGIN_NAMESPACE
-class QGeoBoundingBoxPrivate : public QSharedData
+class QGeoBoundingBoxPrivate : public QGeoBoundingAreaPrivate
{
public:
QGeoBoundingBoxPrivate();
@@ -67,9 +66,13 @@ public:
QGeoBoundingBoxPrivate(const QGeoBoundingBoxPrivate &other);
~QGeoBoundingBoxPrivate();
- QGeoBoundingBoxPrivate& operator= (const QGeoBoundingBoxPrivate &other);
+ bool isValid() const;
+ bool isEmpty() const;
+ bool contains(const QGeoCoordinate &coordinate) const;
+
+ QGeoBoundingAreaPrivate *clone() const;
- bool operator== (const QGeoBoundingBoxPrivate &other) const;
+ bool operator==(const QGeoBoundingAreaPrivate &other) const;
QGeoCoordinate topLeft;
QGeoCoordinate bottomRight;
diff --git a/src/location/qgeoboundingcircle.cpp b/src/location/qgeoboundingcircle.cpp
index d6614d9e..f37ce64d 100644
--- a/src/location/qgeoboundingcircle.cpp
+++ b/src/location/qgeoboundingcircle.cpp
@@ -65,25 +65,50 @@ QT_BEGIN_NAMESPACE
or if the radius is less than zero.
*/
+inline QGeoBoundingCirclePrivate *QGeoBoundingCircle::d_func()
+{
+ return static_cast<QGeoBoundingCirclePrivate *>(d_ptr.data());
+}
+
+inline const QGeoBoundingCirclePrivate *QGeoBoundingCircle::d_func() const
+{
+ return static_cast<const QGeoBoundingCirclePrivate *>(d_ptr.constData());
+}
+
/*!
Constructs a new, invalid bounding circle.
*/
QGeoBoundingCircle::QGeoBoundingCircle()
- : d_ptr(new QGeoBoundingCirclePrivate()) {}
+: QGeoBoundingArea(new QGeoBoundingCirclePrivate)
+{
+}
/*!
Constructs a new bounding circle centered at \a center and with a radius of \a
radius meters.
*/
QGeoBoundingCircle::QGeoBoundingCircle(const QGeoCoordinate &center, qreal radius)
- : d_ptr(new QGeoBoundingCirclePrivate(center, radius)) {}
+{
+ d_ptr = new QGeoBoundingCirclePrivate(center, radius);
+}
/*!
Constructs a new bounding circle from the contents of \a other.
*/
QGeoBoundingCircle::QGeoBoundingCircle(const QGeoBoundingCircle &other)
- : QGeoBoundingArea(other),
- d_ptr(other.d_ptr) {}
+: QGeoBoundingArea(other)
+{
+}
+
+/*!
+ Constructs a new bounding circle from the contents of \a other.
+*/
+QGeoBoundingCircle::QGeoBoundingCircle(const QGeoBoundingArea &other)
+: QGeoBoundingArea(other)
+{
+ if (type() != QGeoBoundingArea::CircleType)
+ d_ptr = new QGeoBoundingCirclePrivate;
+}
/*!
Destroys this bounding circle.
@@ -104,72 +129,31 @@ QGeoBoundingCircle& QGeoBoundingCircle::operator = (const QGeoBoundingCircle & o
/*!
Returns whether this bounding circle is equal to \a other.
*/
-bool QGeoBoundingCircle::operator == (const QGeoBoundingArea &other) const
+bool QGeoBoundingCircle::operator==(const QGeoBoundingCircle &other) const
{
- if (other.type() == QGeoBoundingArea::CircleType) {
- const QGeoBoundingCircle *otherPointer = static_cast<const QGeoBoundingCircle*>(&other);
- return ((*(d_ptr.constData()) == *(otherPointer->d_ptr.constData())));
- } else {
- return false;
- }
-}
+ Q_D(const QGeoBoundingCircle);
-/*!
- Returns whether this bounding circle is equal to \a other.
-*/
-bool QGeoBoundingCircle::operator == (const QGeoBoundingCircle &other) const
-{
- return ((*(d_ptr.constData()) == *(other.d_ptr.constData())));
+ return *d == *other.d_func();
}
/*!
Returns whether this bounding circle is not equal to \a other.
*/
-bool QGeoBoundingCircle::operator != (const QGeoBoundingArea &other) const {
- return !(*this == other);
-}
-
-/*!
- Returns whether this bounding circle is not equal to \a other.
-*/
-bool QGeoBoundingCircle::operator != (const QGeoBoundingCircle &other) const
+bool QGeoBoundingCircle::operator!=(const QGeoBoundingCircle &other) const
{
- return !(this->operator==(other));
-}
-
-/*!
- Returns QGeoBoundingArea::CircleType to identify this as a
- QGeoBoundingCircle instance.
+ Q_D(const QGeoBoundingCircle);
- This function is provided to help find the specific type of
- aQGeoBoundingArea instance.
-*/
-QGeoBoundingArea::AreaType QGeoBoundingCircle::type() const
-{
- return QGeoBoundingArea::CircleType;
+ return !(*d == *other.d_func());
}
-/*!
- Returns whether this bounding circle is valid.
-
- A valid bounding circle has a valid center coordinate and a radius
- greater than or equal to zero.
-*/
-bool QGeoBoundingCircle::isValid() const
+bool QGeoBoundingCirclePrivate::isValid() const
{
- return (d_ptr->center.isValid()
- && !qIsNaN(d_ptr->radius)
- && d_ptr->radius >= -1e-7);
+ return center.isValid() && !qIsNaN(radius) && radius >= -1e-7;
}
-/*!
- Returns whether this bounding circle has a geometrical area of zero.
-
- Returns true if this bounding circle is invalid.
-*/
-bool QGeoBoundingCircle::isEmpty() const
+bool QGeoBoundingCirclePrivate::isEmpty() const
{
- return (!isValid() || (d_ptr->radius <= 1e-7));
+ return !isValid() || radius <= 1e-7;
}
/*!
@@ -177,7 +161,9 @@ bool QGeoBoundingCircle::isEmpty() const
*/
void QGeoBoundingCircle::setCenter(const QGeoCoordinate &center)
{
- d_ptr->center = center;
+ Q_D(QGeoBoundingCircle);
+
+ d->center = center;
}
/*!
@@ -185,7 +171,9 @@ void QGeoBoundingCircle::setCenter(const QGeoCoordinate &center)
*/
QGeoCoordinate QGeoBoundingCircle::center() const
{
- return d_ptr->center;
+ Q_D(const QGeoBoundingCircle);
+
+ return d->center;
}
/*!
@@ -193,7 +181,9 @@ QGeoCoordinate QGeoBoundingCircle::center() const
*/
void QGeoBoundingCircle::setRadius(qreal radius)
{
- d_ptr->radius = radius;
+ Q_D(QGeoBoundingCircle);
+
+ d->radius = radius;
}
/*!
@@ -201,23 +191,17 @@ void QGeoBoundingCircle::setRadius(qreal radius)
*/
qreal QGeoBoundingCircle::radius() const
{
- return d_ptr->radius;
+ Q_D(const QGeoBoundingCircle);
+
+ return d->radius;
}
-/*!
- Returns whether the coordinate \a coordinate is contained within this
- bounding circle.
-*/
-bool QGeoBoundingCircle::contains(const QGeoCoordinate &coordinate) const
+bool QGeoBoundingCirclePrivate::contains(const QGeoCoordinate &coordinate) const
{
-
if (!isValid() || !coordinate.isValid())
return false;
- if (d_ptr->center.distanceTo(coordinate) <= d_ptr->radius)
- return true;
-
- return false;
+ return center.distanceTo(coordinate) <= radius;
}
/*!
@@ -231,8 +215,10 @@ void QGeoBoundingCircle::translate(double degreesLatitude, double degreesLongitu
{
// TODO handle dlat, dlon larger than 360 degrees
- double lat = d_ptr->center.latitude();
- double lon = d_ptr->center.longitude();
+ Q_D(QGeoBoundingCircle);
+
+ double lat = d->center.latitude();
+ double lon = d->center.longitude();
lat += degreesLatitude;
lon += degreesLongitude;
@@ -258,7 +244,7 @@ void QGeoBoundingCircle::translate(double degreesLatitude, double degreesLongitu
lon -= 180;
}
- d_ptr->center = QGeoCoordinate(lat, lon);
+ d->center = QGeoCoordinate(lat, lon);
}
/*!
@@ -277,44 +263,40 @@ QGeoBoundingCircle QGeoBoundingCircle::translated(double degreesLatitude, double
return result;
}
-/*!
- Returns a pointer to a deep copy of this bounding circle.
-*/
-QGeoBoundingArea *QGeoBoundingCircle::clone() const
-{
- return new QGeoBoundingCircle(*this);
-}
-
/*******************************************************************************
*******************************************************************************/
QGeoBoundingCirclePrivate::QGeoBoundingCirclePrivate()
- : QSharedData(),
- radius(-1.0) {}
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::CircleType), radius(-1.0)
+{
+}
QGeoBoundingCirclePrivate::QGeoBoundingCirclePrivate(const QGeoCoordinate &center, qreal radius)
- : QSharedData(),
- center(center),
- radius(radius) {}
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::CircleType), center(center), radius(radius)
+{
+}
QGeoBoundingCirclePrivate::QGeoBoundingCirclePrivate(const QGeoBoundingCirclePrivate &other)
- : QSharedData(),
- center(other.center),
- radius(other.radius) {}
+: QGeoBoundingAreaPrivate(QGeoBoundingArea::CircleType), center(other.center),
+ radius(other.radius)
+{
+}
QGeoBoundingCirclePrivate::~QGeoBoundingCirclePrivate() {}
-QGeoBoundingCirclePrivate& QGeoBoundingCirclePrivate::operator= (const QGeoBoundingCirclePrivate & other)
+QGeoBoundingAreaPrivate *QGeoBoundingCirclePrivate::clone() const
{
- center = other.center;
- radius = other.radius;
-
- return *this;
+ return new QGeoBoundingCirclePrivate(*this);
}
-bool QGeoBoundingCirclePrivate::operator== (const QGeoBoundingCirclePrivate &other) const
+bool QGeoBoundingCirclePrivate::operator==(const QGeoBoundingAreaPrivate &other) const
{
- return ((center == other.center) && (radius == other.radius));
+ if (!QGeoBoundingAreaPrivate::operator==(other))
+ return false;
+
+ const QGeoBoundingCirclePrivate &otherCircle = static_cast<const QGeoBoundingCirclePrivate &>(other);
+
+ return radius == otherCircle.radius && center == otherCircle.center;
}
QT_END_NAMESPACE
diff --git a/src/location/qgeoboundingcircle.h b/src/location/qgeoboundingcircle.h
index 3c00e241..10b23e29 100644
--- a/src/location/qgeoboundingcircle.h
+++ b/src/location/qgeoboundingcircle.h
@@ -60,22 +60,18 @@ class Q_LOCATION_EXPORT QGeoBoundingCircle : public QGeoBoundingArea
public:
QGeoBoundingCircle();
QGeoBoundingCircle(const QGeoCoordinate &center, qreal radius = -1.0);
-
QGeoBoundingCircle(const QGeoBoundingCircle &other);
+ QGeoBoundingCircle(const QGeoBoundingArea &other);
+
~QGeoBoundingCircle();
QGeoBoundingCircle& operator = (const QGeoBoundingCircle &other);
- bool operator == (const QGeoBoundingArea &other) const;
- bool operator == (const QGeoBoundingCircle &other) const;
-
- bool operator != (const QGeoBoundingArea &other) const;
- bool operator != (const QGeoBoundingCircle &other) const;
+ using QGeoBoundingArea::operator==;
+ bool operator==(const QGeoBoundingCircle &other) const;
- QGeoBoundingArea::AreaType type() const;
-
- bool isValid() const;
- bool isEmpty() const;
+ using QGeoBoundingArea::operator!=;
+ bool operator!=(const QGeoBoundingCircle &other) const;
void setCenter(const QGeoCoordinate &center);
QGeoCoordinate center() const;
@@ -83,14 +79,12 @@ public:
void setRadius(qreal radius);
qreal radius() const;
- bool contains(const QGeoCoordinate &coordinate) const;
-
void translate(double degreesLatitude, double degreesLongitude);
QGeoBoundingCircle translated(double degreesLatitude, double degreesLongitude) const;
- QGeoBoundingArea *clone() const;
private:
- QSharedDataPointer<QGeoBoundingCirclePrivate> d_ptr;
+ inline QGeoBoundingCirclePrivate *d_func();
+ inline const QGeoBoundingCirclePrivate *d_func() const;
};
QT_END_NAMESPACE
diff --git a/src/location/qgeoboundingcircle_p.h b/src/location/qgeoboundingcircle_p.h
index f84203a7..3dcf2409 100644
--- a/src/location/qgeoboundingcircle_p.h
+++ b/src/location/qgeoboundingcircle_p.h
@@ -53,13 +53,12 @@
// We mean it.
//
+#include "qgeoboundingarea_p.h"
#include "qgeocoordinate.h"
-#include <QSharedData>
-
QT_BEGIN_NAMESPACE
-class QGeoBoundingCirclePrivate : public QSharedData
+class QGeoBoundingCirclePrivate : public QGeoBoundingAreaPrivate
{
public:
QGeoBoundingCirclePrivate();
@@ -67,9 +66,13 @@ public:
QGeoBoundingCirclePrivate(const QGeoBoundingCirclePrivate &other);
~QGeoBoundingCirclePrivate();
- QGeoBoundingCirclePrivate& operator= (const QGeoBoundingCirclePrivate &other);
+ bool isValid() const;
+ bool isEmpty() const;
+ bool contains(const QGeoCoordinate &coordinate) const;
+
+ QGeoBoundingAreaPrivate *clone() const;
- bool operator== (const QGeoBoundingCirclePrivate &other) const;
+ bool operator==(const QGeoBoundingAreaPrivate &other) const;
QGeoCoordinate center;
qreal radius;
diff --git a/src/plugins/geoservices/nokia/placesv1/qplacerestmanager.cpp b/src/plugins/geoservices/nokia/placesv1/qplacerestmanager.cpp
index 973a4738..12185bff 100644
--- a/src/plugins/geoservices/nokia/placesv1/qplacerestmanager.cpp
+++ b/src/plugins/geoservices/nokia/placesv1/qplacerestmanager.cpp
@@ -284,18 +284,23 @@ QString QPlaceRestManager::prepareSearchRequest(const QPlaceSearchRequest &query
searchString += const_deviceproductid;
// process search center
- if (query.searchArea() != NULL) {
- if (query.searchArea()->type() == QGeoBoundingArea::CircleType) {
- QGeoBoundingCircle * circle = static_cast<QGeoBoundingCircle *>(query.searchArea());
- searchString += const_lat + QString::number(circle->center().latitude());
- searchString += const_lon + QString::number(circle->center().longitude());
- } else if (query.searchArea()->type() == QGeoBoundingArea::BoxType) {
- QGeoBoundingBox *box = static_cast<QGeoBoundingBox *> (query.searchArea());
- searchString += const_top + QString::number(box->topLeft().latitude());
- searchString += const_left + QString::number(box->topLeft().longitude());
- searchString += const_bottom + QString::number(box->bottomRight().latitude());
- searchString += const_right + QString::number(box->bottomRight().longitude());
- }
+ switch (query.searchArea().type()) {
+ case QGeoBoundingArea::CircleType: {
+ QGeoBoundingCircle circle = query.searchArea();
+ searchString += const_lat + QString::number(circle.center().latitude());
+ searchString += const_lon + QString::number(circle.center().longitude());
+ break;
+ }
+ case QGeoBoundingArea::BoxType: {
+ QGeoBoundingBox box = query.searchArea();
+ searchString += const_top + QString::number(box.topLeft().latitude());
+ searchString += const_left + QString::number(box.topLeft().longitude());
+ searchString += const_bottom + QString::number(box.bottomRight().latitude());
+ searchString += const_right + QString::number(box.bottomRight().longitude());
+ break;
+ }
+ default:
+ ;
}
if (!query.categories().isEmpty()) {
diff --git a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp
index 32ebc635..fd761f6a 100644
--- a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp
@@ -51,7 +51,8 @@
QT_BEGIN_NAMESPACE
-QGeocodeReplyNokia::QGeocodeReplyNokia(QNetworkReply *reply, int limit, int offset, QGeoBoundingArea *viewport, QObject *parent)
+QGeocodeReplyNokia::QGeocodeReplyNokia(QNetworkReply *reply, int limit, int offset,
+ const QGeoBoundingArea &viewport, QObject *parent)
: QGeocodeReply(parent),
m_reply(reply)
{
@@ -102,10 +103,10 @@ void QGeocodeReplyNokia::networkFinished()
QGeoCodeXmlParser parser;
if (parser.parse(m_reply)) {
QList<QGeoLocation> locations = parser.results();
- QGeoBoundingArea *bounds = viewport();
- if (bounds) {
+ QGeoBoundingArea bounds = viewport();
+ if (bounds.isValid()) {
for (int i = locations.size() - 1; i >= 0; --i) {
- if (!bounds->contains(locations[i].coordinate()))
+ if (!bounds.contains(locations[i].coordinate()))
locations.removeAt(i);
}
}
diff --git a/src/plugins/geoservices/nokia/qgeocodereply_nokia.h b/src/plugins/geoservices/nokia/qgeocodereply_nokia.h
index a789a26d..6f77a09c 100644
--- a/src/plugins/geoservices/nokia/qgeocodereply_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeocodereply_nokia.h
@@ -58,7 +58,7 @@ class QGeocodeReplyNokia : public QGeocodeReply
{
Q_OBJECT
public:
- QGeocodeReplyNokia(QNetworkReply *reply, int limit, int offset, QGeoBoundingArea *viewport, QObject *parent = 0);
+ QGeocodeReplyNokia(QNetworkReply *reply, int limit, int offset, const QGeoBoundingArea &viewport, QObject *parent = 0);
~QGeocodeReplyNokia();
void abort();
diff --git a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
index 5de863f9..dad8d507 100644
--- a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
@@ -112,7 +112,7 @@ QGeocodingManagerEngineNokia::QGeocodingManagerEngineNokia(const QMap<QString, Q
QGeocodingManagerEngineNokia::~QGeocodingManagerEngineNokia() {}
QGeocodeReply* QGeocodingManagerEngineNokia::geocode(const QGeoAddress &address,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
if (!supportsGeocoding()) {
QGeocodeReply *reply = new QGeocodeReply(QGeocodeReply::UnsupportedOptionError, "Geocoding is not supported by this service provider.", this);
@@ -168,7 +168,7 @@ QGeocodeReply* QGeocodingManagerEngineNokia::geocode(const QGeoAddress &address,
}
QGeocodeReply* QGeocodingManagerEngineNokia::reverseGeocode(const QGeoCoordinate &coordinate,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
if (!supportsReverseGeocoding()) {
QGeocodeReply *reply = new QGeocodeReply(QGeocodeReply::UnsupportedOptionError, "Reverse geocoding is not supported by this service provider.", this);
@@ -195,7 +195,7 @@ QGeocodeReply* QGeocodingManagerEngineNokia::reverseGeocode(const QGeoCoordinate
QGeocodeReply* QGeocodingManagerEngineNokia::geocode(const QString &address,
int limit,
int offset,
- QGeoBoundingArea *bounds)
+ const QGeoBoundingArea &bounds)
{
QString requestString = "http://";
requestString += m_host;
@@ -224,7 +224,7 @@ QGeocodeReply* QGeocodingManagerEngineNokia::geocode(const QString &address,
}
QGeocodeReply* QGeocodingManagerEngineNokia::geocode(QString requestString,
- QGeoBoundingArea *bounds,
+ const QGeoBoundingArea &bounds,
int limit,
int offset)
{
diff --git a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
index c8378db9..bd4d3a76 100644
--- a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
@@ -70,14 +70,14 @@ public:
~QGeocodingManagerEngineNokia();
QGeocodeReply* geocode(const QGeoAddress &address,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
QGeocodeReply* reverseGeocode(const QGeoCoordinate &coordinate,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
QGeocodeReply* geocode(const QString &searchString,
int limit,
int offset,
- QGeoBoundingArea *bounds);
+ const QGeoBoundingArea &bounds);
private slots:
void placesFinished();
@@ -85,7 +85,7 @@ private slots:
private:
static QString trimDouble(double degree, int decimalDigits = 10);
- QGeocodeReply* geocode(QString requestString, QGeoBoundingArea *bounds, int limit = -1, int offset = 0);
+ QGeocodeReply* geocode(QString requestString, const QGeoBoundingArea &bounds, int limit = -1, int offset = 0);
QString languageToMarc(QLocale::Language language);
QNetworkAccessManager *m_networkManager;
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
index 8bfaf51c..caaac67b 100644
--- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
+++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
@@ -237,16 +237,18 @@ QPlaceContentReply *QPlaceManagerEngineNokiaV2::getPlaceContent(const QString &p
return reply;
}
-static QString boundingAreaToLatLong(QGeoBoundingArea *area)
+static QString boundingAreaToLatLong(const QGeoBoundingArea &area)
{
QGeoCoordinate center;
- switch (area->type()) {
+ switch (area.type()) {
case QGeoBoundingArea::BoxType:
- center = static_cast<QGeoBoundingBox *>(area)->center();
+ center = QGeoBoundingBox(area).center();
break;
case QGeoBoundingArea::CircleType:
- center = static_cast<QGeoBoundingCircle *>(area)->center();
+ center = QGeoBoundingCircle(area).center();
break;
+ default:
+ return QString();
}
return QString::number(center.latitude()) + QLatin1Char(',') +
@@ -270,7 +272,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
queryItems.append(qMakePair<QString, QString>(QLatin1String("q"), query.searchTerm()));
- if (query.searchArea()) {
+ if (query.searchArea().isValid()) {
queryItems.append(qMakePair<QString, QString>(QLatin1String("at"),
boundingAreaToLatLong(query.searchArea())));
}
@@ -308,7 +310,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
queryItems.append(qMakePair<QString, QString>(QLatin1String("cat"),
ids.join(QLatin1String(","))));
- if (query.searchArea()) {
+ if (query.searchArea().isValid()) {
queryItems.append(qMakePair<QString, QString>(QLatin1String("at"),
boundingAreaToLatLong(query.searchArea())));
}
@@ -381,7 +383,7 @@ QPlaceSearchSuggestionReply *QPlaceManagerEngineNokiaV2::searchSuggestions(const
queryItems.append(qMakePair<QString, QString>(QLatin1String("q"), query.searchTerm()));
- if (query.searchArea()) {
+ if (query.searchArea().isValid()) {
queryItems.append(qMakePair<QString, QString>(QLatin1String("at"),
boundingAreaToLatLong(query.searchArea())));
}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp b/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp
index c22f0562..d43e4743 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp
+++ b/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp
@@ -70,27 +70,25 @@ void SearchReply::start()
connect(db(), SIGNAL(response(int,QVariant)), this, SLOT(processResponse(int,QVariant)));
connect(db(), SIGNAL(error(int,int,QString)), this, SLOT(processError(int,int,QString)));
- if (request().searchArea() != 0) {
- QGeoBoundingArea *searchArea = request().searchArea();
- if (searchArea->type() == QGeoBoundingArea::BoxType) {
- QGeoBoundingBox *box = static_cast<QGeoBoundingBox *>(searchArea);
- if (!box->isValid()) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("Bounding box search area is invalid"));
- return;
- }
- } else if (searchArea->type() == QGeoBoundingArea::CircleType) {
- QGeoBoundingCircle *circle = static_cast<QGeoBoundingCircle *>(searchArea);
- if (!circle->center().isValid() || qIsNaN(circle->center().latitude()) || qIsNaN(circle->center().longitude())) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("The center of the search area is an invalid coordinate"));
- return;
- }
- if (circle->contains(QGeoCoordinate(90,0)) || circle->contains(QGeoCoordinate(-90,0))) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("The search area contains the north or south pole"));
- return;
- }
+ if (request().searchArea().type() == QGeoBoundingArea::BoxType) {
+ QGeoBoundingBox box(request().searchArea());
+ if (!box.isValid()) {
+ triggerDone(QPlaceReply::BadArgumentError,
+ QString::fromLatin1("Bounding box search area is invalid"));
+ return;
+ }
+ } else if (request().searchArea().type() == QGeoBoundingArea::CircleType) {
+ QGeoBoundingCircle circle(request().searchArea());
+ if (!circle.center().isValid() || qIsNaN(circle.center().latitude()) || qIsNaN(circle.center().longitude())) {
+ triggerDone(QPlaceReply::BadArgumentError,
+ QString::fromLatin1("The center of the search area is an invalid coordinate"));
+ return;
+ }
+
+ if (circle.contains(QGeoCoordinate(90,0)) || circle.contains(QGeoCoordinate(-90,0))) {
+ triggerDone(QPlaceReply::BadArgumentError,
+ QString::fromLatin1("The search area contains the north or south pole"));
+ return;
}
}
@@ -148,79 +146,76 @@ void SearchReply::processResponse(int id, const QVariant &data)
QPlaceSearchResult result;
result.setType(QPlaceSearchResult::PlaceResult);
- if (request().searchArea() != 0) {
- QGeoBoundingArea *searchArea = request().searchArea();
- if (searchArea->type() == QGeoBoundingArea::CircleType) {
- QGeoBoundingCircle *circle = static_cast<QGeoBoundingCircle*>(searchArea);
-
- QPlace place;
- for (int i=0; i < places.count(); ++i) {
- place = places.at(i);
- qreal dist = circle->center().distanceTo(place.location().coordinate());
- if (dist < circle->radius() || qFuzzyCompare(dist, circle->radius()) || circle->radius() < 0.0) {
- result.setDistance(dist);
- result.setPlace(place);
-
- if (request().relevanceHint() == QPlaceSearchRequest::DistanceHint) {
- //TODO: we can optimize this insertion sort
- bool added = false;
- for (int i=0; i < results.count(); ++i) {
- if (result.distance() < results.at(i).distance() || qFuzzyCompare(result.distance(),results.at(i).distance())) {
- results.insert(i, result);
- added = true;
- break;
- }
- }
- if (!added)
- results.append(result);
+ if (request().searchArea().type() == QGeoBoundingArea::CircleType) {
+ QGeoBoundingCircle circle(request().searchArea());
- } else {
- results.append(result);
+ QPlace place;
+ for (int i=0; i < places.count(); ++i) {
+ place = places.at(i);
+ qreal dist = circle.center().distanceTo(place.location().coordinate());
+ if (dist < circle.radius() || qFuzzyCompare(dist, circle.radius()) || circle.radius() < 0.0) {
+ result.setDistance(dist);
+ result.setPlace(place);
+
+ if (request().relevanceHint() == QPlaceSearchRequest::DistanceHint) {
+ //TODO: we can optimize this insertion sort
+ bool added = false;
+ for (int i=0; i < results.count(); ++i) {
+ if (result.distance() < results.at(i).distance() || qFuzzyCompare(result.distance(),results.at(i).distance())) {
+ results.insert(i, result);
+ added = true;
+ break;
+ }
}
+ if (!added)
+ results.append(result);
+
+ } else {
+ results.append(result);
}
}
+ }
- //TODO: we can optimize this using a bounding box to cull candidates
- // and then use distance comparisons for the rest.
+ //TODO: we can optimize this using a bounding box to cull candidates
+ // and then use distance comparisons for the rest.
- } else if (searchArea->type() == QGeoBoundingArea::BoxType) {
- //There seem to be some issues with using the comparison operators
- //so for now we filter in the plugin code
- QGeoBoundingBox *box = static_cast<QGeoBoundingBox *>(searchArea);
- double tly = box->topLeft().latitude();
- double bry = box->bottomRight().latitude();
- double tlx = box->topLeft().longitude();
- double brx = box->bottomRight().longitude();
+ } else if (request().searchArea().type() == QGeoBoundingArea::BoxType) {
+ //There seem to be some issues with using the comparison operators
+ //so for now we filter in the plugin code
+ QGeoBoundingBox box(request().searchArea());
+ double tly = box.topLeft().latitude();
+ double bry = box.bottomRight().latitude();
+ double tlx = box.topLeft().longitude();
+ double brx = box.bottomRight().longitude();
- foreach (const QPlace &place, places) {
- const QGeoCoordinate& coord = place.location().coordinate();
+ foreach (const QPlace &place, places) {
+ const QGeoCoordinate& coord = place.location().coordinate();
- if (coord.latitude() > tly)
- places.removeAll(place);
- if (coord.latitude() < bry)
- places.removeAll(place);
+ if (coord.latitude() > tly)
+ places.removeAll(place);
+ if (coord.latitude() < bry)
+ places.removeAll(place);
- bool lonWrap = (tlx > brx); //box wraps over the dateline
+ bool lonWrap = (tlx > brx); //box wraps over the dateline
- if (!lonWrap) {
- if (coord.longitude() < tlx || coord.longitude() > brx) {
- places.removeAll(place);
- }
- } else {
- if (coord.longitude() < tlx && coord.longitude() > brx) {
- places.removeAll(place);
- }
+ if (!lonWrap) {
+ if (coord.longitude() < tlx || coord.longitude() > brx) {
+ places.removeAll(place);
+ }
+ } else {
+ if (coord.longitude() < tlx && coord.longitude() > brx) {
+ places.removeAll(place);
}
}
+ }
- const QGeoCoordinate bCenter = box->center();
- foreach (const QPlace &place, places) {
- const QGeoCoordinate coord = place.location().coordinate();
- qreal distance = bCenter.distanceTo(coord);
- result.setPlace(place);
- result.setDistance(distance);
- results.append(result);
- }
+ const QGeoCoordinate bCenter = box.center();
+ foreach (const QPlace &place, places) {
+ const QGeoCoordinate coord = place.location().coordinate();
+ qreal distance = bCenter.distanceTo(coord);
+ result.setPlace(place);
+ result.setDistance(distance);
+ results.append(result);
}
}
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 50483a40..0769e70d 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -29,6 +29,7 @@ SUBDIRS += geotestplugin \
qgeocodingmanagerplugins \
qgeoaddress \
qgeoareamonitor \
+ qgeoboundingarea \
qgeoboundingbox \
qgeoboundingcircle \
qgeocodereply \
diff --git a/tests/auto/declarative_core/declarative_core.pro b/tests/auto/declarative_core/declarative_core.pro
index 4e82dc6a..a502f726 100644
--- a/tests/auto/declarative_core/declarative_core.pro
+++ b/tests/auto/declarative_core/declarative_core.pro
@@ -9,4 +9,3 @@ SOURCES += main.cpp
QT += location quick
OTHER_FILES += *.qml
-
diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
index fbd743c4..51fe3dd0 100644
--- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
@@ -68,7 +68,7 @@ public:
void callSetLimit ( int limit ) {setLimit(limit);}
void callSetOffset ( int offset ) {setOffset(offset);}
void callSetLocations ( const QList<QGeoLocation> & locations ) {setLocations(locations);}
- void callSetViewport ( QGeoBoundingArea * viewport ) {setViewport(viewport);}
+ void callSetViewport ( const QGeoBoundingArea &viewport ) {setViewport(viewport);}
void abort() {
emit aborted();
}
@@ -108,7 +108,7 @@ public:
QGeocodeReply* geocode(const QString &searchString,
int limit = -1,
int offset = 0,
- QGeoBoundingArea *bounds = 0)
+ const QGeoBoundingArea &bounds = QGeoBoundingArea())
{
geocodeReply_ = new GeocodeReplyTest();
connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted()));
@@ -140,7 +140,7 @@ public:
return static_cast<QGeocodeReply*>(geocodeReply_);
}
- QGeocodeReply* geocode ( const QGeoAddress & address, QGeoBoundingArea * bounds )
+ QGeocodeReply* geocode ( const QGeoAddress & address, const QGeoBoundingArea &bounds )
{
geocodeReply_ = new GeocodeReplyTest();
connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted()));
@@ -227,7 +227,7 @@ public:
}
}
- QGeocodeReply* reverseGeocode ( const QGeoCoordinate & coordinate, QGeoBoundingArea * bounds )
+ QGeocodeReply* reverseGeocode ( const QGeoCoordinate & coordinate, const QGeoBoundingArea &bounds )
{
geocodeReply_ = new GeocodeReplyTest();
connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted()));
diff --git a/tests/auto/qgeoboundingarea/qgeoboundingarea.pro b/tests/auto/qgeoboundingarea/qgeoboundingarea.pro
new file mode 100644
index 00000000..ea2f18df
--- /dev/null
+++ b/tests/auto/qgeoboundingarea/qgeoboundingarea.pro
@@ -0,0 +1,4 @@
+load(testcase)
+TARGET = tst_qgeoboundingarea
+QT += testlib location
+SOURCES = tst_qgeoboundingarea.cpp
diff --git a/tests/auto/qgeoboundingarea/tst_qgeoboundingarea.cpp b/tests/auto/qgeoboundingarea/tst_qgeoboundingarea.cpp
new file mode 100644
index 00000000..5f1c68c4
--- /dev/null
+++ b/tests/auto/qgeoboundingarea/tst_qgeoboundingarea.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtLocation/QGeoBoundingArea>
+
+class tst_qgeoboundingarea : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testArea();
+};
+
+void tst_qgeoboundingarea::testArea()
+{
+ QGeoBoundingArea area;
+ QVERIFY(!area.isValid());
+ QVERIFY(area.isEmpty());
+ QCOMPARE(area.type(), QGeoBoundingArea::UnknownType);
+ QVERIFY(!area.contains(QGeoCoordinate()));
+
+ // QGeoBoundingArea never constructs a QGeoBoundingAreaPrivate. Hence d_ptr is always 0.
+
+ QGeoBoundingArea area2;
+
+ QCOMPARE(area, area2);
+
+ area = area2;
+
+ QCOMPARE(area, area2);
+
+ QGeoBoundingArea area3(area2);
+
+ QCOMPARE(area2, area3);
+}
+
+QTEST_MAIN(tst_qgeoboundingarea)
+#include "tst_qgeoboundingarea.moc"
diff --git a/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp b/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp
index 443f9147..b270f4a4 100644
--- a/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp
+++ b/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp
@@ -95,8 +95,11 @@ private slots:
void unite();
void unite_data();
- void clone();
void areaComparison();
+ void areaComparison_data();
+
+ void circleComparison();
+ void circleComparison_data();
};
void tst_QGeoBoundingBox::default_constructor()
@@ -136,6 +139,16 @@ void tst_QGeoBoundingBox::copy_constructor()
b2.setBottomRight(QGeoCoordinate(0.0, 30.0));
QCOMPARE(b1.topLeft(), QGeoCoordinate(10.0, 0.0));
QCOMPARE(b1.bottomRight(), QGeoCoordinate(0.0, 10.0));
+
+ QGeoBoundingArea area;
+ QGeoBoundingBox areaBox(area);
+ QVERIFY(!areaBox.isValid());
+ QVERIFY(areaBox.isEmpty());
+
+ QGeoBoundingCircle circle;
+ QGeoBoundingBox circleBox(circle);
+ QVERIFY(!circleBox.isValid());
+ QVERIFY(circleBox.isEmpty());
}
void tst_QGeoBoundingBox::destructor()
@@ -152,30 +165,65 @@ void tst_QGeoBoundingBox::assignment()
QGeoBoundingBox b2 = QGeoBoundingBox(QGeoCoordinate(20.0, 0.0),
QGeoCoordinate(0.0, 20.0));
+ QVERIFY(b1 != b2);
+
b2 = b1;
QCOMPARE(b2.topLeft(), QGeoCoordinate(10.0, 0.0));
QCOMPARE(b2.bottomRight(), QGeoCoordinate(0.0, 10.0));
+ QCOMPARE(b1, b2);
b2.setTopLeft(QGeoCoordinate(30.0, 0.0));
b2.setBottomRight(QGeoCoordinate(0.0, 30.0));
QCOMPARE(b1.topLeft(), QGeoCoordinate(10.0, 0.0));
QCOMPARE(b1.bottomRight(), QGeoCoordinate(0.0, 10.0));
+
+ // Assign b1 to an area
+ QGeoBoundingArea area = b1;
+ QCOMPARE(area.type(), b1.type());
+ QVERIFY(area == b1);
+
+ // Assign the area back to a bounding box
+ QGeoBoundingBox ba = area;
+ QCOMPARE(ba.topLeft(), b1.topLeft());
+ QCOMPARE(ba.bottomRight(), b1.bottomRight());
+
+ // Check that the copy is not modified when modifying the original.
+ b1.setTopLeft(QGeoCoordinate(80, 30));
+ QVERIFY(ba.topLeft() != b1.topLeft());
+ QVERIFY(ba != b1);
}
void tst_QGeoBoundingBox::equality()
{
- QFETCH(QGeoBoundingBox, input1);
- QFETCH(QGeoBoundingBox, input2);
+ QFETCH(QGeoBoundingBox, box1);
+ QFETCH(QGeoBoundingBox, box2);
+ QFETCH(QGeoBoundingArea, area1);
+ QFETCH(QGeoBoundingArea, area2);
QFETCH(bool, equal);
- QCOMPARE((input1 == input2), equal);
- QCOMPARE((input1 != input2), !equal);
+ // compare boxes
+ QCOMPARE((box1 == box2), equal);
+ QCOMPARE((box1 != box2), !equal);
+
+ // compare areas
+ QCOMPARE((area1 == area2), equal);
+ QCOMPARE((area1 != area2), !equal);
+
+ // compare area to box
+ QCOMPARE((area1 == box2), equal);
+ QCOMPARE((area1 != box2), !equal);
+
+ // compare box to area
+ QCOMPARE((box1 == area2), equal);
+ QCOMPARE((box1 != area2), !equal);
}
void tst_QGeoBoundingBox::equality_data()
{
- QTest::addColumn<QGeoBoundingBox>("input1");
- QTest::addColumn<QGeoBoundingBox>("input2");
+ QTest::addColumn<QGeoBoundingBox>("box1");
+ QTest::addColumn<QGeoBoundingBox>("box2");
+ QTest::addColumn<QGeoBoundingArea>("area1");
+ QTest::addColumn<QGeoBoundingArea>("area2");
QTest::addColumn<bool>("equal");
QGeoCoordinate c1(10, 5);
@@ -189,14 +237,20 @@ void tst_QGeoBoundingBox::equality_data()
QGeoBoundingBox b4(c1, c3);
QGeoBoundingBox b5(c1, c2);
+ QGeoBoundingArea a1(b1);
+ QGeoBoundingArea a2(b2);
+ QGeoBoundingArea a3(b3);
+ QGeoBoundingArea a4(b4);
+ QGeoBoundingArea a5(b5);
+
QTest::newRow("all unequal")
- << b1 << b2 << false;
+ << b1 << b2 << a1 << a2 << false;
QTest::newRow("top left unequal")
- << b1 << b3 << false;
+ << b1 << b3 << a1 << a3 << false;
QTest::newRow("bottom right unequal")
- << b1 << b4 << false;
+ << b1 << b4 << a1 << a4 << false;
QTest::newRow("equal")
- << b1 << b5 << true;
+ << b1 << b5 << a1 << a5 << true;
}
void tst_QGeoBoundingBox::isValid()
@@ -205,6 +259,9 @@ void tst_QGeoBoundingBox::isValid()
QFETCH(bool, valid);
QCOMPARE(input.isValid(), valid);
+
+ QGeoBoundingArea area = input;
+ QCOMPARE(area.isValid(), valid);
}
void tst_QGeoBoundingBox::isValid_data()
@@ -234,6 +291,9 @@ void tst_QGeoBoundingBox::isEmpty()
QFETCH(bool, empty);
QCOMPARE(input.isEmpty(), empty);
+
+ QGeoBoundingArea area = input;
+ QCOMPARE(area.isEmpty(), empty);
}
void tst_QGeoBoundingBox::isEmpty_data()
@@ -895,6 +955,9 @@ void tst_QGeoBoundingBox::containsCoord()
QFETCH(bool, contains);
QCOMPARE(box.contains(coord), contains);
+
+ QGeoBoundingArea area = box;
+ QCOMPARE(area.contains(coord), contains);
}
void tst_QGeoBoundingBox::containsCoord_data()
@@ -2127,60 +2190,61 @@ void tst_QGeoBoundingBox::unite_data()
QGeoCoordinate(-30.0, 180.0));
}
-void tst_QGeoBoundingBox::clone()
+void tst_QGeoBoundingBox::areaComparison_data()
{
- //check that the clone copies the same data as the original
- QGeoBoundingBox originalBox;
- originalBox.setTopLeft(QGeoCoordinate(20,20));
- originalBox.setBottomRight(QGeoCoordinate(10,30));
-
- QGeoBoundingArea *areaPtr = originalBox.clone();
- QVERIFY(areaPtr->type() == QGeoBoundingArea::BoxType);
- QGeoBoundingBox *clonedBoxPtr;
- clonedBoxPtr = static_cast<QGeoBoundingBox*>(areaPtr);
- QVERIFY2(clonedBoxPtr->topLeft() == QGeoCoordinate(20,20),
- "Clone's top left coord does not match original");
- QVERIFY2(clonedBoxPtr->bottomRight() == QGeoCoordinate(10,30),
- "Clone's bottom right coord does not match original");
-
- //check that when the original is altered, the clone remains unaltered.
- originalBox.setTopLeft(QGeoCoordinate(80,30));
- originalBox.setBottomRight(QGeoCoordinate(10,40));
-
- QVERIFY2(originalBox.topLeft() == QGeoCoordinate(80,30),
- "Original's top left coord has not changed");
- QVERIFY2(originalBox.bottomRight() == QGeoCoordinate(10,40),
- "Original's bottom right coord has not changed");
-
- QVERIFY2(clonedBoxPtr->topLeft() == QGeoCoordinate(20,20),
- "Clone's top left coord references the original's");
- QVERIFY2(clonedBoxPtr->bottomRight() == QGeoCoordinate(10,30),
- "Clone's bottom right coord references the original's");
+ QTest::addColumn<QGeoBoundingArea>("area");
+ QTest::addColumn<QGeoBoundingBox>("box");
+ QTest::addColumn<bool>("equal");
+
+ QGeoBoundingBox b1(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));
+ QGeoBoundingBox b2(QGeoCoordinate(20.0, 0.0), QGeoCoordinate(0.0, 20.0));
+ QGeoBoundingCircle c(QGeoCoordinate(0.0, 0.0), 10);
+
+ QTest::newRow("default constructed") << QGeoBoundingArea() << QGeoBoundingBox() << false;
+ QTest::newRow("b1 b1") << QGeoBoundingArea(b1) << b1 << true;
+ QTest::newRow("b1 b2") << QGeoBoundingArea(b1) << b2 << false;
+ QTest::newRow("b2 b1") << QGeoBoundingArea(b2) << b1 << false;
+ QTest::newRow("b2 b2") << QGeoBoundingArea(b2) << b2 << true;
+ QTest::newRow("c b1") << QGeoBoundingArea(c) << b1 << false;
}
void tst_QGeoBoundingBox::areaComparison()
{
- QGeoBoundingBox b1(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
- QGeoBoundingBox b2(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
- QGeoBoundingBox b3(QGeoCoordinate(40,40), QGeoCoordinate(10,30));
+ QFETCH(QGeoBoundingArea, area);
+ QFETCH(QGeoBoundingBox, box);
+ QFETCH(bool, equal);
- QVERIFY(b1 == b2);
- QVERIFY(!(b1 != b2));
+ QCOMPARE((area == box), equal);
+ QCOMPARE((area != box), !equal);
- QVERIFY(!(b1 == b3));
- QVERIFY(b1 != b3);
+ QCOMPARE((box == area), equal);
+ QCOMPARE((box != area), !equal);
+}
- QGeoBoundingCircle c1(QGeoCoordinate(20,20), 5000);
- QVERIFY(!(b1 == c1));
- QVERIFY(b1 != c1);
+void tst_QGeoBoundingBox::circleComparison_data()
+{
+ QTest::addColumn<QGeoBoundingCircle>("circle");
+ QTest::addColumn<QGeoBoundingBox>("box");
+ QTest::addColumn<bool>("equal");
+
+ QGeoBoundingBox b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));
+ QGeoBoundingCircle c(QGeoCoordinate(0.0, 0.0), 10);
+
+ QTest::newRow("default constructed") << QGeoBoundingCircle() << QGeoBoundingBox() << false;
+ QTest::newRow("c b") << c << b << false;
+}
+
+void tst_QGeoBoundingBox::circleComparison()
+{
+ QFETCH(QGeoBoundingCircle, circle);
+ QFETCH(QGeoBoundingBox, box);
+ QFETCH(bool, equal);
- QGeoBoundingArea *b2Ptr = &b2;
- QVERIFY(b1 == *b2Ptr);
- QVERIFY(!(b1 != *b2Ptr));
+ QCOMPARE((circle == box), equal);
+ QCOMPARE((circle != box), !equal);
- QGeoBoundingArea *b3Ptr = &b3;
- QVERIFY(!(b1 == *b3Ptr));
- QVERIFY(b1 != *b3Ptr);
+ QCOMPARE((box == circle), equal);
+ QCOMPARE((box != circle), !equal);
}
QTEST_MAIN(tst_QGeoBoundingBox)
diff --git a/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp b/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp
index 5778ba70..ff3a61d8 100644
--- a/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp
+++ b/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp
@@ -53,6 +53,7 @@ class tst_QGeoBoundingCircle : public QObject
private slots:
void defaultConstructor();
void centerRadiusConstructor();
+ void assignment();
void comparison();
void type();
@@ -72,7 +73,11 @@ private slots:
void contains_data();
void contains();
- void clone();
+ void areaComparison();
+ void areaComparison_data();
+
+ void boxComparison();
+ void boxComparison_data();
};
void tst_QGeoBoundingCircle::defaultConstructor()
@@ -89,6 +94,39 @@ void tst_QGeoBoundingCircle::centerRadiusConstructor()
QCOMPARE(c.radius(), qreal(50.0));
}
+void tst_QGeoBoundingCircle::assignment()
+{
+ QGeoBoundingCircle c1 = QGeoBoundingCircle(QGeoCoordinate(10.0, 0.0), 20.0);
+ QGeoBoundingCircle c2 = QGeoBoundingCircle(QGeoCoordinate(20.0, 0.0), 30.0);
+
+ QVERIFY(c1 != c2);
+
+ c2 = c1;
+ QCOMPARE(c2.center(), QGeoCoordinate(10.0, 0.0));
+ QCOMPARE(c2.radius(), 20.0);
+ QCOMPARE(c1, c2);
+
+ c2.setCenter(QGeoCoordinate(30.0, 0.0));
+ c2.setRadius(15.0);
+ QCOMPARE(c1.center(), QGeoCoordinate(10.0, 0.0));
+ QCOMPARE(c1.radius(), 20.0);
+
+ // Assign c1 to an area
+ QGeoBoundingArea area = c1;
+ QCOMPARE(area.type(), c1.type());
+ QVERIFY(area == c1);
+
+ // Assign the area back to a bounding circle
+ QGeoBoundingCircle ca = area;
+ QCOMPARE(ca.center(), c1.center());
+ QCOMPARE(ca.radius(), c1.radius());
+
+ // Check that the copy is not modified when modifying the original.
+ c1.setCenter(QGeoCoordinate(15.0, 15.0));
+ QVERIFY(ca.center() != c1.center());
+ QVERIFY(ca != c1);
+}
+
void tst_QGeoBoundingCircle::comparison()
{
QGeoBoundingCircle c1(QGeoCoordinate(1,1), qreal(50.0));
@@ -209,6 +247,9 @@ void tst_QGeoBoundingCircle::valid()
QGeoBoundingCircle c(center, radius);
QCOMPARE(c.isValid(), valid);
+
+ QGeoBoundingArea area = c;
+ QCOMPARE(c.isValid(), valid);
}
void tst_QGeoBoundingCircle::empty_data()
@@ -234,6 +275,9 @@ void tst_QGeoBoundingCircle::empty()
QGeoBoundingCircle c(center, radius);
QCOMPARE(c.isEmpty(), empty);
+
+ QGeoBoundingArea area = c;
+ QCOMPARE(area.isEmpty(), empty);
}
void tst_QGeoBoundingCircle::contains_data()
@@ -264,34 +308,66 @@ void tst_QGeoBoundingCircle::contains()
QGeoBoundingCircle c(center, radius);
QCOMPARE(c.contains(probe), result);
+
+ QGeoBoundingArea area = c;
+ QCOMPARE(area.contains(probe), result);
+}
+
+void tst_QGeoBoundingCircle::areaComparison_data()
+{
+ QTest::addColumn<QGeoBoundingArea>("area");
+ QTest::addColumn<QGeoBoundingCircle>("circle");
+ QTest::addColumn<bool>("equal");
+
+ QGeoBoundingCircle c1(QGeoCoordinate(10.0, 0.0), 10.0);
+ QGeoBoundingCircle c2(QGeoCoordinate(20.0, 10.0), 20.0);
+ QGeoBoundingBox b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));
+
+ QTest::newRow("default constructed") << QGeoBoundingArea() << QGeoBoundingCircle() << false;
+ QTest::newRow("c1 c1") << QGeoBoundingArea(c1) << c1 << true;
+ QTest::newRow("c1 c2") << QGeoBoundingArea(c1) << c2 << false;
+ QTest::newRow("c2 c1") << QGeoBoundingArea(c2) << c1 << false;
+ QTest::newRow("c2 c2") << QGeoBoundingArea(c2) << c2 << true;
+ QTest::newRow("b c1") << QGeoBoundingArea(b) << c1 << false;
}
-void tst_QGeoBoundingCircle::clone()
+void tst_QGeoBoundingCircle::areaComparison()
{
- //check that the clone copies the same data as the original
- QGeoBoundingCircle originalCircle;
- originalCircle.setCenter(QGeoCoordinate(1,1));
- originalCircle.setRadius(500.0);
- QGeoBoundingArea *areaPtr = originalCircle.clone();
- QVERIFY(areaPtr->type() == QGeoBoundingArea::CircleType);
- QGeoBoundingCircle *clonedCirclePtr;
- clonedCirclePtr = static_cast<QGeoBoundingCircle*>(areaPtr);
- QVERIFY2(clonedCirclePtr->center() == QGeoCoordinate(1,1),
- "Center of clone does not match original");
- QVERIFY2(clonedCirclePtr->radius() == 500.0,
- "Radius of clone does not match original");
-
- //check that when the original is altered, the clone remains unaltered.
- originalCircle.setCenter(QGeoCoordinate(9,9));
- originalCircle.setRadius(99.9);
-
- QVERIFY2(originalCircle.center() == QGeoCoordinate(9,9),
- "Center of original has not changed");
- QCOMPARE(originalCircle.radius(), 99.9);
-
- QVERIFY2(clonedCirclePtr->center() == QGeoCoordinate(1,1),
- "Center of clone references center of original");
- QCOMPARE(clonedCirclePtr->radius(), 500.0);
+ QFETCH(QGeoBoundingArea, area);
+ QFETCH(QGeoBoundingCircle, circle);
+ QFETCH(bool, equal);
+
+ QCOMPARE((area == circle), equal);
+ QCOMPARE((area != circle), !equal);
+
+ QCOMPARE((circle == area), equal);
+ QCOMPARE((circle != area), !equal);
+}
+
+void tst_QGeoBoundingCircle::boxComparison_data()
+{
+ QTest::addColumn<QGeoBoundingBox>("box");
+ QTest::addColumn<QGeoBoundingCircle>("circle");
+ QTest::addColumn<bool>("equal");
+
+ QGeoBoundingCircle c(QGeoCoordinate(10.0, 0.0), 10.0);
+ QGeoBoundingBox b(QGeoCoordinate(10.0, 0.0), QGeoCoordinate(0.0, 10.0));
+
+ QTest::newRow("default constructed") << QGeoBoundingBox() << QGeoBoundingCircle() << false;
+ QTest::newRow("b c") << b << c << false;
+}
+
+void tst_QGeoBoundingCircle::boxComparison()
+{
+ QFETCH(QGeoBoundingBox, box);
+ QFETCH(QGeoBoundingCircle, circle);
+ QFETCH(bool, equal);
+
+ QCOMPARE((box == circle), equal);
+ QCOMPARE((box != circle), !equal);
+
+ QCOMPARE((circle == box), equal);
+ QCOMPARE((circle != box), !equal);
}
QTEST_MAIN(tst_QGeoBoundingCircle)
diff --git a/tests/auto/qgeocodereply/tst_qgeocodereply.cpp b/tests/auto/qgeocodereply/tst_qgeocodereply.cpp
index 76758213..e030b090 100644
--- a/tests/auto/qgeocodereply/tst_qgeocodereply.cpp
+++ b/tests/auto/qgeocodereply/tst_qgeocodereply.cpp
@@ -277,9 +277,9 @@ void tst_QGeocodeReply::viewport()
qgeoboundingbox = new QGeoBoundingBox (*qgeocoordinate, 0.5 , 0.5);
- reply->callSetViewport(qgeoboundingbox);
+ reply->callSetViewport(*qgeoboundingbox);
- QCOMPARE (reply->viewport(), static_cast<QGeoBoundingArea*>(qgeoboundingbox));
+ QCOMPARE (reply->viewport(), static_cast<const QGeoBoundingArea &>(*qgeoboundingbox));
delete qgeocoordinate;
delete qgeoboundingbox;
diff --git a/tests/auto/qgeocodereply/tst_qgeocodereply.h b/tests/auto/qgeocodereply/tst_qgeocodereply.h
index 070c7084..f6971da0 100644
--- a/tests/auto/qgeocodereply/tst_qgeocodereply.h
+++ b/tests/auto/qgeocodereply/tst_qgeocodereply.h
@@ -69,7 +69,7 @@ public:
void callSetLimit ( int limit ) {setLimit(limit);}
void callSetOffset ( int offset ) {setOffset(offset);}
void callSetLocations ( const QList<QGeoLocation> & locations ) {setLocations(locations);}
- void callSetViewport ( QGeoBoundingArea * viewport ) {setViewport(viewport);}
+ void callSetViewport ( const QGeoBoundingArea &viewport ) {setViewport(viewport);}
};
diff --git a/tests/auto/qgeocodingmanager/tst_qgeocodingmanager.cpp b/tests/auto/qgeocodingmanager/tst_qgeocodingmanager.cpp
index 0a075a00..7a292bec 100644
--- a/tests/auto/qgeocodingmanager/tst_qgeocodingmanager.cpp
+++ b/tests/auto/qgeocodingmanager/tst_qgeocodingmanager.cpp
@@ -131,17 +131,14 @@ void tst_QGeocodingManager::search()
QString search = "Berlin. Invaliendenstrasse";
int limit = 10;
int offset = 2;
- QGeoBoundingBox *bounds = new QGeoBoundingBox ();
- QGeocodeReply * reply = qgeocodingmanager->geocode(search, limit,offset,bounds);
+ QGeocodeReply * reply = qgeocodingmanager->geocode(search, limit,offset);
QCOMPARE(reply->errorString(),search);
QCOMPARE(signalfinished->count(),1);
QCOMPARE(signalerror->count(),0);
delete reply;
- delete bounds;
-
}
void tst_QGeocodingManager::geocode()
@@ -153,16 +150,13 @@ void tst_QGeocodingManager::geocode()
QString city = "Berlin";
address->setCity(city);
- QGeoBoundingBox *bounds = new QGeoBoundingBox ();
-
- QGeocodeReply *reply = qgeocodingmanager->geocode(*address,bounds);
+ QGeocodeReply *reply = qgeocodingmanager->geocode(*address);
QCOMPARE(reply->errorString(),city);
QCOMPARE(signalfinished->count(),1);
QCOMPARE(signalerror->count(),0);
delete address;
- delete bounds;
delete reply;
}
@@ -172,16 +166,14 @@ void tst_QGeocodingManager::reverseGeocode()
QCOMPARE(signalfinished->count(),0);
QGeoCoordinate *coordinate = new QGeoCoordinate (34.34 , 56.65);
- QGeoBoundingBox *bounds = new QGeoBoundingBox ();
- QGeocodeReply *reply = qgeocodingmanager->reverseGeocode(*coordinate,bounds);
+ QGeocodeReply *reply = qgeocodingmanager->reverseGeocode(*coordinate);
QCOMPARE(reply->errorString(),coordinate->toString());
QCOMPARE(signalfinished->count(),1);
QCOMPARE(signalerror->count(),0);
delete coordinate;
- delete bounds;
delete reply;
diff --git a/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h b/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
index 9022362b..4c1a2e66 100644
--- a/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
+++ b/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
@@ -65,7 +65,7 @@ public:
void callSetLimit ( int limit ) {setLimit(limit);}
void callSetOffset ( int offset ) {setOffset(offset);}
void callSetLocations ( const QList<QGeoLocation> & locations ) {setLocations(locations);}
- void callSetViewport ( QGeoBoundingArea * viewport ) {setViewport(viewport);}
+ void callSetViewport ( const QGeoBoundingArea &viewport ) {setViewport(viewport);}
};
@@ -85,7 +85,7 @@ public:
setLocale(QLocale(QLocale::German, QLocale::Germany));
}
- QGeocodeReply* geocode ( const QString & searchString, int limit, int offset, QGeoBoundingArea * bounds )
+ QGeocodeReply* geocode ( const QString & searchString, int limit, int offset, const QGeoBoundingArea &bounds )
{
GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
geocodereply->callSetLimit(limit);
@@ -98,7 +98,7 @@ public:
return static_cast<QGeocodeReply*>(geocodereply);
}
- QGeocodeReply* geocode ( const QGeoAddress & address, QGeoBoundingArea * bounds )
+ QGeocodeReply* geocode ( const QGeoAddress & address, const QGeoBoundingArea &bounds )
{
GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
geocodereply->callSetViewport(bounds);
@@ -109,7 +109,7 @@ public:
return static_cast<QGeocodeReply*>(geocodereply);
}
- QGeocodeReply* reverseGeocode ( const QGeoCoordinate & coordinate, QGeoBoundingArea * bounds )
+ QGeocodeReply* reverseGeocode ( const QGeoCoordinate & coordinate, const QGeoBoundingArea &bounds )
{
GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
geocodereply->callSetViewport(bounds);
diff --git a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
index f1452b7a..f5638020 100644
--- a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
+++ b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
@@ -743,7 +743,7 @@ void tst_QPlaceManagerJsonDb::searchByBox()
doSavePlaces(places);
QPlaceSearchRequest request;
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, -5.0), QGeoCoordinate(-5.0, 5.0)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(5.0, -5.0), QGeoCoordinate(-5.0, 5.0)));
QList<QPlaceSearchResult> results1;
doSearch(request, &results1);
@@ -763,7 +763,7 @@ void tst_QPlaceManagerJsonDb::searchByBox()
QCOMPARE(testSet1, inBoxSet1);
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, 10.0), QGeoCoordinate(-5.0, 20.0)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(5.0, 10.0), QGeoCoordinate(-5.0, 20.0)));
QList<QPlace> places2;
doSearch(request, &places2);
QCOMPARE(places2.size(), inBox2.size());
@@ -778,7 +778,7 @@ void tst_QPlaceManagerJsonDb::searchByBox()
QCOMPARE(testSet2, inBoxSet2);
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20.0, -5.0), QGeoCoordinate(10.0, 5.0)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(20.0, -5.0), QGeoCoordinate(10.0, 5.0)));
QList<QPlace> places3;
doSearch(request, &places3);
@@ -794,7 +794,7 @@ void tst_QPlaceManagerJsonDb::searchByBox()
QCOMPARE(testSet3, inBoxSet3);
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20.0, 10.0), QGeoCoordinate(10.0, 20.0)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(20.0, 10.0), QGeoCoordinate(10.0, 20.0)));
QList<QPlace> places4;
doSearch(request, &places4);
QCOMPARE(places4.size(), inBox4.size());
@@ -809,7 +809,7 @@ void tst_QPlaceManagerJsonDb::searchByBox()
QCOMPARE(testSet4, inBoxSet4);
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, 175.0), QGeoCoordinate(-5.0, -175.0)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(5.0, 175.0), QGeoCoordinate(-5.0, -175.0)));
QList<QPlace> places5;
doSearch(request, &places5);
QCOMPARE(places5.size(), inBox5.size());
@@ -835,17 +835,17 @@ void tst_QPlaceManagerJsonDb::searchByBox()
QCOMPARE(testSet5, inBoxSet5);
//try a box that finds nothing
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(-70,-70), QGeoCoordinate(-80,-60)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(-70,-70), QGeoCoordinate(-80,-60)));
QVERIFY(doSearch(request, &places));
QCOMPARE(places.count(), 0);
//--- Test error conditions
//bottom right latitude > top left latitude
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(50,30)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(50,30)));
QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
//try an invalid coordinate for one of the corners
- request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(qQNaN(),20),QGeoCoordinate(10,30)));
+ request.setSearchArea(QGeoBoundingBox(QGeoCoordinate(qQNaN(),20),QGeoCoordinate(10,30)));
QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
}
@@ -961,7 +961,7 @@ void tst_QPlaceManagerJsonDb::searchByCircle()
QPlaceSearchRequest request;
for (int j = 0; j < filterCoords.size(); ++j) {
- request.setSearchArea(new QGeoBoundingCircle(filterCoords.at(j),dist));
+ request.setSearchArea(QGeoBoundingCircle(filterCoords.at(j),dist));
if (i ==2 || i ==3) {
//TODO: Testing poles, ignore fo rnow
@@ -992,55 +992,55 @@ void tst_QPlaceManagerJsonDb::searchByCircle()
//--- Test error conditions and edge cases
//try a circle that covers the north pole
QPlaceSearchRequest request;
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(89.91,0),11000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(89.91,0),11000));
QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
QCOMPARE(places.count(), 0);
//try a circle that's close to but does not cover the north pole
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(89.91,0),9000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(89.91,0),9000));
QVERIFY(doSearch(request,&places, QPlaceReply::NoError));
//try a circle that covers the south pole
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-89.91,180),11000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(-89.91,180),11000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QCOMPARE(places.count(), 0);
//try a circle that's close to but does not cover the south pole
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-89.91,180),9000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(-89.91,180),9000));
QVERIFY(doSearch(request, &places, QPlaceReply::NoError));
//try a radius of 0
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(11.0,11.0), 0));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(11.0,11.0), 0));
QVERIFY(doSearch(request, &places));
QCOMPARE(places.count(), 1);
QCOMPARE(places.at(0).location().coordinate().latitude(), 11.0);
QCOMPARE(places.at(0).location().coordinate().longitude(), 11.0);
//try an invalid center
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(), 5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(), 5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
//try an invalid latitude for the center
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(qQNaN(),50), 5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(qQNaN(),50), 5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
//try a proximity filter with an out of range latitude
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(90,10), 5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(90,10), 5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(150,10), 5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(150,10), 5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
//try a proximity filter with an out of range longitude
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-12,180.1),5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(-12,180.1),5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
- request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-12,-180.1),5000));
+ request.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(-12,-180.1),5000));
QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
QVERIFY(places.isEmpty());
}
@@ -1112,7 +1112,7 @@ void tst_QPlaceManagerJsonDb::searchWithDistanceHint()
doSavePlaces(places);
QPlaceSearchRequest searchRequest;
- QGeoBoundingCircle *circle = new QGeoBoundingCircle(QGeoCoordinate(20,20));
+ QGeoBoundingCircle circle(QGeoCoordinate(20,20));
searchRequest.setSearchArea(circle);
searchRequest.setRelevanceHint(QPlaceSearchRequest::DistanceHint);
QList<QPlace> results;
@@ -1126,7 +1126,7 @@ void tst_QPlaceManagerJsonDb::searchWithDistanceHint()
QCOMPARE(results.at(5), place5);
qreal radius = QGeoCoordinate(20,20).distanceTo(QGeoCoordinate(20,50));
- circle->setRadius(radius);
+ circle.setRadius(radius);
QVERIFY(doSearch(searchRequest, &results));
QCOMPARE(results.count(),4);
@@ -1136,7 +1136,7 @@ void tst_QPlaceManagerJsonDb::searchWithDistanceHint()
QCOMPARE(results.at(3), place2);
//try radius less than 1
- circle->setRadius(-5);
+ circle.setRadius(-5);
QVERIFY(doSearch(searchRequest, &results));
QCOMPARE(results.count(), 6);
QCOMPARE(results.at(0), place1);
diff --git a/tests/auto/qplacesearchreply/tst_qplacesearchreply.cpp b/tests/auto/qplacesearchreply/tst_qplacesearchreply.cpp
index e1561946..71f31f5c 100644
--- a/tests/auto/qplacesearchreply/tst_qplacesearchreply.cpp
+++ b/tests/auto/qplacesearchreply/tst_qplacesearchreply.cpp
@@ -102,8 +102,8 @@ void tst_QPlaceSearchReply::requestTest()
request.setLimit(10);
request.setOffset(50);
- QGeoBoundingCircle *circle = new QGeoBoundingCircle();
- circle->setCenter(QGeoCoordinate(10,20));
+ QGeoBoundingCircle circle;
+ circle.setCenter(QGeoCoordinate(10,20));
request.setSearchArea(circle);
request.setSearchTerm("pizza");
diff --git a/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp b/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp
index d780225f..2b5c510b 100644
--- a/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp
+++ b/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp
@@ -109,58 +109,58 @@ void tst_QPlaceSearchRequest::categoriesTest()
void tst_QPlaceSearchRequest::boundingCircleTest()
{
QPlaceSearchRequest query;
- QVERIFY2(query.searchArea() == NULL, "Wrong default value");
- QGeoBoundingCircle *circle = new QGeoBoundingCircle;
- circle->setCenter(QGeoCoordinate(30,20));
- circle->setRadius(500.0);
+ QVERIFY2(query.searchArea() == QGeoBoundingArea(), "Wrong default value");
+ QGeoBoundingCircle circle;
+ circle.setCenter(QGeoCoordinate(30,20));
+ circle.setRadius(500.0);
query.setSearchArea(circle);
- QVERIFY(query.searchArea() != NULL);
- QVERIFY(query.searchArea()->type() == QGeoBoundingArea::CircleType);
+ QVERIFY(query.searchArea() != QGeoBoundingArea());
+ QVERIFY(query.searchArea().type() == QGeoBoundingArea::CircleType);
QVERIFY(query.searchArea() == circle);
- QGeoBoundingCircle *retrievedCircle = static_cast<QGeoBoundingCircle *>(query.searchArea());
- QVERIFY2(retrievedCircle->center() == QGeoCoordinate(30,20), "Wrong value returned");
- QVERIFY2(retrievedCircle->radius() == 500.0, "Wrong value returned");
+ QGeoBoundingCircle retrievedCircle = query.searchArea();
+ QVERIFY2(retrievedCircle.center() == QGeoCoordinate(30,20), "Wrong value returned");
+ QVERIFY2(retrievedCircle.radius() == 500.0, "Wrong value returned");
query.clear();
- QVERIFY2(query.searchArea() == NULL, "Search area not cleared");
+ QVERIFY2(query.searchArea() == QGeoBoundingArea(), "Search area not cleared");
}
void tst_QPlaceSearchRequest::boundingBoxTest()
{
QPlaceSearchRequest query;
- QVERIFY2(query.searchArea() == NULL, "Wrong default value");
- QGeoBoundingBox *box = new QGeoBoundingBox;
+ QVERIFY2(query.searchArea() == QGeoBoundingArea(), "Wrong default value");
+ QGeoBoundingBox box;
- box->setTopLeft(QGeoCoordinate(30,20));
- box->setBottomRight(QGeoCoordinate(10,50));
+ box.setTopLeft(QGeoCoordinate(30,20));
+ box.setBottomRight(QGeoCoordinate(10,50));
query.setSearchArea(box);
- QVERIFY(query.searchArea() != NULL);
- QVERIFY(query.searchArea()->type() == QGeoBoundingArea::BoxType);
+ QVERIFY(query.searchArea() != QGeoBoundingArea());
+ QVERIFY(query.searchArea().type() == QGeoBoundingArea::BoxType);
QVERIFY(query.searchArea() == box);
- QGeoBoundingBox *retrievedBox = static_cast<QGeoBoundingBox*>(query.searchArea());
- QVERIFY2(retrievedBox->topLeft() == QGeoCoordinate(30,20), "Wrong value returned");
- QVERIFY2(retrievedBox->bottomRight() == QGeoCoordinate(10,50), "Wrong value returned");
+ QGeoBoundingBox retrievedBox = query.searchArea();
+ QVERIFY2(retrievedBox.topLeft() == QGeoCoordinate(30,20), "Wrong value returned");
+ QVERIFY2(retrievedBox.bottomRight() == QGeoCoordinate(10,50), "Wrong value returned");
query.clear();
- QVERIFY2(query.searchArea() == NULL, "Wrong cleared value returned");
+ QVERIFY2(query.searchArea() == QGeoBoundingArea(), "Wrong cleared value returned");
}
void tst_QPlaceSearchRequest::searchAreaTest()
{
//test assignment of new search area over an old search area
QPlaceSearchRequest *query = new QPlaceSearchRequest;
- QGeoBoundingCircle *circle = new QGeoBoundingCircle;
- circle->setCenter(QGeoCoordinate(30,20));
- circle->setRadius(500.0);
+ QGeoBoundingCircle circle;
+ circle.setCenter(QGeoCoordinate(30,20));
+ circle.setRadius(500.0);
query->setSearchArea(circle);
QVERIFY(query->searchArea() == circle);
- QGeoBoundingBox *box = new QGeoBoundingBox;
- box->setTopLeft(QGeoCoordinate(30,20));
- box->setBottomRight(QGeoCoordinate(10,50));
+ QGeoBoundingBox box;
+ box.setTopLeft(QGeoCoordinate(30,20));
+ box.setBottomRight(QGeoCoordinate(10,50));
query->setSearchArea(box);
QVERIFY2(query->searchArea() == box, "New search area not assigned");
}
@@ -211,9 +211,9 @@ void tst_QPlaceSearchRequest::operatorsTest()
testObj2.setMaximumCorrections(0);
QVERIFY(testObj == testObj2);
- QGeoBoundingBox *b1 = new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
- QGeoBoundingBox *b2 = new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
- QGeoBoundingBox *b3 = new QGeoBoundingBox(QGeoCoordinate(40,40), QGeoCoordinate(10,40));
+ QGeoBoundingBox b1(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
+ QGeoBoundingBox b2(QGeoCoordinate(20,20), QGeoCoordinate(10,30));
+ QGeoBoundingBox b3(QGeoCoordinate(40,40), QGeoCoordinate(10,40));
//testing that identical boxes match
testObj.setSearchArea(b1);
@@ -224,9 +224,9 @@ void tst_QPlaceSearchRequest::operatorsTest()
testObj2.setSearchArea(b3);
QVERIFY2(testObj != testObj2, "Different box areas identified as matching");
- QGeoBoundingCircle *c1 = new QGeoBoundingCircle(QGeoCoordinate(5,5),500);
- QGeoBoundingCircle *c2 = new QGeoBoundingCircle(QGeoCoordinate(5,5),500);
- QGeoBoundingCircle *c3 = new QGeoBoundingCircle(QGeoCoordinate(9,9),600);
+ QGeoBoundingCircle c1(QGeoCoordinate(5,5),500);
+ QGeoBoundingCircle c2(QGeoCoordinate(5,5),500);
+ QGeoBoundingCircle c3(QGeoCoordinate(9,9),600);
//test that identical cirlces match
testObj.setSearchArea(c1);
@@ -238,8 +238,8 @@ void tst_QPlaceSearchRequest::operatorsTest()
QVERIFY2(testObj != testObj2, "Different circle areas identified as matching");
//test that circles and boxes do not match
- QGeoBoundingBox *b4 = new QGeoBoundingBox(QGeoCoordinate(20,20),QGeoCoordinate(10,30));
- QGeoBoundingCircle *c4 = new QGeoBoundingCircle(QGeoCoordinate(20,20),500);
+ QGeoBoundingBox b4(QGeoCoordinate(20,20),QGeoCoordinate(10,30));
+ QGeoBoundingCircle c4(QGeoCoordinate(20,20),500);
testObj.setSearchArea(b4);
testObj2.setSearchArea(c4);
QVERIFY2(testObj != testObj2, "Circle and box identified as matching");
@@ -260,7 +260,7 @@ void tst_QPlaceSearchRequest::clearTest()
{
QPlaceSearchRequest req;
req.setSearchTerm("pizza");
- req.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(1,1), 5000));
+ req.setSearchArea(QGeoBoundingCircle(QGeoCoordinate(1,1), 5000));
QPlaceCategory category;
category.setName("Fast Food");
req.setCategory(category);
@@ -270,7 +270,7 @@ void tst_QPlaceSearchRequest::clearTest()
req.clear();
QVERIFY(req.searchTerm().isEmpty());
- QVERIFY(req.searchArea() == 0);
+ QVERIFY(req.searchArea() == QGeoBoundingArea());
QVERIFY(req.categories().isEmpty());
QVERIFY(req.maximumCorrections() == 0);
QVERIFY(req.limit() == -1);