diff options
24 files changed, 276 insertions, 233 deletions
diff --git a/examples/declarative/qmlplaces/qmlplaces.qml b/examples/declarative/qmlplaces/qmlplaces.qml index 55fb83b3..3f502cee 100644 --- a/examples/declarative/qmlplaces/qmlplaces.qml +++ b/examples/declarative/qmlplaces/qmlplaces.qml @@ -6,12 +6,6 @@ Rectangle { width: 640 height: 360 - property Coordinate searchCoordinate: Coordinate { - // Brisbane - longitude: 153.02778 - latitude: -27.46778 - } - Text { id: queryText text: "Query:" @@ -202,7 +196,16 @@ Rectangle { SearchResultModel { id: resultModel - searchCenter: searchCoordinate + searchArea: BoundingCircle { + id: proximity + center: Coordinate { + id: searchCoordinate + // Brisbane + longitude: 153.02778 + latitude: -27.46778 + } + radius:5000 + } didYouMean: 5 //onQueryFinished: console.log("datareceived " + error) } @@ -227,7 +230,7 @@ Rectangle { TextPredictionModel { id: resultSuggestion - searchCenter: searchCoordinate + searchArea: proximity offset: 0 limit: 15 searchTerm: search_term.text @@ -235,7 +238,7 @@ Rectangle { RecommendationModel { id: recommendationModel - searchCenter: searchCoordinate + searchArea: proximity offset: 0 limit: 15 //onQueryFinished: console.log("datareceived " + error) diff --git a/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel.cpp index 3d865ae3..2fab992f 100644 --- a/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel.cpp @@ -31,11 +31,13 @@ QT_USE_NAMESPACE RecommenadationModel { id: searchModel - searchCenter: - GeoCoordinates { - latitude: 53 - longitude: 10 - } + searchArea: BoundingCircle { + center: Coordinate { + longitude: 53 + latitude: 100 + } + radius:5000 + } start: 0 limit: 15 } @@ -191,49 +193,24 @@ void QDeclarativeRecommendationModel::setPlaceId(const QString &placeId) } /*! - \qmlproperty GeoCoordinate RecommenadationModel::searchCenter - - This element holds search center. - - Note: this property's changed() signal is currently emitted only if the - whole element changes, not if only the contents of the element change. -*/ -QDeclarativeCoordinate *QDeclarativeRecommendationModel::searchCenter() -{ - return &m_center; -} - -void QDeclarativeRecommendationModel::setSearchCenter(QDeclarativeCoordinate *searchCenter) -{ - if (m_queryParameters.searchCenter() == searchCenter->coordinate()) { - return; - } - m_queryParameters.setSearchCenter(searchCenter->coordinate()); - m_center.setCoordinate(m_queryParameters.searchCenter()); - emit searchCenterChanged(); -} - -/*! - \qmlproperty GeoBoundingBox RecommenadationModel::boundingBox + \qmlproperty GeoCoordinate SearchResultModel::searchArea - This element holds bounding box of text prediction search. + This element holds the search area. Note: this property's changed() signal is currently emitted only if the whole element changes, not if only the contents of the element change. */ -QDeclarativeGeoBoundingBox *QDeclarativeRecommendationModel::boundingBox() +QDeclarativeGeoBoundingArea *QDeclarativeRecommendationModel::searchArea() const { - return &m_boundingBox; + return m_searchArea; } -void QDeclarativeRecommendationModel::setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox) +void QDeclarativeRecommendationModel::setSearchArea(QDeclarativeGeoBoundingArea *searchArea) { - if (m_queryParameters.boundingBox() == boundingBox->box()) { + if (m_searchArea == searchArea) return; - } - m_queryParameters.setBoundingBox(boundingBox->box()); - m_boundingBox.setBox(m_queryParameters.boundingBox()); - emit boundingBoxChanged(); + m_searchArea = searchArea; + emit searchAreaChanged(); } /*! @@ -288,13 +265,10 @@ void QDeclarativeRecommendationModel::executeQuery() m_manager = new QPlaceManager(this); } cancelPreviousRequest(); - beginResetModel(); - qDeleteAll(m_results); - m_results.clear(); - endResetModel(); - emit resultsChanged(); + QGeoPlace target; target.setPlaceId(m_queryParameters.searchTerm()); + m_queryParameters.setSearchArea(m_searchArea->area()); connectNewResponse(m_manager->recommendations(target, m_queryParameters)); } diff --git a/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel_p.h index 87152684..4485f5c8 100644 --- a/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativerecommendationmodel_p.h @@ -18,8 +18,7 @@ class QDeclarativeRecommendationModel : public QAbstractListModel Q_OBJECT Q_PROPERTY(QString placeId READ placeId WRITE setPlaceId NOTIFY placeIdChanged); - Q_PROPERTY(QDeclarativeCoordinate* searchCenter READ searchCenter WRITE setSearchCenter NOTIFY searchCenterChanged); - Q_PROPERTY(QDeclarativeGeoBoundingBox* boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged); + Q_PROPERTY(QDeclarativeGeoBoundingArea* searchArea READ searchArea WRITE setSearchArea NOTIFY searchAreaChanged); Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged); Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged); @@ -44,10 +43,8 @@ public: QString placeId() const; void setPlaceId(const QString &placeId); - QDeclarativeCoordinate *searchCenter(); - void setSearchCenter(QDeclarativeCoordinate *searchCenter); - QDeclarativeGeoBoundingBox *boundingBox(); - void setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox); + QDeclarativeGeoBoundingArea *searchArea() const; + void setSearchArea(QDeclarativeGeoBoundingArea *area); int offset() const; void setOffset(const int &offset); int limit() const; @@ -60,8 +57,7 @@ signals: void queryFinished(const int &error); void placeIdChanged(); - void searchCenterChanged(); - void boundingBoxChanged(); + void searchAreaChanged(); void offsetChanged(); void limitChanged(); void resultsChanged(); @@ -76,8 +72,7 @@ private: void convertResultsToDeclarative(); private: - QDeclarativeCoordinate m_center; - QDeclarativeGeoBoundingBox m_boundingBox; + QDeclarativeGeoBoundingArea *m_searchArea; QList<QDeclarativeSearchResult*> m_results; QPlaceSearchQuery m_queryParameters; diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index 0c427692..d383f720 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -31,11 +31,15 @@ QT_USE_NAMESPACE SearchResultModel { id: searchModel - searchCenter: - GeoCoordinates { - latitude: 53 - longitude: 10 - } + searchArea: BoundingCircle { + id: proximity + center: Coordinate { + longitude: 53 + latitude: 100 + } + radius:5000 + } + start: 0 limit: 15 } @@ -212,49 +216,24 @@ void QDeclarativeSearchResultModel::setSearchCategory(QDeclarativeCategory *sear } /*! - \qmlproperty GeoCoordinate SearchResultModel::searchCenter - - This element holds search center. - - Note: this property's changed() signal is currently emitted only if the - whole element changes, not if only the contents of the element change. -*/ -QDeclarativeCoordinate *QDeclarativeSearchResultModel::searchCenter() -{ - return &m_center; -} - -void QDeclarativeSearchResultModel::setSearchCenter(QDeclarativeCoordinate *searchCenter) -{ - if (m_queryParameters.searchCenter() == searchCenter->coordinate()) { - return; - } - m_queryParameters.setSearchCenter(searchCenter->coordinate()); - m_center.setCoordinate(m_queryParameters.searchCenter()); - emit searchCenterChanged(); -} - -/*! - \qmlproperty GeoBoundingBox SearchResultModel::boundingBox + \qmlproperty GeoCoordinate SearchResultModel::searchArea - This element holds bounding box of text prediction search. + This element holds the search area. Note: this property's changed() signal is currently emitted only if the whole element changes, not if only the contents of the element change. */ -QDeclarativeGeoBoundingBox *QDeclarativeSearchResultModel::boundingBox() +QDeclarativeGeoBoundingArea *QDeclarativeSearchResultModel::searchArea() const { - return &m_boundingBox; + return m_searchArea; } -void QDeclarativeSearchResultModel::setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox) +void QDeclarativeSearchResultModel::setSearchArea(QDeclarativeGeoBoundingArea *searchArea) { - if (m_queryParameters.boundingBox() == boundingBox->box()) { + if (m_searchArea == searchArea) return; - } - m_queryParameters.setBoundingBox(boundingBox->box()); - m_boundingBox.setBox(m_queryParameters.boundingBox()); - emit boundingBoxChanged(); + m_searchArea = searchArea; + emit searchAreaChanged(); } /*! @@ -328,6 +307,7 @@ void QDeclarativeSearchResultModel::executeQuery() m_manager = new QPlaceManager(this); } cancelPreviousRequest(); + m_queryParameters.setSearchArea(m_searchArea->area()); connectNewResponse(m_manager->searchForPlaces(m_queryParameters, QPlaceManager::PublicScope)); } diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h index 4b017c83..931f69c5 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h @@ -7,8 +7,7 @@ #include <qplacemanager.h> -#include "qdeclarativecoordinate_p.h" -#include "qdeclarativegeoboundingbox_p.h" +#include "qdeclarativegeoboundingarea_p.h" #include "qdeclarativesearchresult_p.h" QT_BEGIN_NAMESPACE @@ -19,13 +18,13 @@ class QDeclarativeSearchResultModel : public QAbstractListModel Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged); Q_PROPERTY(QDeclarativeCategory* searchCategory READ searchCategory WRITE setSearchCategory NOTIFY searchCategoryChanged); - Q_PROPERTY(QDeclarativeCoordinate* searchCenter READ searchCenter WRITE setSearchCenter NOTIFY searchCenterChanged); - Q_PROPERTY(QDeclarativeGeoBoundingBox* boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged); + Q_PROPERTY(QDeclarativeGeoBoundingArea *searchArea READ searchArea WRITE setSearchArea NOTIFY searchAreaChanged); Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged); Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged); Q_PROPERTY(int didYouMean READ didYouMean WRITE setDidYouMean NOTIFY didYouMeanChanged); Q_PROPERTY(QDeclarativeListProperty<QDeclarativeSearchResult> results READ results NOTIFY resultsChanged) + public: explicit QDeclarativeSearchResultModel(QObject *parent = 0); ~QDeclarativeSearchResultModel(); @@ -48,10 +47,8 @@ public: void setSearchTerm(const QString &searchTerm); QDeclarativeCategory *searchCategory(); void setSearchCategory(QDeclarativeCategory *searchCategory); - QDeclarativeCoordinate *searchCenter(); - void setSearchCenter(QDeclarativeCoordinate *searchCenter); - QDeclarativeGeoBoundingBox *boundingBox(); - void setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox); + QDeclarativeGeoBoundingArea *searchArea() const; + void setSearchArea(QDeclarativeGeoBoundingArea *searchArea); int offset() const; void setOffset(const int &offset); int limit() const; @@ -70,8 +67,7 @@ signals: void searchTermChanged(); void searchCategoryChanged(); - void searchCenterChanged(); - void boundingBoxChanged(); + void searchAreaChanged(); void offsetChanged(); void limitChanged(); void didYouMeanChanged(); @@ -88,7 +84,7 @@ private: private: QDeclarativeCoordinate m_center; - QDeclarativeGeoBoundingBox m_boundingBox; + QDeclarativeGeoBoundingArea *m_searchArea; QDeclarativeCategory m_category; QList<QDeclarativeSearchResult*> m_results; diff --git a/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel.cpp index 60909134..56056616 100644 --- a/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel.cpp @@ -28,11 +28,13 @@ QT_USE_NAMESPACE TextPredictionModel { id: textPredictionModel - searchCenter: - GeoCoordinates { - latitude: 53 - longitude: 10 - } + searchArea: BoundingCircle { + center: Coordinate { + longitude: 53 + latitude: 100 + } + radius:5000 + } start: 0 limit: 15 } @@ -137,49 +139,24 @@ void QDeclarativeTextPredictionModel::setSearchTerm(const QString &searchTerm) } /*! - \qmlproperty GeoCoordinate TextPredictionModel::searchCenter - - This element holds search center. - - Note: this property's changed() signal is currently emitted only if the - whole element changes, not if only the contents of the element change. -*/ -QDeclarativeCoordinate *QDeclarativeTextPredictionModel::searchCenter() -{ - return &m_center; -} - -void QDeclarativeTextPredictionModel::setSearchCenter(QDeclarativeCoordinate *searchCenter) -{ - if (m_queryParameters.searchCenter() == searchCenter->coordinate()) { - return; - } - m_queryParameters.setSearchCenter(searchCenter->coordinate()); - m_center.setCoordinate(m_queryParameters.searchCenter()); - emit searchCenterChanged(); -} - -/*! - \qmlproperty GeoBoundingBox TextPredictionModel::boundingBox + \qmlproperty GeoCoordinate TextPredictionModel::searchArea - This element holds bounding box of text prediction search. + This element holds the search area. Note: this property's changed() signal is currently emitted only if the whole element changes, not if only the contents of the element change. */ -QDeclarativeGeoBoundingBox *QDeclarativeTextPredictionModel::boundingBox() +QDeclarativeGeoBoundingArea *QDeclarativeTextPredictionModel::searchArea() const { - return &m_boundingBox; + return m_searchArea; } -void QDeclarativeTextPredictionModel::setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox) +void QDeclarativeTextPredictionModel::setSearchArea(QDeclarativeGeoBoundingArea *searchArea) { - if (m_queryParameters.boundingBox() == boundingBox->box()) { + if (m_searchArea == searchArea) return; - } - m_queryParameters.setBoundingBox(boundingBox->box()); - m_boundingBox.setBox(m_queryParameters.boundingBox()); - emit boundingBoxChanged(); + m_searchArea = searchArea; + emit searchAreaChanged(); } /*! @@ -237,9 +214,7 @@ void QDeclarativeTextPredictionModel::executeQuery() m_manager = new QPlaceManager(this); } cancelPreviousRequest(); - // empty old data - beginResetModel(); - endResetModel(); + m_queryParameters.setSearchArea(m_searchArea->area()); connectNewResponse(m_manager->textPredictions(m_queryParameters)); } diff --git a/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel_p.h index d522748f..4d9e9bef 100644 --- a/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativetextpredictionmodel_p.h @@ -18,8 +18,7 @@ class QDeclarativeTextPredictionModel : public QAbstractListModel Q_OBJECT Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged); - Q_PROPERTY(QDeclarativeCoordinate* searchCenter READ searchCenter WRITE setSearchCenter NOTIFY searchCenterChanged); - Q_PROPERTY(QDeclarativeGeoBoundingBox* boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged); + Q_PROPERTY(QDeclarativeGeoBoundingArea* searchArea READ searchArea WRITE setSearchArea NOTIFY searchAreaChanged); Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged); Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged); @@ -39,10 +38,8 @@ public: QString searchTerm() const; void setSearchTerm(const QString &searchTerm); - QDeclarativeCoordinate *searchCenter(); - void setSearchCenter(QDeclarativeCoordinate *searchCenter); - QDeclarativeGeoBoundingBox *boundingBox(); - void setBoundingBox(QDeclarativeGeoBoundingBox *boundingBox); + QDeclarativeGeoBoundingArea *searchArea() const; + void setSearchArea(QDeclarativeGeoBoundingArea *area); int offset() const; void setOffset(const int &offset); int limit() const; @@ -57,8 +54,7 @@ signals: void queryFinished(const int &error); void searchTermChanged(); - void searchCenterChanged(); - void boundingBoxChanged(); + void searchAreaChanged(); void offsetChanged(); void limitChanged(); void predictionsChanged(); @@ -73,9 +69,7 @@ private: void connectNewResponse(QPlaceTextPredictionReply *newResponse); private: - QDeclarativeCoordinate m_center; - QDeclarativeGeoBoundingBox m_boundingBox; - + QDeclarativeGeoBoundingArea *m_searchArea; QPlaceSearchQuery m_queryParameters; QPlaceManager *m_manager; diff --git a/src/imports/location/qdeclarativegeoboundingarea_p.h b/src/imports/location/qdeclarativegeoboundingarea_p.h index 824c90d1..f189a3f3 100644 --- a/src/imports/location/qdeclarativegeoboundingarea_p.h +++ b/src/imports/location/qdeclarativegeoboundingarea_p.h @@ -56,6 +56,7 @@ class QDeclarativeGeoBoundingArea : public QObject public: QDeclarativeGeoBoundingArea(QObject *parent) :QObject(parent){} + virtual QGeoBoundingArea *area() const = 0; }; QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoboundingbox.cpp b/src/imports/location/qdeclarativegeoboundingbox.cpp index dba963a0..b104b34e 100644 --- a/src/imports/location/qdeclarativegeoboundingbox.cpp +++ b/src/imports/location/qdeclarativegeoboundingbox.cpp @@ -85,6 +85,11 @@ QGeoBoundingBox QDeclarativeGeoBoundingBox::box() return m_box; } +QGeoBoundingArea *QDeclarativeGeoBoundingBox::area() const +{ + return m_box.clone(); +} + QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::bottomLeft() { return &m_declarativeBottomLeft; diff --git a/src/imports/location/qdeclarativegeoboundingbox_p.h b/src/imports/location/qdeclarativegeoboundingbox_p.h index 49de789b..9c4c81db 100644 --- a/src/imports/location/qdeclarativegeoboundingbox_p.h +++ b/src/imports/location/qdeclarativegeoboundingbox_p.h @@ -67,6 +67,7 @@ public: QDeclarativeGeoBoundingBox(const QGeoBoundingBox& box, QObject* parent = 0); void setBox(const QGeoBoundingBox& box); QGeoBoundingBox box(); + virtual 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 a12e9d42..5a8e4e11 100644 --- a/src/imports/location/qdeclarativegeoboundingcircle.cpp +++ b/src/imports/location/qdeclarativegeoboundingcircle.cpp @@ -70,6 +70,11 @@ QGeoBoundingCircle QDeclarativeGeoBoundingCircle::circle() return circle_; } +QGeoBoundingArea *QDeclarativeGeoBoundingCircle::area() const +{ + return circle_.clone(); +} + Q_INVOKABLE bool QDeclarativeGeoBoundingCircle::contains(QDeclarativeCoordinate* coordinate) { if (!coordinate) diff --git a/src/imports/location/qdeclarativegeoboundingcircle_p.h b/src/imports/location/qdeclarativegeoboundingcircle_p.h index 44f9db0e..d8c2137a 100644 --- a/src/imports/location/qdeclarativegeoboundingcircle_p.h +++ b/src/imports/location/qdeclarativegeoboundingcircle_p.h @@ -63,6 +63,7 @@ public: QDeclarativeGeoBoundingCircle(const QGeoBoundingCircle& circle, QObject* parent = 0); void setCircle(const QGeoBoundingCircle& circle); QGeoBoundingCircle circle(); + virtual QGeoBoundingArea *area() const; Q_INVOKABLE bool contains(QDeclarativeCoordinate* coordinate); QDeclarativeCoordinate* center(); diff --git a/src/location/places/qplacesearchquery.cpp b/src/location/places/qplacesearchquery.cpp index bf79ebdc..a748aba4 100644 --- a/src/location/places/qplacesearchquery.cpp +++ b/src/location/places/qplacesearchquery.cpp @@ -56,8 +56,7 @@ public: QString searchTerm; QList<QPlaceCategory> categories; - QGeoCoordinate searchCenter; - QGeoBoundingBox boundingBox; + QGeoBoundingArea *searchArea; int dymNumber; }; @@ -67,7 +66,8 @@ QT_USE_NAMESPACE QPlaceSearchQueryPrivate::QPlaceSearchQueryPrivate() : QSharedData(), - dymNumber(0) + dymNumber(0), + searchArea(0) { } @@ -76,13 +76,14 @@ QPlaceSearchQueryPrivate::QPlaceSearchQueryPrivate(const QPlaceSearchQueryPrivat { this->searchTerm = other.searchTerm; this->categories = other.categories; - this->searchCenter = other.searchCenter; - this->boundingBox = other.boundingBox; + this->searchArea = other.searchArea; this->dymNumber = other.dymNumber; } QPlaceSearchQueryPrivate::~QPlaceSearchQueryPrivate() { + delete searchArea; + searchArea = 0; } bool QPlaceSearchQueryPrivate::operator==(const QPlaceSearchQueryPrivate &other) const @@ -90,8 +91,7 @@ bool QPlaceSearchQueryPrivate::operator==(const QPlaceSearchQueryPrivate &other) return ( this->searchTerm == other.searchTerm && this->categories == other.categories - && this->searchCenter == other.searchCenter - && this->boundingBox == other.boundingBox + && this->searchArea == other.searchArea && this->dymNumber == other.dymNumber ); } @@ -196,35 +196,24 @@ void QPlaceSearchQuery::setCategory(const QPlaceCategory &category) } /*! - Returns search center. + Returns search area. The default search area is a null pointer. */ -QGeoCoordinate QPlaceSearchQuery::searchCenter() const +QGeoBoundingArea *QPlaceSearchQuery::searchArea() const { - return d->searchCenter; + return d->searchArea; } /*! - Sets the search query to search with search \a center. + Sets the search query to search within the given \a area. Ownership of the is + transferred to the place query who is responsible for pointer deletion. If a new \a area + is being assigned, the old area is deleted. */ -void QPlaceSearchQuery::setSearchCenter(const QGeoCoordinate ¢er) +void QPlaceSearchQuery::setSearchArea(QGeoBoundingArea *area) { - d->searchCenter = center; -} + if (d->searchArea != area) + delete d->searchArea; -/*! - Returns search bounding box. -*/ -QGeoBoundingBox QPlaceSearchQuery::boundingBox() const -{ - return d->boundingBox; -} - -/*! - Sets the search query to search with bounding box. -*/ -void QPlaceSearchQuery::setBoundingBox(const QGeoBoundingBox &boundingBox) -{ - d->boundingBox = boundingBox; + d->searchArea = area; } /*! @@ -251,7 +240,6 @@ void QPlaceSearchQuery::clear() QPlaceQuery::clear(); d->searchTerm.clear(); d->categories.clear(); - d->boundingBox = QGeoBoundingBox(); - d->searchCenter = QGeoCoordinate(); + d->searchArea = 0; d->dymNumber = 0; } diff --git a/src/location/places/qplacesearchquery.h b/src/location/places/qplacesearchquery.h index 4a8c5c81..8d0f0328 100644 --- a/src/location/places/qplacesearchquery.h +++ b/src/location/places/qplacesearchquery.h @@ -43,7 +43,7 @@ #define QPLACESEARCHQUERY_H #include <QSharedDataPointer> -#include "qgeoboundingbox.h" +#include "qgeoboundingarea.h" #include "qmobilityglobal.h" #include "qplacecategory.h" #include "qplacequery.h" @@ -81,11 +81,8 @@ public: QList<QPlaceCategory> categories() const; void setCategory(const QPlaceCategory &category); - QGeoCoordinate searchCenter() const; - void setSearchCenter(const QGeoCoordinate ¢er); - - QGeoBoundingBox boundingBox() const; - void setBoundingBox(const QGeoBoundingBox &boundingBox); + QGeoBoundingArea *searchArea() const; + void setSearchArea(QGeoBoundingArea *area); int didYouMeanSuggestionNumber() const; void setDidYouMeanSuggestionNumber(const int &number); diff --git a/src/location/qgeoboundingarea.cpp b/src/location/qgeoboundingarea.cpp index 252f1095..dd186c47 100644 --- a/src/location/qgeoboundingarea.cpp +++ b/src/location/qgeoboundingarea.cpp @@ -110,4 +110,10 @@ area. \since 1.1 */ +/*! +\fn QGeoBoundingArea* QGeoBoundingArea::clone() const + +Creates a new QGeoBoundingArea that is a deep copy of this bounding area. +*/ + QT_END_NAMESPACE diff --git a/src/location/qgeoboundingarea.h b/src/location/qgeoboundingarea.h index 9812359b..90fdd6a1 100644 --- a/src/location/qgeoboundingarea.h +++ b/src/location/qgeoboundingarea.h @@ -66,6 +66,7 @@ public: virtual bool isValid() const = 0; virtual bool isEmpty() const = 0; virtual bool contains(const QGeoCoordinate &coordinate) const = 0; + virtual QGeoBoundingArea *clone() const = 0; }; QT_END_NAMESPACE diff --git a/src/location/qgeoboundingbox.cpp b/src/location/qgeoboundingbox.cpp index 637a0bf8..059b78e2 100644 --- a/src/location/qgeoboundingbox.cpp +++ b/src/location/qgeoboundingbox.cpp @@ -829,6 +829,14 @@ QGeoBoundingBox& QGeoBoundingBox::operator |= (const QGeoBoundingBox & boundingB return *this; } +/*! + Returns a pointer to a deep copy of this bounding box. +*/ +QGeoBoundingArea *QGeoBoundingBox::clone() const +{ + return new QGeoBoundingBox(*this); +} + /******************************************************************************* *******************************************************************************/ diff --git a/src/location/qgeoboundingbox.h b/src/location/qgeoboundingbox.h index fc1547df..14896574 100644 --- a/src/location/qgeoboundingbox.h +++ b/src/location/qgeoboundingbox.h @@ -105,6 +105,8 @@ public: QGeoBoundingBox operator | (const QGeoBoundingBox &boundingBox) const; QGeoBoundingBox& operator |= (const QGeoBoundingBox &boundingBox); + QGeoBoundingArea *clone() const; + private: QSharedDataPointer<QGeoBoundingBoxPrivate> d_ptr; }; diff --git a/src/location/qgeoboundingcircle.cpp b/src/location/qgeoboundingcircle.cpp index ec5d158c..ffe12a04 100644 --- a/src/location/qgeoboundingcircle.cpp +++ b/src/location/qgeoboundingcircle.cpp @@ -273,6 +273,14 @@ 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); +} + /******************************************************************************* *******************************************************************************/ diff --git a/src/location/qgeoboundingcircle.h b/src/location/qgeoboundingcircle.h index 4eb57151..c62a5978 100644 --- a/src/location/qgeoboundingcircle.h +++ b/src/location/qgeoboundingcircle.h @@ -82,6 +82,8 @@ public: void translate(double degreesLatitude, double degreesLongitude); QGeoBoundingCircle translated(double degreesLatitude, double degreesLongitude) const; + + QGeoBoundingArea *clone() const; private: QSharedDataPointer<QGeoBoundingCirclePrivate> d_ptr; }; diff --git a/src/plugins/places/nokia/qplacerestmanager.cpp b/src/plugins/places/nokia/qplacerestmanager.cpp index 085aa723..d0d4e997 100644 --- a/src/plugins/places/nokia/qplacerestmanager.cpp +++ b/src/plugins/places/nokia/qplacerestmanager.cpp @@ -52,6 +52,8 @@ #include <QHash> #include <qplacesearchquery.h> +#include <qgeoboundingcircle.h> +#include <qgeoboundingbox.h> #include "qplacerestreply.h" #if defined(QT_PLACES_LOGGING) @@ -259,17 +261,18 @@ QString QPlaceRestManager::prepareSearchRequest(const QPlaceSearchQuery &query) searchString += const_views; searchString += const_deviceproductid; // process search center - QGeoCoordinate searchCentre = query.searchCenter(); - if (searchCentre.isValid()) { - searchString += const_lat + QString::number(searchCentre.latitude()); - searchString += const_lon + QString::number(searchCentre.longitude()); - } - // process view port - if (query.boundingBox().isValid()) { - searchString += const_top + QString::number(query.boundingBox().topLeft().latitude()); - searchString += const_left + QString::number(query.boundingBox().topLeft().longitude()); - searchString += const_bottom + QString::number(query.boundingBox().bottomRight().latitude()); - searchString += const_right + QString::number(query.boundingBox().bottomRight().longitude()); + 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()); + } } // processing limit diff --git a/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp b/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp index 7ebec8ac..f0e1736f 100644 --- a/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp +++ b/tests/auto/qgeoboundingbox/tst_qgeoboundingbox.cpp @@ -95,6 +95,8 @@ private slots: void unite(); void unite_data(); + + void clone(); }; void tst_QGeoBoundingBox::default_constructor() @@ -2121,6 +2123,37 @@ void tst_QGeoBoundingBox::unite_data() QGeoCoordinate(-30.0, 180.0)); } +void tst_QGeoBoundingBox::clone() +{ + //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_MAIN(tst_QGeoBoundingBox) #include "tst_qgeoboundingbox.moc" diff --git a/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp b/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp index 5ff960b2..4224ddd6 100644 --- a/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp +++ b/tests/auto/qgeoboundingcircle/tst_qgeoboundingcircle.cpp @@ -72,6 +72,8 @@ private slots: void contains_data(); void contains(); + + void clone(); }; void tst_QGeoBoundingCircle::defaultConstructor() @@ -246,5 +248,35 @@ void tst_QGeoBoundingCircle::contains() QCOMPARE(c.contains(probe), result); } +void tst_QGeoBoundingCircle::clone() +{ + //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"); + QVERIFY2(originalCircle.radius() == 99.9, + "Radius of original has not changed"); + + QVERIFY2(clonedCirclePtr->center() == QGeoCoordinate(1,1), + "Center of clone references center of original"); + QVERIFY2(clonedCirclePtr->radius() == 500.0, + "Radius of clone references radius of original"); +} + QTEST_MAIN(tst_QGeoBoundingCircle) #include "tst_qgeoboundingcircle.moc" diff --git a/tests/auto/qplacesearchquery/tst_qplacesearchquery.cpp b/tests/auto/qplacesearchquery/tst_qplacesearchquery.cpp index 50e8fe81..929c39a4 100644 --- a/tests/auto/qplacesearchquery/tst_qplacesearchquery.cpp +++ b/tests/auto/qplacesearchquery/tst_qplacesearchquery.cpp @@ -2,6 +2,8 @@ #include <QtTest/QtTest> #include <qplacesearchquery.h> +#include <qgeoboundingcircle.h> +#include <qgeoboundingbox.h> QT_USE_NAMESPACE @@ -16,8 +18,9 @@ private Q_SLOTS: void constructorTest(); void searchTermTest(); void categoriesTest(); - void searchCenterTest(); + void boundingCircleTest(); void boundingBoxTest(); + void searchAreaTest(); void didYouMeanSuggestionNumberTest(); void operatorsTest(); }; @@ -56,33 +59,63 @@ void tst_QPlaceSearchQuery::categoriesTest() QVERIFY2(testObj.categories()[0] == cat, "Wrong category returned"); } -void tst_QPlaceSearchQuery::searchCenterTest() +void tst_QPlaceSearchQuery::boundingCircleTest() { - QPlaceSearchQuery testObj; - QVERIFY2(testObj.searchCenter().isValid() == false, "Wrong default value"); - QGeoCoordinate coordinate; - coordinate.setLatitude(30); - coordinate.setLongitude(20); - testObj.setSearchCenter(coordinate); - QVERIFY2(testObj.searchCenter() == coordinate, "Wrong value returned"); - testObj.clear(); - QVERIFY2(testObj.searchCenter().isValid() == false, "Wrong cleared value returned"); + QPlaceSearchQuery query; + QVERIFY2(query.searchArea() == NULL, "Wrong default value"); + QGeoBoundingCircle *circle = new QGeoBoundingCircle; + 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() == 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"); + query.clear(); + QVERIFY2(query.searchArea() == NULL, "Search area not cleared"); } void tst_QPlaceSearchQuery::boundingBoxTest() { - QPlaceSearchQuery testObj; - QVERIFY2(testObj.boundingBox().isValid() == false, "Wrong default value"); - QGeoCoordinate coordinate; - coordinate.setLatitude(30); - coordinate.setLongitude(20); - QGeoBoundingBox box; - box.setTopLeft(coordinate); - box.setBottomRight(coordinate); - testObj.setBoundingBox(box); - QVERIFY2(testObj.boundingBox() == box, "Wrong value returned"); - testObj.clear(); - QVERIFY2(testObj.boundingBox().isValid() == false, "Wrong cleared value returned"); + QPlaceSearchQuery query; + QVERIFY2(query.searchArea() == NULL, "Wrong default value"); + QGeoBoundingBox *box = new QGeoBoundingBox; + + 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() == 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"); + + query.clear(); + QVERIFY2(query.searchArea() == NULL, "Wrong cleared value returned"); +} + +void tst_QPlaceSearchQuery::searchAreaTest() +{ + //test assignment of new search area over an old search area + QPlaceSearchQuery *query = new QPlaceSearchQuery; + QGeoBoundingCircle *circle = new QGeoBoundingCircle; + 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)); + query->setSearchArea(box); + QVERIFY2(query->searchArea() == box, "New search area not assigned"); } void tst_QPlaceSearchQuery::didYouMeanSuggestionNumberTest() |