| 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 "qplacematchrequest.h" |
| 38 | |
| 39 | #include <QtCore/QSharedData> |
| 40 | #include <QtCore/QList> |
| 41 | #include <QtLocation/QPlaceResult> |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | class QPlaceMatchRequestPrivate : public QSharedData |
| 46 | { |
| 47 | public: |
| 48 | QPlaceMatchRequestPrivate(); |
| 49 | QPlaceMatchRequestPrivate(const QPlaceMatchRequestPrivate &other); |
| 50 | ~QPlaceMatchRequestPrivate(); |
| 51 | |
| 52 | QPlaceMatchRequestPrivate &operator=(const QPlaceMatchRequestPrivate &other); |
| 53 | bool operator==(const QPlaceMatchRequestPrivate &other) const; |
| 54 | |
| 55 | void clear(); |
| 56 | |
| 57 | QList<QPlace> places; |
| 58 | QVariantMap parameters; |
| 59 | }; |
| 60 | |
| 61 | QPlaceMatchRequestPrivate::QPlaceMatchRequestPrivate() |
| 62 | : QSharedData() |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | QPlaceMatchRequestPrivate::QPlaceMatchRequestPrivate(const QPlaceMatchRequestPrivate &other) |
| 67 | : QSharedData(other), |
| 68 | places(other.places), |
| 69 | parameters(other.parameters) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | QPlaceMatchRequestPrivate::~QPlaceMatchRequestPrivate() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | QPlaceMatchRequestPrivate &QPlaceMatchRequestPrivate::operator=(const QPlaceMatchRequestPrivate &other) |
| 78 | { |
| 79 | if (this != &other) { |
| 80 | places = other.places; |
| 81 | parameters = other.parameters; |
| 82 | } |
| 83 | |
| 84 | return *this; |
| 85 | } |
| 86 | |
| 87 | bool QPlaceMatchRequestPrivate::operator==(const QPlaceMatchRequestPrivate &other) const |
| 88 | { |
| 89 | return (places == other.places |
| 90 | && parameters == other.parameters); |
| 91 | } |
| 92 | |
| 93 | void QPlaceMatchRequestPrivate::clear() |
| 94 | { |
| 95 | places.clear(); |
| 96 | parameters.clear(); |
| 97 | } |
| 98 | |
| 99 | /*! |
| 100 | \class QPlaceMatchRequest |
| 101 | \inmodule QtLocation |
| 102 | \ingroup QtLocation-places |
| 103 | \ingroup QtLocation-places-requests |
| 104 | \since 5.6 |
| 105 | |
| 106 | \brief The QPlaceMatchRequest class is used to find places from one manager that match those from another. It represents |
| 107 | a set of request parameters. |
| 108 | |
| 109 | Places from another manager that may have corresponding/matching places in the current manager are assigned using setPlaces() or setResults(). |
| 110 | A set of further parameters are specified which determines the criteria for matching. |
| 111 | |
| 112 | The typical key for matching is the QPlaceMatchRequest::AlternativeId, the value is an alternative identifier attribute type of the format |
| 113 | x_id_<provider name> for example x_id_here. The provider name is name supplied to the QGeoServiceProvider instance. |
| 114 | |
| 115 | See \l {Matching places between managers} for an example on how to use a match request. |
| 116 | |
| 117 | \sa QPlaceMatchReply, QPlaceManager |
| 118 | */ |
| 119 | |
| 120 | /*! |
| 121 | \variable QPlaceMatchRequest::AlternativeId |
| 122 | The key to specify that matching is to be accomplished via an alternative place identifier. |
| 123 | */ |
| 124 | const QString QPlaceMatchRequest::AlternativeId(QLatin1String("alternativeId" )); |
| 125 | |
| 126 | /*! |
| 127 | Default constructor. Constructs a new request object. |
| 128 | */ |
| 129 | QPlaceMatchRequest::QPlaceMatchRequest() |
| 130 | : d_ptr(new QPlaceMatchRequestPrivate()) |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | /*! |
| 135 | Constructs a copy of \a other. |
| 136 | */ |
| 137 | QPlaceMatchRequest::QPlaceMatchRequest(const QPlaceMatchRequest &other) |
| 138 | : d_ptr(other.d_ptr) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | /*! |
| 143 | Destroys the request object. |
| 144 | */ |
| 145 | QPlaceMatchRequest::~QPlaceMatchRequest() |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | /*! |
| 150 | Assigns \a other to this search request and returns a reference |
| 151 | to this match request. |
| 152 | */ |
| 153 | QPlaceMatchRequest &QPlaceMatchRequest::operator= (const QPlaceMatchRequest & other) |
| 154 | { |
| 155 | if (this == &other) |
| 156 | return *this; |
| 157 | d_ptr = other.d_ptr; |
| 158 | return *this; |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | Returns true if \a other is equal to this match request, |
| 163 | otherwise returns false. |
| 164 | */ |
| 165 | bool QPlaceMatchRequest::operator== (const QPlaceMatchRequest &other) const |
| 166 | { |
| 167 | Q_D(const QPlaceMatchRequest); |
| 168 | return *d == *other.d_func(); |
| 169 | } |
| 170 | |
| 171 | /*! |
| 172 | Returns true if \a other is not equal to this match request, |
| 173 | otherwise returns false. |
| 174 | */ |
| 175 | bool QPlaceMatchRequest::operator!= (const QPlaceMatchRequest &other) const |
| 176 | { |
| 177 | Q_D(const QPlaceMatchRequest); |
| 178 | return !(*d == *other.d_func()); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /*! |
| 183 | Returns a list of places which are to be matched. |
| 184 | */ |
| 185 | QList<QPlace> QPlaceMatchRequest::places() const |
| 186 | { |
| 187 | Q_D(const QPlaceMatchRequest); |
| 188 | return d->places; |
| 189 | } |
| 190 | |
| 191 | /*! |
| 192 | Sets a list of \a places which are to be matched. |
| 193 | |
| 194 | \sa setResults() |
| 195 | */ |
| 196 | void QPlaceMatchRequest::setPlaces(const QList<QPlace> places) |
| 197 | { |
| 198 | Q_D(QPlaceMatchRequest); |
| 199 | d->places = places; |
| 200 | } |
| 201 | |
| 202 | /*! |
| 203 | Convenience function which uses a set of search \a results to set |
| 204 | the places which should be matched. |
| 205 | |
| 206 | \sa setPlaces() |
| 207 | */ |
| 208 | void QPlaceMatchRequest::setResults(const QList<QPlaceSearchResult> &results) |
| 209 | { |
| 210 | Q_D(QPlaceMatchRequest); |
| 211 | QList<QPlace> places; |
| 212 | foreach (const QPlaceSearchResult &result, results) { |
| 213 | if (result.type() == QPlaceSearchResult::PlaceResult) { |
| 214 | QPlaceResult placeResult = result; |
| 215 | places.append(t: placeResult.place()); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | d->places = places; |
| 220 | } |
| 221 | |
| 222 | /*! |
| 223 | Returns the parameters for matching places. |
| 224 | */ |
| 225 | QVariantMap QPlaceMatchRequest::parameters() const |
| 226 | { |
| 227 | Q_D(const QPlaceMatchRequest); |
| 228 | return d->parameters; |
| 229 | } |
| 230 | |
| 231 | /*! |
| 232 | Sets the \a parameters for matching places. |
| 233 | */ |
| 234 | void QPlaceMatchRequest::setParameters(const QVariantMap ¶meters) |
| 235 | { |
| 236 | Q_D(QPlaceMatchRequest); |
| 237 | d->parameters = parameters; |
| 238 | } |
| 239 | |
| 240 | /*! |
| 241 | Clears the match request. |
| 242 | */ |
| 243 | void QPlaceMatchRequest::clear() |
| 244 | { |
| 245 | Q_D(QPlaceMatchRequest); |
| 246 | d->clear(); |
| 247 | } |
| 248 | |
| 249 | inline QPlaceMatchRequestPrivate *QPlaceMatchRequest::d_func() |
| 250 | { |
| 251 | return static_cast<QPlaceMatchRequestPrivate *>(d_ptr.data()); |
| 252 | } |
| 253 | |
| 254 | inline const QPlaceMatchRequestPrivate *QPlaceMatchRequest::d_func() const |
| 255 | { |
| 256 | return static_cast<const QPlaceMatchRequestPrivate *>(d_ptr.constData()); |
| 257 | } |
| 258 | |
| 259 | QT_END_NAMESPACE |
| 260 | |