| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #include "qplaceresult.h" |
| 38 | #include "qplaceresult_p.h" |
| 39 | #include <QtCore/qnumeric.h> |
| 40 | |
| 41 | QT_USE_NAMESPACE |
| 42 | |
| 43 | QPlaceResultPrivate::QPlaceResultPrivate() |
| 44 | : QPlaceSearchResultPrivate(), distance(qQNaN()), sponsored(false) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | QPlaceResultPrivate::QPlaceResultPrivate(const QPlaceResultPrivate &other) |
| 49 | : QPlaceSearchResultPrivate(other), distance(other.distance), place(other.place), |
| 50 | sponsored(other.sponsored) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | QPlaceResultPrivate::~QPlaceResultPrivate() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | bool QPlaceResultPrivate::compare(const QPlaceSearchResultPrivate *other) const |
| 59 | { |
| 60 | const QPlaceResultPrivate *od = static_cast<const QPlaceResultPrivate *>(other); |
| 61 | return QPlaceSearchResultPrivate::compare(other) |
| 62 | && ((qIsNaN(d: distance) && qIsNaN(d: od->distance)) |
| 63 | || qFuzzyCompare(p1: distance, p2: od->distance)) |
| 64 | && place == od->place |
| 65 | && sponsored == od->sponsored; |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | \class QPlaceResult |
| 70 | \inmodule QtLocation |
| 71 | \ingroup QtLocation-places |
| 72 | \ingroup QtLocation-places-data |
| 73 | \since 5.6 |
| 74 | |
| 75 | \brief The QPlaceResult class represents a search result containing a place. |
| 76 | |
| 77 | The PlaceResult holds the distance to the place from the center of the search request, |
| 78 | an instance of the place and an indication of whether the result is |
| 79 | sponsored or \l {http://en.wikipedia.org/wiki/Organic_search}{organic}. |
| 80 | |
| 81 | The intended usage is that a QPlaceSearchResult can be converted into a QPlaceResult |
| 82 | like so: |
| 83 | |
| 84 | \snippet places/requesthandler.h Convert search result |
| 85 | |
| 86 | The implementation is handled in such a way that object slicing is not an issue. |
| 87 | |
| 88 | \sa QPlaceSearchResult |
| 89 | */ |
| 90 | |
| 91 | /*! |
| 92 | Constructs a new place result object. |
| 93 | */ |
| 94 | QPlaceResult::QPlaceResult() |
| 95 | : QPlaceSearchResult(new QPlaceResultPrivate) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | /*! |
| 100 | Destructor. |
| 101 | */ |
| 102 | QPlaceResult::~QPlaceResult() |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | /*! |
| 107 | \fn QPlaceResult::QPlaceResult(const QPlaceSearchResult &other) |
| 108 | Constructs a copy of \a other if possible, otherwise constructs a default place result. |
| 109 | */ |
| 110 | Q_IMPLEMENT_SEARCHRESULT_COPY_CTOR(QPlaceResult) |
| 111 | |
| 112 | Q_IMPLEMENT_SEARCHRESULT_D_FUNC(QPlaceResult) |
| 113 | |
| 114 | /*! |
| 115 | Returns the distance of the place to the search center. This |
| 116 | field is only relevant provided the search request contained |
| 117 | a search area with a search center. Otherwise, |
| 118 | the distance is NaN indicating an undefined distance. The default value |
| 119 | for distance is NaN. |
| 120 | */ |
| 121 | qreal QPlaceResult::distance() const |
| 122 | { |
| 123 | Q_D(const QPlaceResult); |
| 124 | return d->distance; |
| 125 | } |
| 126 | |
| 127 | /*! |
| 128 | Set the \a distance of the search result's place from a search center. |
| 129 | */ |
| 130 | void QPlaceResult::setDistance(qreal distance) |
| 131 | { |
| 132 | Q_D(QPlaceResult); |
| 133 | d->distance = distance; |
| 134 | } |
| 135 | |
| 136 | /*! |
| 137 | Returns the place of the search result. |
| 138 | */ |
| 139 | QPlace QPlaceResult::place() const |
| 140 | { |
| 141 | Q_D(const QPlaceResult); |
| 142 | return d->place; |
| 143 | } |
| 144 | |
| 145 | /*! |
| 146 | Sets the \a place that this result refers to. |
| 147 | */ |
| 148 | void QPlaceResult::setPlace(const QPlace &place) |
| 149 | { |
| 150 | Q_D(QPlaceResult); |
| 151 | d->place = place; |
| 152 | } |
| 153 | |
| 154 | /*! |
| 155 | Returns true if the result is a sponsored result. |
| 156 | |
| 157 | \sa setSponsored() |
| 158 | */ |
| 159 | bool QPlaceResult::() const |
| 160 | { |
| 161 | Q_D(const QPlaceResult); |
| 162 | return d->sponsored; |
| 163 | } |
| 164 | |
| 165 | /*! |
| 166 | Sets whether the result is a \a sponsored result or not. |
| 167 | |
| 168 | \sa isSponsored() |
| 169 | */ |
| 170 | void QPlaceResult::(bool ) |
| 171 | { |
| 172 | Q_D(QPlaceResult); |
| 173 | d->sponsored = sponsored; |
| 174 | } |
| 175 | |