diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2012-02-21 13:13:09 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-21 04:30:11 +0100 |
commit | e2c3d8978ca8a598aa3dd6481f776a5fe8d7c9c2 (patch) | |
tree | adf7a6be8e6f6f0a5165dc778410864faa0f6b93 | |
parent | 8789d662712461b0b8a8ee4724c972bf299b25b3 (diff) | |
download | qtlocation-e2c3d8978ca8a598aa3dd6481f776a5fe8d7c9c2.tar.gz |
Add sponsored field/role to place search results.
Place search results can be either sponsored or organic search results.
This adds a sponsored field/role so that applications can distinguish
between the two.
Change-Id: I10c9a5699b1c013a2b7ba8ac8100348213a68b8a
Reviewed-by: abcd <amos.choy@nokia.com>
8 files changed, 65 insertions, 8 deletions
diff --git a/examples/declarative/places/content/places/SearchResultDelegate.qml b/examples/declarative/places/content/places/SearchResultDelegate.qml index ecf6ee1a..9ecde825 100644 --- a/examples/declarative/places/content/places/SearchResultDelegate.qml +++ b/examples/declarative/places/content/places/SearchResultDelegate.qml @@ -60,6 +60,12 @@ Item { height: childrenRect.height width: parent.width + Rectangle { + anchors.fill: parent + color: "#dbffde" + visible: sponsored + } + Column { width: parent.width @@ -74,6 +80,13 @@ Item { Text { id: placeName; text: place.favorite ? place.favorite.name : place.name } } Text { id: distanceText; text: distance + "m"; font.italic: true; } + Text { + text: qsTr("Sponsored result") + horizontalAlignment: Text.AlignRight + font.pixelSize: 8 + width: parent.width + visible: sponsored + } } MouseArea { diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index a80c2d53..883a4dff 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -74,6 +74,10 @@ QT_USE_NAMESPACE \l offset and \l limit properties are set the search results between \l offset and (\l offset + \l limit - 1) will be returned. + The PlaceSearchModel returns both sponsored and + \l {http://en.wikipedia.org/wiki/Organic_search}{organic search results}. Sponsored search + results will have the \c sponsored role set to true. + The model returns data for the following roles: \table @@ -92,9 +96,14 @@ QT_USE_NAMESPACE \row \o place \o \l Place - \o Valid only when they \c type role is \c PlaceResult, an object representing the + \o Valid only when the \c type role is \c PlaceResult, an object representing the place. \row + \o sponsored + \o bool + \o Valid only when the \c type role is \c PlaceResult, true if the search result is a + sponsored result. + \row \o correction \o string \o Valid only when the \c type role is \c CorrectionResult, a suggested correction to @@ -215,6 +224,7 @@ QDeclarativeSearchResultModel::QDeclarativeSearchResultModel(QObject *parent) QHash<int, QByteArray> roles = roleNames(); roles.insert(SearchResultTypeRole, "type"); roles.insert(CorrectionRole, "correction"); + roles.insert(SponsoredRole, "sponsored"); setRoleNames(roles); } @@ -405,6 +415,8 @@ QVariant QDeclarativeSearchResultModel::data(const QModelIndex &index, int role) return m_results.at(index.row()).type(); case CorrectionRole: return m_results.at(index.row()).correction(); + case SponsoredRole: + return m_results.at(index.row()).isSponsored(); default: return QDeclarativeResultModelBase::data(index, role); } diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h index 8f98ea5c..33bd1b2d 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel_p.h @@ -117,7 +117,8 @@ private slots: private: enum Roles { SearchResultTypeRole = QDeclarativeResultModelBase::PlaceRole + 1, - CorrectionRole + CorrectionRole, + SponsoredRole }; int getRow(const QString &placeId) const; diff --git a/src/location/places/qplacesearchresult.cpp b/src/location/places/qplacesearchresult.cpp index c383a951..ecf9ab41 100644 --- a/src/location/places/qplacesearchresult.cpp +++ b/src/location/places/qplacesearchresult.cpp @@ -46,7 +46,8 @@ QT_USE_NAMESPACE QPlaceSearchResultPrivate::QPlaceSearchResultPrivate() - : QSharedData(), distance(qQNaN()), type(QPlaceSearchResult::UnknownSearchResult) +: QSharedData(), distance(qQNaN()), type(QPlaceSearchResult::UnknownSearchResult), + sponsored(false) { } @@ -57,6 +58,7 @@ QPlaceSearchResultPrivate::QPlaceSearchResultPrivate(const QPlaceSearchResultPri type = other.type; place = other.place; correction = other.correction; + sponsored = other.sponsored; } QPlaceSearchResultPrivate::~QPlaceSearchResultPrivate() @@ -68,7 +70,8 @@ bool QPlaceSearchResultPrivate::operator==(const QPlaceSearchResultPrivate &othe return distance == other.distance && type == other.type && place == other.place && - correction == other.correction; + correction == other.correction && + sponsored == other.sponsored; } /*! @@ -80,10 +83,11 @@ bool QPlaceSearchResultPrivate::operator==(const QPlaceSearchResultPrivate &othe \brief The QPlaceSearchResult class represents a search result. - There are two types of search result. The first is a + There are two types of search results. The first is a \l {QPlaceSearchResult::PlaceResult} {place result}, which contains - a place that matched a search request, but also metadata about the place - such as the distance from the search center of a search request (if it had one). + a place that matched the search request, but also metadata about the place + such as the distance from the search center of a search request and whether the result is a + sponsored or \l {http://en.wikipedia.org/wiki/Organic_search}{organic} search result. The other type is a \l {QPlaceSearchResult::CorrectionResult}{correction}, which contains an alternative search term that may better reflect the @@ -215,3 +219,23 @@ void QPlaceSearchResult::setCorrection(const QString &correction) { d->correction = correction; } + +/*! + Returns true if the search result represents a sponsored result. + + \sa setSponsored() +*/ +bool QPlaceSearchResult::isSponsored() const +{ + return d->sponsored; +} + +/*! + Sets whether the search result represents a \a sponsored result or not. + + \sa isSponsored() +*/ +void QPlaceSearchResult::setSponsored(bool sponsored) +{ + d->sponsored = sponsored; +} diff --git a/src/location/places/qplacesearchresult.h b/src/location/places/qplacesearchresult.h index 90ac8f47..8f1f0ee3 100644 --- a/src/location/places/qplacesearchresult.h +++ b/src/location/places/qplacesearchresult.h @@ -88,6 +88,9 @@ public: QString correction() const; void setCorrection(const QString &correction); + bool isSponsored() const; + void setSponsored(bool sponsored); + private: QSharedDataPointer<QPlaceSearchResultPrivate> d; }; diff --git a/src/location/places/qplacesearchresult_p.h b/src/location/places/qplacesearchresult_p.h index 17fef5bd..05e96e69 100644 --- a/src/location/places/qplacesearchresult_p.h +++ b/src/location/places/qplacesearchresult_p.h @@ -62,6 +62,7 @@ public: QPlaceSearchResult::SearchResultType type; QPlace place; QString correction; + bool sponsored; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp index 1341a431..b4cf4419 100644 --- a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp @@ -153,7 +153,7 @@ void QPlaceSearchReplyImpl::replyFinished() //QJsonArray having = item.value(QLatin1String("having")).toArray(); - //bool sponsored = item.value(QLatin1String("sponsored")).toBool(); + result.setSponsored(item.value(QLatin1String("sponsored")).toBool()); QUrl href = item.value(QLatin1String("href")).toString(); //QUrl type = item.value(QLatin1String("type")).toString(); diff --git a/tests/auto/qplacesearchresult/tst_qplacesearchresult.cpp b/tests/auto/qplacesearchresult/tst_qplacesearchresult.cpp index 365d50eb..e73a5523 100644 --- a/tests/auto/qplacesearchresult/tst_qplacesearchresult.cpp +++ b/tests/auto/qplacesearchresult/tst_qplacesearchresult.cpp @@ -61,16 +61,19 @@ void tst_QPlaceSearchResult::test() QVERIFY(qIsNaN(result.distance())); QCOMPARE(result.place(), QPlace()); QVERIFY(result.correction().isEmpty()); + QVERIFY(!result.isSponsored()); result.setType(QPlaceSearchResult::PlaceResult); result.setDistance(2.0); result.setPlace(QPlace()); result.setCorrection(QLatin1String("suggestion")); + result.setSponsored(true); QCOMPARE(result.type(), QPlaceSearchResult::PlaceResult); QCOMPARE(result.distance(), 2.0); QCOMPARE(result.place(), QPlace()); QCOMPARE(result.correction(), QLatin1String("suggestion")); + QVERIFY(result.isSponsored()); QPlaceSearchResult result2(result); |