Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplacesearchrequest.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
7#include "qgeoshape.h"
8
9#include <QtLocation/QPlaceCategory>
10
11#include <QtCore/QSharedData>
12#include <QtCore/QList>
13#include <QtCore/QVariant>
14#include <QDebug>
15
17
18QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QPlaceSearchRequestPrivate)
19
20bool QPlaceSearchRequestPrivate::operator==(const QPlaceSearchRequestPrivate &other) const
21{
22 return searchTerm == other.searchTerm &&
23 categories == other.categories &&
24 searchArea == other.searchArea &&
25 recommendationId == other.recommendationId &&
26 visibilityScope == other.visibilityScope &&
27 relevanceHint == other.relevanceHint &&
28 limit == other.limit &&
29 searchContext == other.searchContext;
30
31 // deliberately not testing related and page. comparing only the content.
32}
33
34void QPlaceSearchRequestPrivate::clear()
35{
36 limit = -1;
37 searchTerm.clear();
38 categories.clear();
39 searchArea = QGeoShape();
40 recommendationId.clear();
41 visibilityScope = QLocation::UnspecifiedVisibility;
42 relevanceHint = QPlaceSearchRequest::UnspecifiedHint;
43 searchContext.clear();
44 related = false;
45 page = 0;
46}
47
48const QPlaceSearchRequestPrivate *QPlaceSearchRequestPrivate::get(const QPlaceSearchRequest &request)
49{
50 return request.d_ptr.constData();
51}
52
53QPlaceSearchRequestPrivate *QPlaceSearchRequestPrivate::get(QPlaceSearchRequest &request)
54{
55 return request.d_ptr.data();
56}
57
58/*!
59 \class QPlaceSearchRequest
60 \inmodule QtLocation
61 \ingroup QtLocation-places
62 \ingroup QtLocation-places-requests
63 \since 5.6
64
65 \brief The QPlaceSearchRequest class represents the set of parameters for a search request.
66
67 A typical search request may look like the following:
68 \snippet places/requesthandler.h Search request
69
70 Note that specifying a search center can be done by setting a circular search area that has
71 a center but no radius. The default radius is set to -1, which indicates an undefined radius. The provider will
72 interpret this as being free to choose its own default radius.
73
74 The QPlaceSearchRequest is primarily used with the QPlaceManager to
75 \l {QPlaceManager::search()} {search for places}, however it is also
76 used to provide parameters for \l {QPlaceManager::searchSuggestions()}{generating search term suggestions}.
77 Note that in this context only some of the parameters may be relevant. For example, the search area
78 is useful in narrowing down relevant search suggestions, while other parameters such as relevance hint
79 are not so applicable.
80
81 Also be aware that providers may vary by which parameters they support for example some providers may not support
82 paging while others do, some providers may honor relevance hints while others may completely ignore them,
83 see the \l {Qt Location#Plugin References and Parameters}{plugin documentation} for more
84 details.
85*/
86
87/*!
88 \enum QPlaceSearchRequest::RelevanceHint
89
90 Defines hints to help rank place results.
91 \value UnspecifiedHint
92 No explicit hint has been specified.
93 \value DistanceHint
94 Distance to a search center is relevant for the user. Closer places
95 are more highly weighted. This hint is only useful
96 if a circular search area is used in the query.
97 \value LexicalPlaceNameHint
98 Alphabetic ordering of places according to name is relevant to the user.
99*/
100
101/*!
102 Default constructor. Constructs an new request object.
103*/
104QPlaceSearchRequest::QPlaceSearchRequest()
105 : d_ptr(new QPlaceSearchRequestPrivate())
106{
107}
108
109/*!
110 Constructs a copy of \a other.
111*/
112QPlaceSearchRequest::QPlaceSearchRequest(const QPlaceSearchRequest &other) noexcept = default;
113
114/*!
115 Destroys the request object.
116*/
117QPlaceSearchRequest::~QPlaceSearchRequest() = default;
118
119/*!
120 Assigns \a other to this search request and returns a reference
121 to this search request.
122*/
123QPlaceSearchRequest &QPlaceSearchRequest::operator=(const QPlaceSearchRequest & other) noexcept
124{
125 if (this == &other)
126 return *this;
127
128 d_ptr = other.d_ptr;
129 return *this;
130}
131
132/*!
133 \fn bool QPlaceSearchRequest::operator==(const QPlaceSearchRequest &lhs, const QPlaceSearchRequest &rhs) noexcept
134
135 Returns true if \a lhs is equal to \a rhs, otherwise returns false.
136*/
137
138/*!
139 \fn bool QPlaceSearchRequest::operator!=(const QPlaceSearchRequest &lhs, const QPlaceSearchRequest &rhs) noexcept
140
141 Returns true if \a lhs is not equal to \a rhs, otherwise returns false.
142*/
143
144bool QPlaceSearchRequest::isEqual(const QPlaceSearchRequest &other) const noexcept
145{
146 Q_D(const QPlaceSearchRequest);
147 return *d == *other.d_func();
148}
149
150/*!
151 Returns the search term.
152*/
153QString QPlaceSearchRequest::searchTerm() const
154{
155 Q_D(const QPlaceSearchRequest);
156 return d->searchTerm;
157}
158
159/*!
160 Sets the search \a term.
161*/
162void QPlaceSearchRequest::setSearchTerm(const QString &term)
163{
164 Q_D(QPlaceSearchRequest);
165 d->searchTerm = term;
166}
167
168/*!
169 Return the categories to be used in the search request.
170 Places need only to belong to one of the categories
171 to be considered a match by the request.
172*/
173QList<QPlaceCategory> QPlaceSearchRequest::categories() const
174{
175 Q_D(const QPlaceSearchRequest);
176 return d->categories;
177}
178
179/*!
180 Sets the search request to search by a single \a category
181
182 \sa setCategories()
183*/
184void QPlaceSearchRequest::setCategory(const QPlaceCategory &category)
185{
186 Q_D(QPlaceSearchRequest);
187 d->categories.clear();
188
189 if (!category.categoryId().isEmpty())
190 d->categories.append(category);
191}
192
193/*!
194 Sets the search request to search from the list of given \a categories.
195 Any places returned during the search will match at least one of the \a
196 categories.
197
198 \sa setCategory()
199*/
200void QPlaceSearchRequest::setCategories(const QList<QPlaceCategory> &categories)
201{
202 Q_D(QPlaceSearchRequest);
203 d->categories = categories;
204}
205
206/*!
207 Returns the search area which will be used to limit search results. The default search area is
208 an invalid QGeoShape, indicating that no specific search area is defined.
209*/
210QGeoShape QPlaceSearchRequest::searchArea() const
211{
212 Q_D(const QPlaceSearchRequest);
213 return d->searchArea;
214}
215
216/*!
217 Sets the search request to search within the given \a area.
218*/
219void QPlaceSearchRequest::setSearchArea(const QGeoShape &area)
220{
221 Q_D(QPlaceSearchRequest);
222 d->searchArea = area;
223}
224
225/*!
226 Returns the place id which will be used to search for recommendations
227 for similar places.
228*/
229QString QPlaceSearchRequest::recommendationId() const
230{
231 Q_D(const QPlaceSearchRequest);
232 return d->recommendationId;
233}
234
235/*!
236 Sets the \a placeId which will be used to search for recommendations.
237*/
238void QPlaceSearchRequest::setRecommendationId(const QString &placeId)
239{
240 Q_D(QPlaceSearchRequest);
241 d->recommendationId = placeId;
242}
243
244/*!
245 Returns backend specific additional search context associated with this place search request.
246 The search context is typically set as part of a
247 \l {QPlaceSearchResult::ProposedSearchResult}{proposed search results}.
248*/
249QVariant QPlaceSearchRequest::searchContext() const
250{
251 Q_D(const QPlaceSearchRequest);
252 return d->searchContext;
253}
254
255/*!
256 Sets the search context to \a context.
257
258 \note This method is intended to be used by geo service plugins when returning search results
259 of type \l QPlaceSearchResult::ProposedSearchResult.
260
261 The search context is used by backends to store additional search context related to the search
262 request. Other relevant fields should also be filled in. For example, if the search context
263 encodes a text search the search term should also be set with \l setSearchTerm(). The search
264 context allows additional search context to be kept which is not directly accessible via the
265 Qt Location API.
266
267 The search context can be of any type storable in a QVariant. The value of the search context
268 is not intended to be use directly by applications.
269*/
270void QPlaceSearchRequest::setSearchContext(const QVariant &context)
271{
272 Q_D(QPlaceSearchRequest);
273 d->searchContext = context;
274}
275
276/*!
277 Returns the visibility scope used when searching for places. The default value is
278 QLocation::UnspecifiedVisibility meaning that no explicit scope has been assigned.
279 Places of any scope may be returned during the search.
280*/
281QLocation::VisibilityScope QPlaceSearchRequest::visibilityScope() const
282{
283 Q_D(const QPlaceSearchRequest);
284 return d->visibilityScope;
285}
286
287/*!
288 Sets the visibility \a scope used when searching for places.
289*/
290void QPlaceSearchRequest::setVisibilityScope(QLocation::VisibilityScope scope)
291{
292 Q_D(QPlaceSearchRequest);
293 d->visibilityScope = scope;
294}
295
296/*!
297 Returns the relevance hint of the request. The hint is given to the provider
298 to help but not dictate the ranking of results. For example providing a distance hint
299 may give closer places a higher ranking but it doesn't necessarily mean
300 that he results will be ordered strictly according to distance.
301*/
302QPlaceSearchRequest::RelevanceHint QPlaceSearchRequest::relevanceHint() const
303{
304 Q_D(const QPlaceSearchRequest);
305 return d->relevanceHint;
306}
307
308/*!
309 Sets the relevance \a hint to be used when searching for a place.
310*/
311void QPlaceSearchRequest::setRelevanceHint(QPlaceSearchRequest::RelevanceHint hint)
312{
313 Q_D(QPlaceSearchRequest);
314 d->relevanceHint = hint;
315}
316
317/*!
318 Returns the maximum number of search results to retrieve.
319
320 A negative value for limit means that it is undefined. It is left up to the backend
321 provider to choose an appropriate number of results to return. The default limit is -1.
322*/
323int QPlaceSearchRequest::limit() const
324{
325 Q_D(const QPlaceSearchRequest);
326 return d->limit;
327}
328
329/*!
330 Set the maximum number of search results to retrieve to \a limit.
331*/
332void QPlaceSearchRequest::setLimit(int limit)
333{
334 Q_D(QPlaceSearchRequest);
335 d->limit = limit;
336}
337
338/*!
339 Clears the search request.
340*/
341void QPlaceSearchRequest::clear()
342{
343 Q_D(QPlaceSearchRequest);
344 d->clear();
345}
346
347inline QPlaceSearchRequestPrivate *QPlaceSearchRequest::d_func()
348{
349 return static_cast<QPlaceSearchRequestPrivate *>(d_ptr.data());
350}
351
352inline const QPlaceSearchRequestPrivate *QPlaceSearchRequest::d_func() const
353{
354 return static_cast<const QPlaceSearchRequestPrivate *>(d_ptr.constData());
355}
356
357QT_END_NAMESPACE
Combined button and popup list for selecting options.