diff options
21 files changed, 818 insertions, 115 deletions
diff --git a/examples/declarative/places/content/places/SearchResultDelegate.qml b/examples/declarative/places/content/places/SearchResultDelegate.qml index 11f6f909..76b64e83 100644 --- a/examples/declarative/places/content/places/SearchResultDelegate.qml +++ b/examples/declarative/places/content/places/SearchResultDelegate.qml @@ -65,31 +65,37 @@ Item { anchors.fill: parent color: "#dbffde" visible: model.sponsored !== undefined ? model.sponsored : false - } - - Column { - width: parent.width - - Row { - Image { - visible: (place.favorite != null) - source: "../../resources/star.png" - height: placeName.height - fillMode: Image.PreserveAspectFit - } - Text { id: placeName; text: place.favorite ? place.favorite.name : place.name } - } - Text { id: distanceText; text: PlacesUtils.prettyDistance(distance); font.italic: true } Text { text: qsTr("Sponsored result") horizontalAlignment: Text.AlignRight + anchors.right: parent.right + anchors.bottom: parent.bottom font.pixelSize: 8 - width: parent.width visible: model.sponsored !== undefined ? model.sponsored : false } } + Row { + Image { + source: place.favorite ? "../../resources/star.png" : place.icon.url() + } + + Column { + anchors.verticalCenter: parent.verticalCenter + Text { + id: placeName + text: place.favorite ? place.favorite.name : place.name + } + + Text { + id: distanceText + font.italic: true + text: PlacesUtils.prettyDistance(distance) + } + } + } + MouseArea { anchors.fill: parent @@ -124,6 +130,49 @@ Item { } //! [PlaceSearchModel place delegate] + Component { + id: proposedSearchComponent + + Item { + id: proposedSearchRoot + + height: childrenRect.height + width: parent.width + + Row { + Image { + source: icon.url() + } + + Text { + id: proposedSearchTitle + anchors.verticalCenter: parent.verticalCenter + text: "Search for " + title + } + } + + MouseArea { + anchors.fill: parent + + onPressed: proposedSearchRoot.state = "Pressed" + onReleased: proposedSearchRoot.state = "" + onCanceled: proposedSearchRoot.state = "" + + onClicked: root.ListView.view.model.updateWith(index); + } + + states: [ + State { + name: "" + }, + State { + name: "Pressed" + PropertyChanges { target: proposedSearchTitle; color: "#1C94FC"} + } + ] + } + } + Loader { anchors.left: parent.left anchors.right: parent.right @@ -132,6 +181,8 @@ Item { switch (model.type) { case PlaceSearchModel.PlaceResult: return placeComponent; + case PlaceSearchModel.ProposedSearchResult: + return proposedSearchComponent; default: //do nothing, don't assign component if result type not recognized } diff --git a/examples/declarative/places/places.qml b/examples/declarative/places/places.qml index 1fce1654..2df5b538 100644 --- a/examples/declarative/places/places.qml +++ b/examples/declarative/places/places.qml @@ -519,7 +519,9 @@ Item { MapItemView { model: placeSearchModel delegate: MapQuickItem { - coordinate: place.location.coordinate + coordinate: model.type === PlaceSearchModel.PlaceResult ? place.location.coordinate : QtLocation.coordinate() + + visible: model.type === PlaceSearchModel.PlaceResult anchorPoint.x: image.width * 0.28 anchorPoint.y: image.height diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index 28ed5b32..9a44dac1 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -51,6 +51,7 @@ #include <QtLocation/QPlaceMatchRequest> #include <QtLocation/QPlaceMatchReply> #include <QtLocation/QPlaceResult> +#include <QtLocation/QProposedSearchResult> QT_USE_NAMESPACE @@ -116,11 +117,14 @@ QT_USE_NAMESPACE \table \row + \li PlaceSearchModel.UnknownSearchResult + \li The contents of the search result are unknown. + \row \li PlaceSearchModel.PlaceResult \li The search result contains a place. \row - \li PlaceSearchModel.UnknownSearchResult - \li The contents of the search result are unknown. + \li PlaceSearchModel.ProposedSearchResult + \li The search result contains a proposed search which may be relevant. \endtable @@ -343,6 +347,8 @@ QString QDeclarativeSearchResultModel::searchTerm() const void QDeclarativeSearchResultModel::setSearchTerm(const QString &searchTerm) { + m_request.setSearchContext(QVariant()); + if (m_request.searchTerm() == searchTerm) return; @@ -371,6 +377,7 @@ void QDeclarativeSearchResultModel::categories_append(QQmlListProperty<QDeclarat { QDeclarativeSearchResultModel *searchModel = qobject_cast<QDeclarativeSearchResultModel *>(list->object); if (searchModel && declCategory) { + searchModel->m_request.setSearchContext(QVariant()); searchModel->m_categories.append(declCategory); QList<QPlaceCategory> categories = searchModel->m_request.categories(); categories.append(declCategory->category()); @@ -404,6 +411,7 @@ void QDeclarativeSearchResultModel::categories_clear(QQmlListProperty<QDeclarati if (searchModel) { //note: we do not need to delete each of the objects in m_categories since the search model //should never be the parent of the categories anyway. + searchModel->m_request.setSearchContext(QVariant()); searchModel->m_categories.clear(); searchModel->m_request.setCategories(QList<QPlaceCategory>()); emit searchModel->categoriesChanged(); @@ -642,6 +650,26 @@ QHash<int, QByteArray> QDeclarativeSearchResultModel::roleNames() const return roles; } +/*! + \qmlmethod PlaceSearchModel::updateWith(int proposedSearchIndex) + + Updates the model based on the ProposedSearchResult at index \a proposedSearchIndex. The model + will be populated with a list of places matching the proposed search. Model status will be set + to PlaceSearchModel.Loading. If the model is updated successfully status will be set to + PlaceSearchModel.Ready. If an error occurs status will be set to PlaceSearchModel.Error and the + model cleared. + + If \a proposedSearchIndex does not reference a ProposedSearchResult this method does nothing. +*/ +void QDeclarativeSearchResultModel::updateWith(int proposedSearchIndex) +{ + if (m_results.at(proposedSearchIndex).type() != QPlaceSearchResult::ProposedSearchResult) + return; + + m_request = QProposedSearchResult(m_results.at(proposedSearchIndex)).searchRequest(); + update(); +} + QPlaceReply *QDeclarativeSearchResultModel::sendQuery(QPlaceManager *manager, const QPlaceSearchRequest &request) { @@ -785,19 +813,24 @@ void QDeclarativeSearchResultModel::updateLayout(const QList<QPlace> &favoritePl m_resultsBuffer.clear(); for (int i = 0; i < m_results.count(); ++i) { - if (m_results.at(i).type() == QPlaceSearchResult::PlaceResult) { - QPlaceResult placeResult = m_results.at(i); - QDeclarativePlace *place = new QDeclarativePlace(placeResult.place(),plugin(), this); - m_places.append(place); + const QPlaceSearchResult &result = m_results.at(i); - QDeclarativePlaceIcon *icon = 0; - if (!m_results.at(i).icon().isEmpty()) - icon = new QDeclarativePlaceIcon(m_results.at(i).icon(), plugin(), this); - m_icons.append(icon); + if (result.type() == QPlaceSearchResult::PlaceResult) { + QPlaceResult placeResult = result; + QDeclarativePlace *place = new QDeclarativePlace(placeResult.place(), plugin(), this); + m_places.append(place); if ((favoritePlaces.count() == m_results.count()) && favoritePlaces.at(i) != QPlace()) - m_places[i]->setFavorite(new QDeclarativePlace(favoritePlaces.at(i), m_favoritesPlugin, m_places[i])); + m_places[i]->setFavorite(new QDeclarativePlace(favoritePlaces.at(i), + m_favoritesPlugin, m_places[i])); + } else if (result.type() == QPlaceSearchResult::ProposedSearchResult) { + m_places.append(0); } + + QDeclarativePlaceIcon *icon = 0; + if (!result.icon().isEmpty()) + icon = new QDeclarativePlaceIcon(result.icon(), plugin(), this); + m_icons.append(icon); } endResetModel(); diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h index 56775901..efa41291 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h @@ -70,7 +70,8 @@ class QDeclarativeSearchResultModel : public QDeclarativeSearchModelBase public: enum SearchResultType { UnknownSearchResult = QPlaceSearchResult::UnknownSearchResult, - PlaceResult = QPlaceSearchResult::PlaceResult + PlaceResult = QPlaceSearchResult::PlaceResult, + ProposedSearchResult = QPlaceSearchResult::ProposedSearchResult }; enum RelevanceHint { @@ -114,6 +115,10 @@ public: Q_INVOKABLE QVariant data(int index, const QString &roleName) const; QHash<int, QByteArray> roleNames() const; + Q_INVOKABLE void updateWith(int proposedSearchIndex); + + void updateSearchRequest(); + Q_SIGNALS: void searchTermChanged(); void categoriesChanged(); diff --git a/src/location/places/places.pri b/src/location/places/places.pri index dc7e1af6..4c3a0667 100644 --- a/src/location/places/places.pri +++ b/src/location/places/places.pri @@ -19,6 +19,7 @@ PUBLIC_HEADERS += \ #result places/qplacesearchresult.h \ places/qplaceresult.h \ + places/qproposedsearchresult.h \ #request classes places/qplacecontentrequest.h \ places/qplacematchrequest.h \ @@ -46,6 +47,7 @@ PRIVATE_HEADERS += \ places/qplaceimage_p.h \ places/qplaceratings_p.h \ places/qplaceresult_p.h \ + places/qproposedsearchresult_p.h \ places/qplacereview_p.h \ places/qplacesupplier_p.h \ places/qplacesearchresult_p.h \ @@ -74,6 +76,7 @@ SOURCES += \ #result places/qplacesearchresult.cpp \ places/qplaceresult.cpp \ + places/qproposedsearchresult.cpp \ #request classes places/qplacecontentrequest.cpp \ places/qplacematchrequest.cpp \ diff --git a/src/location/places/qplaceresult_p.h b/src/location/places/qplaceresult_p.h index 01442d90..f6a21460 100644 --- a/src/location/places/qplaceresult_p.h +++ b/src/location/places/qplaceresult_p.h @@ -54,7 +54,7 @@ public: ~QPlaceResultPrivate(); - bool compare(const QPlaceSearchResultPrivate *other) const; + bool compare(const QPlaceSearchResultPrivate *other) const Q_DECL_OVERRIDE; Q_DEFINE_SEARCHRESULT_PRIVATE_HELPER(QPlaceResult, QPlaceSearchResult::PlaceResult) diff --git a/src/location/places/qplacesearchrequest.cpp b/src/location/places/qplacesearchrequest.cpp index 4af49102..c5878b22 100644 --- a/src/location/places/qplacesearchrequest.cpp +++ b/src/location/places/qplacesearchrequest.cpp @@ -45,6 +45,7 @@ #include <QtCore/QSharedData> #include <QtCore/QList> +#include <QtCore/QVariant> QT_BEGIN_NAMESPACE @@ -68,6 +69,7 @@ public: QPlaceSearchRequest::RelevanceHint relevanceHint; int limit; int offset; + QVariant searchContext; }; QPlaceSearchRequestPrivate::QPlaceSearchRequestPrivate() @@ -87,7 +89,8 @@ QPlaceSearchRequestPrivate::QPlaceSearchRequestPrivate(const QPlaceSearchRequest visibilityScope(other.visibilityScope), relevanceHint(other.relevanceHint), limit(other.limit), - offset(other.offset) + offset(other.offset), + searchContext(other.searchContext) { } @@ -106,6 +109,7 @@ QPlaceSearchRequestPrivate &QPlaceSearchRequestPrivate::operator=(const QPlaceSe relevanceHint = other.relevanceHint; limit = other.limit; offset = other.offset; + searchContext = other.searchContext; } return *this; @@ -120,7 +124,8 @@ bool QPlaceSearchRequestPrivate::operator==(const QPlaceSearchRequestPrivate &ot visibilityScope == other.visibilityScope && relevanceHint == other.relevanceHint && limit == other.limit && - offset == other.offset; + offset == other.offset && + searchContext == other.searchContext; } void QPlaceSearchRequestPrivate::clear() @@ -133,6 +138,7 @@ void QPlaceSearchRequestPrivate::clear() recommendationId.clear(); visibilityScope = QLocation::UnspecifiedVisibility; relevanceHint = QPlaceSearchRequest::UnspecifiedHint; + searchContext.clear(); } /*! @@ -329,6 +335,38 @@ void QPlaceSearchRequest::setRecommendationId(const QString &placeId) } /*! + Returns backend specific additional search context associated with this place search request. + The search context is typically set as part of a + \l {QPlaceSearchResult::ProposedSearchResult}{proposed search results}. +*/ +QVariant QPlaceSearchRequest::searchContext() const +{ + Q_D(const QPlaceSearchRequest); + return d->searchContext; +} + +/*! + Sets the search context to \a context. + + \note This method is intended to be used by geo service plugins when returning search results + of type \l QPlaceSearchResult::ProposedSearchResult. + + The search context is used by backends to store additional search context related to the search + request. Other relevant fields should also be filled in. For example, if the search context + encodes a text search the search term should also be set with \l setSearchTerm(). The search + context allows additional search context to be kept which is not directly accessible via the + Qt Location API. + + The search context can be of any type storable in a QVariant. The value of the search context + is not intended to be use directly by applications. +*/ +void QPlaceSearchRequest::setSearchContext(const QVariant &context) +{ + Q_D(QPlaceSearchRequest); + d->searchContext = context; +} + +/*! Returns the visibility scope used when searching for places. The default value is QLocation::UnspecifiedVisibility meaning that no explicit scope has been assigned. Places of any scope may be returned during the search. diff --git a/src/location/places/qplacesearchrequest.h b/src/location/places/qplacesearchrequest.h index 5fe93179..65ca3fe0 100644 --- a/src/location/places/qplacesearchrequest.h +++ b/src/location/places/qplacesearchrequest.h @@ -85,6 +85,9 @@ public: QString recommendationId() const; void setRecommendationId(const QString &recommendationId); + QVariant searchContext() const; + void setSearchContext(const QVariant &context); + QLocation::VisibilityScope visibilityScope() const; void setVisibilityScope(QLocation::VisibilityScope visibilityScopes); diff --git a/src/location/places/qplacesearchresult.cpp b/src/location/places/qplacesearchresult.cpp index 124299f5..4b6ab6de 100644 --- a/src/location/places/qplacesearchresult.cpp +++ b/src/location/places/qplacesearchresult.cpp @@ -96,9 +96,12 @@ bool QPlaceSearchResultPrivate::compare(const QPlaceSearchResultPrivate *other) /*! \enum QPlaceSearchResult::SearchResultType + Defines the type of search result - \value PlaceResult The search result contains a place. + \value UnknownSearchResult The contents of the search result are unknown. + \value PlaceResult The search result contains a place. + \value ProposedSearchResult The search result contains a proposed search which may be relevant. */ /*! diff --git a/src/location/places/qplacesearchresult.h b/src/location/places/qplacesearchresult.h index f8f0a5fc..4bcdf6d8 100644 --- a/src/location/places/qplacesearchresult.h +++ b/src/location/places/qplacesearchresult.h @@ -57,7 +57,9 @@ QT_BEGIN_NAMESPACE #define Q_DECLARE_SEARCHRESULT_COPY_CTOR(Class) \ Class(const QPlaceSearchResult &other); +class QPlaceSearchRequest; class QPlaceSearchResultPrivate; +class QPlaceIcon; class Q_LOCATION_EXPORT QPlaceSearchResult { @@ -76,7 +78,8 @@ public: enum SearchResultType { UnknownSearchResult = 0, - PlaceResult + PlaceResult, + ProposedSearchResult }; SearchResultType type() const; diff --git a/src/location/places/qplacesearchresult_p.h b/src/location/places/qplacesearchresult_p.h index f6a72f72..f12a9f70 100644 --- a/src/location/places/qplacesearchresult_p.h +++ b/src/location/places/qplacesearchresult_p.h @@ -43,6 +43,7 @@ #define QPLACESEARCHRESULT_P_H #include "qplacesearchresult.h" +#include "qplacesearchrequest.h" #include <QSharedData> #include <QtLocation/QPlaceIcon> diff --git a/src/location/places/qproposedsearchresult.cpp b/src/location/places/qproposedsearchresult.cpp new file mode 100644 index 00000000..94581b89 --- /dev/null +++ b/src/location/places/qproposedsearchresult.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qproposedsearchresult.h" +#include "qproposedsearchresult_p.h" + +QT_BEGIN_NAMESPACE + +QProposedSearchResultPrivate::QProposedSearchResultPrivate() +{ +} + +QProposedSearchResultPrivate::QProposedSearchResultPrivate(const QProposedSearchResultPrivate &other) +: QPlaceSearchResultPrivate(other), searchRequest(other.searchRequest) +{ +} + +QProposedSearchResultPrivate::~QProposedSearchResultPrivate() +{ +} + +bool QProposedSearchResultPrivate::compare(const QPlaceSearchResultPrivate *other) const +{ + const QProposedSearchResultPrivate *od = static_cast<const QProposedSearchResultPrivate *>(other); + return QPlaceSearchResultPrivate::compare(other) && searchRequest == od->searchRequest; +} + +/*! + \class QProposedSearchResult + \inmodule QtLocation + \ingroup QtLocation-places + \ingroup QtLocation-places-data + \since Qt Location 5.2 + + \brief The QProposedSearchResult class represents a search result containing a proposed search. + + \sa QPlaceSearchResult +*/ + +/*! + Constructs a new proposed search result. +*/ +QProposedSearchResult::QProposedSearchResult() +: QPlaceSearchResult(new QProposedSearchResultPrivate) +{ +} + +/*! + \fn QProposedSearchResult::QProposedSearchResult(const QPlaceSearchRequest &other) + + Contructs a copy of \a other if possible, otherwise constructs a default proposed search + result. +*/ +Q_IMPLEMENT_SEARCHRESULT_COPY_CTOR(QProposedSearchResult) + +Q_IMPLEMENT_SEARCHRESULT_D_FUNC(QProposedSearchResult) + +/*! + Destroys the proposed search result. +*/ +QProposedSearchResult::~QProposedSearchResult() +{ +} + +/*! + Returns a place search request that can be used to perform an additional proposed search. +*/ +QPlaceSearchRequest QProposedSearchResult::searchRequest() const +{ + Q_D(const QProposedSearchResult); + return d->searchRequest; +} + +/*! + Sets the proposed search request to \a request. +*/ +void QProposedSearchResult::setSearchRequest(const QPlaceSearchRequest &request) +{ + Q_D(QProposedSearchResult); + d->searchRequest = request; +} + +QT_END_NAMESPACE diff --git a/src/location/places/qproposedsearchresult.h b/src/location/places/qproposedsearchresult.h new file mode 100644 index 00000000..8c937324 --- /dev/null +++ b/src/location/places/qproposedsearchresult.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPOSEDSEARCHRESULT_H +#define QPROPOSEDSEARCHRESULT_H + +#include <QtLocation/QPlaceSearchResult> + +QT_BEGIN_NAMESPACE + +class QProposedSearchResultPrivate; + +class Q_LOCATION_EXPORT QProposedSearchResult : public QPlaceSearchResult +{ +public: + QProposedSearchResult(); + +#ifdef Q_QDOC + QProposedSearchResult(const QPlaceSearchRequest &other); +#else + Q_DECLARE_SEARCHRESULT_COPY_CTOR(QProposedSearchResult) +#endif + + ~QProposedSearchResult(); + + QPlaceSearchRequest searchRequest() const; + void setSearchRequest(const QPlaceSearchRequest &request); + +private: + Q_DECLARE_SEARCHRESULT_D_FUNC(QProposedSearchResult) +}; + +Q_DECLARE_TYPEINFO(QProposedSearchResult, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +#endif // QPROPOSEDSEARCHRESULT_H diff --git a/src/location/places/qproposedsearchresult_p.h b/src/location/places/qproposedsearchresult_p.h new file mode 100644 index 00000000..37df3447 --- /dev/null +++ b/src/location/places/qproposedsearchresult_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPOSEDSEARCHRESULT_P_H +#define QPROPOSEDSEARCHRESULT_P_H + +#include "qplacesearchresult_p.h" + +QT_BEGIN_NAMESPACE + +class QProposedSearchResultPrivate : public QPlaceSearchResultPrivate +{ +public: + QProposedSearchResultPrivate(); + QProposedSearchResultPrivate(const QProposedSearchResultPrivate &other); + + ~QProposedSearchResultPrivate(); + + bool compare(const QPlaceSearchResultPrivate *other) const Q_DECL_OVERRIDE; + + Q_DEFINE_SEARCHRESULT_PRIVATE_HELPER(QProposedSearchResult, QPlaceSearchResult::ProposedSearchResult) + + QPlaceSearchRequest searchRequest; +}; + +QT_END_NAMESPACE + +#endif // QPROPOSEDSEARCHRESULT_P_H diff --git a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp index 94a087e8..41f1c73e 100644 --- a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp @@ -57,6 +57,7 @@ #include <QtCore/QJsonArray> #include <QtLocation/QPlaceIcon> #include <QtLocation/QPlaceResult> +#include <QtLocation/QProposedSearchResult> #include <QtCore/QDebug> @@ -123,85 +124,107 @@ void QPlaceSearchReplyImpl::replyFinished() QJsonObject object = document.object(); //QJsonObject searchObject = object.value(QLatin1String("search")).toObject(); - QJsonArray items; - if (request().recommendationId().isEmpty()) { - QJsonObject resultsObject = object.value(QLatin1String("results")).toObject(); - items = resultsObject.value(QLatin1String("items")).toArray(); - } else { - items = object.value(QLatin1String("items")).toArray(); - } + + QJsonObject resultsObject = object.value(QLatin1String("results")).toObject(); + QJsonArray items = resultsObject.value(QLatin1String("items")).toArray(); QList<QPlaceSearchResult> results; for (int i = 0; i < items.count(); ++i) { QJsonObject item = items.at(i).toObject(); - QPlaceResult result; + const QString type = item.value(QLatin1String("type")).toString(); + if (type == QStringLiteral("urn:nlp-types:place")) + results.append(parsePlaceResult(item)); + else if (type == QStringLiteral("urn:nlp-types:search")) + results.append(parseSearchResult(item)); + } - if (item.contains(QLatin1String("distance"))) - result.setDistance(item.value(QLatin1String("distance")).toDouble()); + setResults(results); - QPlace place; + m_reply->deleteLater(); + m_reply = 0; - QGeoLocation location; + setFinished(true); + emit finished(); +} - location.setCoordinate(parseCoordinate(item.value(QLatin1String("position")).toArray())); +QPlaceResult QPlaceSearchReplyImpl::parsePlaceResult(const QJsonObject &item) const +{ + QPlaceResult result; - const QString vicinity = item.value(QLatin1String("vicinity")).toString(); - QGeoAddress address; - address.setText(vicinity); - location.setAddress(address); + if (item.contains(QLatin1String("distance"))) + result.setDistance(item.value(QLatin1String("distance")).toDouble()); - if (item.contains(QLatin1String("bbox"))) { - QJsonArray bbox = item.value(QLatin1String("bbox")).toArray(); - QGeoRectangle box(QGeoCoordinate(bbox.at(3).toDouble(), bbox.at(0).toDouble()), - QGeoCoordinate(bbox.at(1).toDouble(), bbox.at(2).toDouble())); - location.setBoundingBox(box); - } + QPlace place; - place.setLocation(location); + QGeoLocation location; - QPlaceRatings ratings; - ratings.setAverage(item.value(QLatin1String("averageRating")).toDouble()); - ratings.setMaximum(5.0); - place.setRatings(ratings); + location.setCoordinate(parseCoordinate(item.value(QLatin1String("position")).toArray())); - const QString title = item.value(QLatin1String("title")).toString(); - place.setName(title); - result.setTitle(title); + const QString vicinity = item.value(QLatin1String("vicinity")).toString(); + QGeoAddress address; + address.setText(vicinity); + location.setAddress(address); - QPlaceIcon icon = m_engine->icon(item.value(QLatin1String("icon")).toString()); - place.setIcon(icon); - result.setIcon(icon); + if (item.contains(QLatin1String("bbox"))) { + QJsonArray bbox = item.value(QLatin1String("bbox")).toArray(); + QGeoRectangle box(QGeoCoordinate(bbox.at(3).toDouble(), bbox.at(0).toDouble()), + QGeoCoordinate(bbox.at(1).toDouble(), bbox.at(2).toDouble())); + location.setBoundingBox(box); + } - place.setCategory(parseCategory(item.value(QLatin1String("category")).toObject(), - m_engine)); + place.setLocation(location); - //QJsonArray having = item.value(QLatin1String("having")).toArray(); + QPlaceRatings ratings; + ratings.setAverage(item.value(QLatin1String("averageRating")).toDouble()); + ratings.setMaximum(5.0); + place.setRatings(ratings); - result.setSponsored(item.value(QLatin1String("sponsored")).toBool()); + const QString title = item.value(QLatin1String("title")).toString(); + place.setName(title); + result.setTitle(title); - QUrl href = item.value(QLatin1String("href")).toString(); - //QUrl type = item.value(QLatin1String("type")).toString(); + QPlaceIcon icon = m_engine->icon(item.value(QLatin1String("icon")).toString()); + place.setIcon(icon); + result.setIcon(icon); - place.setPlaceId(href.path().mid(18, 41)); + place.setCategory(parseCategory(item.value(QLatin1String("category")).toObject(), + m_engine)); - QPlaceAttribute provider; - provider.setText(QLatin1String("nokia")); - place.setExtendedAttribute(QPlaceAttribute::Provider, provider); - place.setVisibility(QLocation::PublicVisibility); + //QJsonArray having = item.value(QLatin1String("having")).toArray(); - result.setPlace(place); + result.setSponsored(item.value(QLatin1String("sponsored")).toBool()); - results.append(result); - } + QUrl href = item.value(QLatin1String("href")).toString(); + //QUrl type = item.value(QLatin1String("type")).toString(); - setResults(results); + place.setPlaceId(href.path().mid(18, 41)); - m_reply->deleteLater(); - m_reply = 0; + QPlaceAttribute provider; + provider.setText(QLatin1String("nokia")); + place.setExtendedAttribute(QPlaceAttribute::Provider, provider); + place.setVisibility(QLocation::PublicVisibility); - setFinished(true); - emit finished(); + result.setPlace(place); + + return result; +} + +QProposedSearchResult QPlaceSearchReplyImpl::parseSearchResult(const QJsonObject &item) const +{ + QProposedSearchResult result; + + result.setTitle(item.value(QLatin1String("title")).toString()); + + QPlaceIcon icon = m_engine->icon(item.value(QStringLiteral("icon")).toString()); + result.setIcon(icon); + + QPlaceSearchRequest request; + request.setSearchContext(QUrl(item.value("href").toString())); + + result.setSearchRequest(request); + + return result; } QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h index 887147d8..a7871653 100644 --- a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h +++ b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE class QPlaceManagerEngineNokiaV2; +class QPlaceResult; +class QProposedSearchResult; class QPlaceSearchReplyImpl : public QPlaceSearchReply { @@ -73,6 +75,9 @@ private slots: void replyFinished(); private: + QPlaceResult parsePlaceResult(const QJsonObject &item) const; + QProposedSearchResult parseSearchResult(const QJsonObject &item) const; + QNetworkReply *m_reply; QPlaceManagerEngineNokiaV2 *m_engine; }; diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp index 27c4d06d..a31d88c4 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp @@ -402,9 +402,9 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest QUrlQuery queryItems; - //check the search area is valid for all searches except recommendation searches - //which do not need search centers. - if (query.recommendationId().isEmpty()) { + // Check that the search area is valid for all searches except recommendation and proposed + // searches, which do not need search centers. + if (query.recommendationId().isEmpty() && !query.searchContext().isValid()) { if (!addAtForBoundingArea(query.searchArea(), &queryItems)) { QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, 0, this); connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); @@ -417,7 +417,28 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest } } - if (!query.searchTerm().isEmpty()) { + QNetworkReply *networkReply = 0; + + if (query.searchContext().userType() == qMetaTypeId<QUrl>()) { + // provided search context + QUrl u = query.searchContext().value<QUrl>(); + + typedef QPair<QString, QString> QueryItem; + QList<QueryItem> queryItemList = queryItems.queryItems(QUrl::FullyEncoded); + queryItems = QUrlQuery(u); + foreach (const QueryItem &item, queryItemList) + queryItems.addQueryItem(item.first, item.second); + + if (query.limit() > 0) + queryItems.addQueryItem(QStringLiteral("size"), QString::number(query.limit())); + + if (query.offset() > -1) + queryItems.addQueryItem(QStringLiteral("offset"), QString::number(query.offset())); + + u.setQuery(queryItems); + + networkReply = sendRequest(u); + } else if (!query.searchTerm().isEmpty()) { // search term query QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() + QLatin1String("/places/v1/discover/search")); @@ -449,30 +470,22 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest requestUrl.setQuery(queryItems); - QNetworkReply *networkReply = sendRequest(requestUrl); - - QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this); - connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); - connect(reply, SIGNAL(error(QPlaceReply::Error,QString)), - this, SLOT(replyError(QPlaceReply::Error,QString))); - - return reply; + networkReply = sendRequest(requestUrl); } else { // category search - // The request URL should be "/places/v1/discover/explore" but that returns both places and - // clusters of places. We don't support clusters so we use the undocumented - // "/places/v1/discover/explore/places" instead which only returns places. - QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() + - QLatin1String("/places/v1/discover/explore/places")); + QUrl requestUrl(QStringLiteral("http://") + m_uriProvider->getCurrentHost() + + QStringLiteral("/places/v1/discover/explore")); QStringList ids; foreach (const QPlaceCategory &category, query.categories()) ids.append(category.categoryId()); - if (ids.count() > 0) { - queryItems.addQueryItem(QLatin1String("cat"), - ids.join(QLatin1String(","))); - } + QUrlQuery queryItems; + + if (!ids.isEmpty()) + queryItems.addQueryItem(QStringLiteral("cat"), ids.join(QStringLiteral(","))); + + addAtForBoundingArea(query.searchArea(), &queryItems); queryItems.addQueryItem(QLatin1String("tf"), QLatin1String("html")); @@ -487,15 +500,15 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest requestUrl.setQuery(queryItems); - QNetworkReply *networkReply = sendRequest(requestUrl); + networkReply = sendRequest(requestUrl); + } - QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this); - connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); - connect(reply, SIGNAL(error(QPlaceReply::Error,QString)), - this, SLOT(replyError(QPlaceReply::Error,QString))); + QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this); + connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); + connect(reply, SIGNAL(error(QPlaceReply::Error,QString)), + this, SLOT(replyError(QPlaceReply::Error,QString))); - return reply; - } + return reply; } QPlaceSearchSuggestionReply *QPlaceManagerEngineNokiaV2::searchSuggestions(const QPlaceSearchRequest &query) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index ff6ca81c..7cb6d27e 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -13,6 +13,7 @@ SUBDIRS += qplace \ qplaceimage \ qplaceratings \ qplaceresult \ + qproposedsearchresult \ qplacereply \ qplacereview \ qplacesearchrequest \ diff --git a/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp b/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp index ea9fe0e9..5753ddd3 100644 --- a/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp +++ b/tests/auto/qplacesearchrequest/tst_qplacesearchrequest.cpp @@ -63,6 +63,7 @@ private Q_SLOTS: void searchAreaTest(); void visibilityScopeTest(); void relevanceHintTest(); + void searchContextTest(); void operatorsTest(); void clearTest(); }; @@ -187,6 +188,14 @@ void tst_QPlaceSearchRequest::relevanceHintTest() QCOMPARE(request.relevanceHint(), QPlaceSearchRequest::UnspecifiedHint); } +void tst_QPlaceSearchRequest::searchContextTest() +{ + QPlaceSearchRequest request; + QVERIFY(!request.searchContext().value<QUrl>().isValid()); + request.setSearchContext(QUrl(QLatin1String("http://www.example.com/"))); + QCOMPARE(request.searchContext().value<QUrl>(), QUrl(QLatin1String("http://www.example.com/"))); +} + void tst_QPlaceSearchRequest::operatorsTest() { QPlaceSearchRequest testObj; @@ -242,6 +251,12 @@ void tst_QPlaceSearchRequest::operatorsTest() //test that different scopes do not match testObj2.setVisibilityScope(QLocation::PrivateVisibility); QVERIFY2(testObj != testObj2, "Different scopes identified as matching"); + + //test that different search contexts do not match + testObj.clear(); + testObj2.clear(); + testObj2.setSearchContext(QUrl(QLatin1String("http://www.example.com/"))); + QVERIFY(testObj != testObj2); } void tst_QPlaceSearchRequest::clearTest() diff --git a/tests/auto/qproposedsearchresult/qproposedsearchresult.pro b/tests/auto/qproposedsearchresult/qproposedsearchresult.pro new file mode 100644 index 00000000..3a328920 --- /dev/null +++ b/tests/auto/qproposedsearchresult/qproposedsearchresult.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +CONFIG += testcase +TARGET = tst_qproposedsearchresult + +SOURCES += tst_qproposedsearchresult.cpp + +QT += location testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qproposedsearchresult/tst_qproposedsearchresult.cpp b/tests/auto/qproposedsearchresult/tst_qproposedsearchresult.cpp new file mode 100644 index 00000000..71ba06de --- /dev/null +++ b/tests/auto/qproposedsearchresult/tst_qproposedsearchresult.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QString> +#include <QtLocation/QProposedSearchResult> +#include <QtLocation/QPlaceIcon> +#include <QtLocation/QPlaceSearchRequest> +#include <QtTest/QtTest> + +#include "../utils/qlocationtestutils_p.h" + +QT_USE_NAMESPACE + +class tst_QProposedSearchResult : public QObject +{ + Q_OBJECT + +public: + QProposedSearchResult initialSubObject(); + bool checkType(const QPlaceSearchResult &result); + void detach(QPlaceSearchResult *result); + void setSubClassProperty(QProposedSearchResult *result); + +private Q_SLOTS: + void constructorTest(); + void title(); + void icon(); + void searchRequest(); + void conversion(); +}; + +QProposedSearchResult tst_QProposedSearchResult::initialSubObject() +{ + QProposedSearchResult proposedSearchResult; + proposedSearchResult.setTitle(QStringLiteral("title")); + + QPlaceIcon icon; + QVariantMap parameters; + parameters.insert(QPlaceIcon::SingleUrl, + QUrl(QStringLiteral("file:///opt/icons/icon.png"))); + icon.setParameters(parameters); + proposedSearchResult.setIcon(icon); + + QPlaceSearchRequest searchRequest; + searchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/"))); + proposedSearchResult.setSearchRequest(searchRequest); + + return proposedSearchResult; +} + +bool tst_QProposedSearchResult::checkType(const QPlaceSearchResult &result) +{ + return result.type() == QPlaceSearchResult::ProposedSearchResult; +} + +void tst_QProposedSearchResult::detach(QPlaceSearchResult *result) +{ + result->setTitle(QStringLiteral("title")); +} + +void tst_QProposedSearchResult::setSubClassProperty(QProposedSearchResult *result) +{ + QPlaceSearchRequest request; + request.setSearchContext(QUrl(QStringLiteral("http://www.example.com/place-search"))); + result->setSearchRequest(request); +} + +void tst_QProposedSearchResult::constructorTest() +{ + QProposedSearchResult result; + QCOMPARE(result.type(), QPlaceSearchResult::ProposedSearchResult); + + result.setTitle(QStringLiteral("title")); + + QPlaceIcon icon; + QVariantMap parameters; + parameters.insert(QLatin1String("paramKey"), QLatin1String("paramValue")); + icon.setParameters(parameters); + result.setIcon(icon); + + QPlaceSearchRequest searchRequest; + searchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/place-search"))); + result.setSearchRequest(searchRequest); + + //check copy constructor + QProposedSearchResult result2(result); + QCOMPARE(result2.title(), QStringLiteral("title")); + QCOMPARE(result2.icon(), icon); + QCOMPARE(result2.searchRequest(), searchRequest); + + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + //check results are the same after detachment of underlying shared data pointer + result2.setTitle(QStringLiteral("title")); + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + //check construction of SearchResult using a ProposedSearchResult + QPlaceSearchResult searchResult(result); + QCOMPARE(searchResult.title(), QStringLiteral("title")); + QCOMPARE(searchResult.icon(), icon); + QVERIFY(QLocationTestUtils::compareEquality(searchResult, result)); + QVERIFY(searchResult.type() == QPlaceSearchResult::ProposedSearchResult); + result2 = searchResult; + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + //check construction of a SearchResult using a SearchResult + //that is actually a PlaceResult underneath + QPlaceSearchResult searchResult2(searchResult); + QCOMPARE(searchResult2.title(), QStringLiteral("title")); + QCOMPARE(searchResult2.icon(), icon); + QVERIFY(QLocationTestUtils::compareEquality(searchResult2, result)); + QVERIFY(QLocationTestUtils::compareEquality(searchResult, searchResult2)); + QVERIFY(searchResult2.type() == QPlaceSearchResult::ProposedSearchResult); + result2 = searchResult2; + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); +} + +void tst_QProposedSearchResult::title() +{ + QProposedSearchResult result; + QVERIFY(result.title().isEmpty()); + + result.setTitle(QStringLiteral("title")); + QCOMPARE(result.title(), QStringLiteral("title")); + + result.setTitle(QString()); + QVERIFY(result.title().isEmpty()); + + QProposedSearchResult result2; + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + result2.setTitle("title"); + QVERIFY(QLocationTestUtils::compareInequality(result, result2)); + + result.setTitle("title"); + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); +} + +void tst_QProposedSearchResult::icon() +{ + QProposedSearchResult result; + QVERIFY(result.icon().isEmpty()); + + QPlaceIcon icon; + QVariantMap iconParams; + iconParams.insert(QLatin1String("paramKey"), QLatin1String("paramValue")); + icon.setParameters(iconParams); + result.setIcon(icon); + QCOMPARE(result.icon(), icon); + + result.setIcon(QPlaceIcon()); + QVERIFY(result.icon().isEmpty()); + + QProposedSearchResult result2; + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + result2.setIcon(icon); + QVERIFY(QLocationTestUtils::compareInequality(result, result2)); + + result.setIcon(icon); + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); +} + +void tst_QProposedSearchResult::searchRequest() +{ + QProposedSearchResult result; + QCOMPARE(result.searchRequest(), QPlaceSearchRequest()); + + QPlaceSearchRequest placeSearchRequest; + placeSearchRequest.setSearchContext(QUrl(QStringLiteral("http://www.example.com/"))); + result.setSearchRequest(placeSearchRequest); + QCOMPARE(result.searchRequest(), placeSearchRequest); + + result.setSearchRequest(QPlaceSearchRequest()); + QCOMPARE(result.searchRequest(), QPlaceSearchRequest()); + + QProposedSearchResult result2; + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); + + result2.setSearchRequest(placeSearchRequest); + QVERIFY(QLocationTestUtils::compareInequality(result, result2)); + + result.setSearchRequest(placeSearchRequest); + QVERIFY(QLocationTestUtils::compareEquality(result, result2)); +} + +void tst_QProposedSearchResult::conversion() +{ + QLocationTestUtils::testConversion<tst_QProposedSearchResult, + QPlaceSearchResult, + QProposedSearchResult>(this); +} + +QTEST_APPLESS_MAIN(tst_QProposedSearchResult) + +#include "tst_qproposedsearchresult.moc" |