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